Aggiunti controlli univocità username e pw in Registrazioni e Insert/Update Tecnici
This commit is contained in:
parent
3702f9d97e
commit
3cc84dc72d
@ -124,6 +124,12 @@ namespace VirtualTask.Controllers
|
||||
bool bAziPres = false;
|
||||
bool privacy1=false;
|
||||
|
||||
Controllo cUtePres = isLoginPresente(model.username, model.passwd, helper);
|
||||
if (cUtePres.isPresente)
|
||||
{
|
||||
ModelState.AddModelError("tcuser", "Login già utilizzata. Scegliere un nome utente differente");
|
||||
}
|
||||
|
||||
bAziPres = checkAziendaPresente(model.azienda);
|
||||
if (bAziPres)
|
||||
{
|
||||
@ -145,7 +151,7 @@ namespace VirtualTask.Controllers
|
||||
privacy1 = true;
|
||||
}
|
||||
|
||||
if (!bAziPres && bEmail && !privacy1)
|
||||
if (!bAziPres && bEmail && !privacy1 && !cUtePres.isPresente)
|
||||
{
|
||||
urlBase = apiUrl + "registrazioni/add";
|
||||
Uri baseAddress = new Uri(urlBase);
|
||||
@ -714,6 +720,38 @@ namespace VirtualTask.Controllers
|
||||
return txt;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private static Random random = new Random();
|
||||
|
||||
public static string RandomString(int length)
|
||||
|
||||
@ -270,32 +270,48 @@ namespace VirtualTask.Controllers
|
||||
{
|
||||
return RedirectToAction("Login2", "Login");
|
||||
}
|
||||
tecnico.tccodazi = tenant;
|
||||
|
||||
apiUrl = helper.GetStringValue("apiUrl");
|
||||
admin = helper.GetStringValue("admin");
|
||||
ViewBag.Admin = admin;
|
||||
urlBase = apiUrl + "tecnici/mod";
|
||||
urlBase = urlBase + "?token=" + token;
|
||||
Uri baseAddress = new Uri(urlBase);
|
||||
client = new HttpClient();
|
||||
client.BaseAddress = baseAddress;
|
||||
|
||||
string data = JsonConvert.SerializeObject(tecnico);
|
||||
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
//step 1 prima controllo che le credenziali di login non siano già presenti.
|
||||
//per fare questo chiamo il metodo api tecniciListAll
|
||||
Controllo c = isLoginPresente(tecnico.tcuser, tecnico.tcpwd, helper);
|
||||
if (c.isPresente)
|
||||
{
|
||||
return RedirectToAction("Index");
|
||||
ModelState.AddModelError("tcuser", "Login già utilizzata. Scegliere un nome utente differente");
|
||||
}
|
||||
|
||||
if (!c.isPresente)
|
||||
{
|
||||
tecnico.tccodazi = tenant;
|
||||
|
||||
apiUrl = helper.GetStringValue("apiUrl");
|
||||
admin = helper.GetStringValue("admin");
|
||||
ViewBag.Admin = admin;
|
||||
urlBase = apiUrl + "tecnici/mod";
|
||||
urlBase = urlBase + "?token=" + token;
|
||||
Uri baseAddress = new Uri(urlBase);
|
||||
client = new HttpClient();
|
||||
client.BaseAddress = baseAddress;
|
||||
|
||||
string data = JsonConvert.SerializeObject(tecnico);
|
||||
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("Error");
|
||||
}
|
||||
//return View(tecnico);
|
||||
}
|
||||
else
|
||||
{
|
||||
errMes = response.Content.ReadAsStringAsync().Result;
|
||||
helper.SetStringValue("errMsg", errMes);
|
||||
return RedirectToAction("Error");
|
||||
return View(tecnico);
|
||||
}
|
||||
//return View(tecnico);
|
||||
}
|
||||
|
||||
#endregion EDIT
|
||||
@ -384,6 +400,7 @@ namespace VirtualTask.Controllers
|
||||
string e = helper.GetStringValue("errMsg");
|
||||
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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user