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 bAziPres = false;
|
||||||
bool privacy1=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);
|
bAziPres = checkAziendaPresente(model.azienda);
|
||||||
if (bAziPres)
|
if (bAziPres)
|
||||||
{
|
{
|
||||||
@ -145,7 +151,7 @@ namespace VirtualTask.Controllers
|
|||||||
privacy1 = true;
|
privacy1 = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bAziPres && bEmail && !privacy1)
|
if (!bAziPres && bEmail && !privacy1 && !cUtePres.isPresente)
|
||||||
{
|
{
|
||||||
urlBase = apiUrl + "registrazioni/add";
|
urlBase = apiUrl + "registrazioni/add";
|
||||||
Uri baseAddress = new Uri(urlBase);
|
Uri baseAddress = new Uri(urlBase);
|
||||||
@ -714,6 +720,38 @@ namespace VirtualTask.Controllers
|
|||||||
return txt;
|
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();
|
private static Random random = new Random();
|
||||||
|
|
||||||
public static string RandomString(int length)
|
public static string RandomString(int length)
|
||||||
|
|||||||
@ -270,32 +270,48 @@ namespace VirtualTask.Controllers
|
|||||||
{
|
{
|
||||||
return RedirectToAction("Login2", "Login");
|
return RedirectToAction("Login2", "Login");
|
||||||
}
|
}
|
||||||
tecnico.tccodazi = tenant;
|
|
||||||
|
|
||||||
apiUrl = helper.GetStringValue("apiUrl");
|
//step 1 prima controllo che le credenziali di login non siano già presenti.
|
||||||
admin = helper.GetStringValue("admin");
|
//per fare questo chiamo il metodo api tecniciListAll
|
||||||
ViewBag.Admin = admin;
|
Controllo c = isLoginPresente(tecnico.tcuser, tecnico.tcpwd, helper);
|
||||||
urlBase = apiUrl + "tecnici/mod";
|
if (c.isPresente)
|
||||||
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");
|
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
|
else
|
||||||
{
|
{
|
||||||
errMes = response.Content.ReadAsStringAsync().Result;
|
return View(tecnico);
|
||||||
helper.SetStringValue("errMsg", errMes);
|
|
||||||
return RedirectToAction("Error");
|
|
||||||
}
|
}
|
||||||
//return View(tecnico);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion EDIT
|
#endregion EDIT
|
||||||
@ -384,6 +400,7 @@ 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)
|
public Controllo isLoginPresente(string user, string pwd, SessionHelper helper)
|
||||||
{
|
{
|
||||||
Controllo c=new Controllo();
|
Controllo c=new Controllo();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user