Controlli unicità login tecnici
This commit is contained in:
parent
a90d7ff2e8
commit
e9fe869a2f
@ -1,7 +1,9 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Xml.Linq;
|
||||||
using VirtualTask.Models;
|
using VirtualTask.Models;
|
||||||
using X.PagedList;
|
using X.PagedList;
|
||||||
using static System.Net.Mime.MediaTypeNames;
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
@ -104,39 +106,71 @@ namespace VirtualTask.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult Create(Tecnici model)
|
public IActionResult Create(Tecnici model)
|
||||||
{
|
{
|
||||||
|
|
||||||
SessionHelper helper = new SessionHelper(this);
|
SessionHelper helper = new SessionHelper(this);
|
||||||
token = helper.GetStringValue("tok");
|
if (ModelState.IsValid)
|
||||||
tenant = helper.GetStringValue("tenant");
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(token))
|
|
||||||
{
|
{
|
||||||
return RedirectToAction("Login2", "Login");
|
token = helper.GetStringValue("tok");
|
||||||
}
|
tenant = helper.GetStringValue("tenant");
|
||||||
model.tccodazi = tenant;
|
|
||||||
|
|
||||||
apiUrl = helper.GetStringValue("apiUrl");
|
if (string.IsNullOrEmpty(token))
|
||||||
admin = helper.GetStringValue("admin");
|
{
|
||||||
ViewBag.Admin = admin;
|
return RedirectToAction("Login2", "Login");
|
||||||
urlBase = apiUrl + "tecnici/add";
|
}
|
||||||
urlBase = urlBase + "?token=" + token;
|
//step 1 prima controllo che le credenziali di login non siano già presenti.
|
||||||
Uri baseAddress = new Uri(urlBase);
|
//per fare questo chiamo il metodo api tecniciListAll
|
||||||
client = new HttpClient();
|
Controllo c = isLoginPresente(model.tcuser, model.tcpwd, helper);
|
||||||
client.BaseAddress = baseAddress;
|
if (c.isPresente)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("tcuser", "Login già utilizzata. Scegliere un nome utente differente");
|
||||||
|
}
|
||||||
|
|
||||||
string data = JsonConvert.SerializeObject(model);
|
if(!c.isPresente)
|
||||||
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
{
|
||||||
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
model.tccodazi = tenant;
|
||||||
|
|
||||||
if (response.IsSuccessStatusCode)
|
apiUrl = helper.GetStringValue("apiUrl");
|
||||||
{
|
admin = helper.GetStringValue("admin");
|
||||||
return RedirectToAction("Index");
|
ViewBag.Admin = admin;
|
||||||
|
urlBase = apiUrl + "tecnici/add";
|
||||||
|
urlBase = urlBase + "?token=" + token;
|
||||||
|
Uri baseAddress = new Uri(urlBase);
|
||||||
|
client = new HttpClient();
|
||||||
|
client.BaseAddress = baseAddress;
|
||||||
|
|
||||||
|
string data = JsonConvert.SerializeObject(model);
|
||||||
|
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
||||||
|
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
||||||
|
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errMes = response.Content.ReadAsStringAsync().Result;
|
||||||
|
helper.SetStringValue("ErrMsg", errMes);
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return View("Create", model);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
errMes = response.Content.ReadAsStringAsync().Result;
|
//foreach (var Elemento in ModelState.Values)
|
||||||
helper.SetStringValue("ErrMsg", errMes);
|
//{
|
||||||
return RedirectToAction("Index");
|
// foreach (var Errore in Elemento.Errors)
|
||||||
|
// {
|
||||||
|
// string ErroreRilevato = Errore.ErrorMessage;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//return RedirectToAction("Create");
|
||||||
|
return View("Create", model);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion CREATE
|
#endregion CREATE
|
||||||
@ -347,5 +381,47 @@ namespace VirtualTask.Controllers
|
|||||||
string e = helper.GetStringValue("errMsg");
|
string e = helper.GetStringValue("errMsg");
|
||||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, ErrMsg = e });
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, ErrMsg = e });
|
||||||
}
|
}
|
||||||
|
public Controllo isLoginPresente(string user, string pwd, SessionHelper helper)
|
||||||
|
{
|
||||||
|
Controllo c=new Controllo();
|
||||||
|
c.isPresente = false;
|
||||||
|
|
||||||
|
urlBase = apiUrl + "tecniciListAll";
|
||||||
|
urlBase = urlBase + "?usr=" + user;
|
||||||
|
urlBase = urlBase + "&pwd=" + pwd;
|
||||||
|
Uri baseAddress = new Uri(urlBase);
|
||||||
|
client = new HttpClient();
|
||||||
|
client.BaseAddress = baseAddress;
|
||||||
|
|
||||||
|
List<Tecnici> modelList = new List<Tecnici>();
|
||||||
|
|
||||||
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
||||||
|
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
string data = response.Content.ReadAsStringAsync().Result;
|
||||||
|
modelList = JsonConvert.DeserializeObject<List<Tecnici>>(data);
|
||||||
|
if(modelList!=null && modelList.Count>0)
|
||||||
|
c.isPresente=true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errMes = response.Content.ReadAsStringAsync().Result;
|
||||||
|
helper.SetStringValue("errMsg", errMes);
|
||||||
|
c.errMsg = errMes;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public class Controllo
|
||||||
|
{
|
||||||
|
/// <summary></summary>
|
||||||
|
public string? errMsg { get; set; }
|
||||||
|
|
||||||
|
/// <summary></summary>
|
||||||
|
public bool isPresente { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -74,6 +74,8 @@
|
|||||||
<form asp-action="DeleteConfirmed">
|
<form asp-action="DeleteConfirmed">
|
||||||
<input type="submit" value="Elimina" class="agy-btn submitForm" />
|
<input type="submit" value="Elimina" class="agy-btn submitForm" />
|
||||||
<input type="hidden" id="id" value=@Html.DisplayFor(model => model.ancodice) name="id" />
|
<input type="hidden" id="id" value=@Html.DisplayFor(model => model.ancodice) name="id" />
|
||||||
|
<input type="hidden" id="antipcon" value="C" name="antipcon" />
|
||||||
|
<input type="hidden" id="ancodice" value=@Html.DisplayFor(model => model.ancodice) name="ancodice" />
|
||||||
<div>
|
<div>
|
||||||
<a asp-action="Index">Torna alla lista</a>
|
<a asp-action="Index">Torna alla lista</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -6,8 +6,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ApplicationInsights": {
|
"ApplicationInsights": {
|
||||||
//"rootUrlApi": "https://api.poloinformatico.it:9000/api/Polo/",
|
"rootUrlApi": "https://api.poloinformatico.it:9000/api/Polo/",
|
||||||
"rootUrlApi": "http://testapi.poloinformatico.it:9001/api/Polo/",
|
//"rootUrlApi": "http://testapi.poloinformatico.it:9001/api/Polo/",
|
||||||
"mittenteMail": "audiffredi@poloinformatico.it",
|
"mittenteMail": "audiffredi@poloinformatico.it",
|
||||||
"nomeMail": "Supporto Virtual Task",
|
"nomeMail": "Supporto Virtual Task",
|
||||||
"pwdMail": "audicruz70",
|
"pwdMail": "audicruz70",
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 564 KiB After Width: | Height: | Size: 556 KiB |
Loading…
Reference in New Issue
Block a user