Aggiunti controlli univocità username e pw in Registrazioni e Insert/Update Tecnici

This commit is contained in:
michele 2025-09-19 11:50:06 +02:00
parent 3702f9d97e
commit 3cc84dc72d
2 changed files with 76 additions and 21 deletions

View File

@ -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)

View File

@ -270,6 +270,17 @@ namespace VirtualTask.Controllers
{
return RedirectToAction("Login2", "Login");
}
//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)
{
ModelState.AddModelError("tcuser", "Login già utilizzata. Scegliere un nome utente differente");
}
if (!c.isPresente)
{
tecnico.tccodazi = tenant;
apiUrl = helper.GetStringValue("apiUrl");
@ -297,6 +308,11 @@ namespace VirtualTask.Controllers
}
//return View(tecnico);
}
else
{
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();