From 76b064389f040910e502fe06cef75c62b2c29b7f Mon Sep 17 00:00:00 2001 From: Marco Audiffredi Date: Tue, 5 Dec 2023 16:31:48 +0100 Subject: [PATCH] login nuovo --- Controllers/HomeController.cs | 2 +- Controllers/LoginController.cs | 69 +++++++++++++++++++----------- Models/Login.cs | 2 + Views/Login/Login2.cshtml | 12 ++++-- Views/Shared/_LayoutPortale.cshtml | 2 +- appsettings.json | 3 +- 6 files changed, 59 insertions(+), 31 deletions(-) diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index 7b0e67e..aca8bc5 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -24,7 +24,7 @@ namespace VirtualTask.Controllers ViewBag.Admin = admin; if (string.IsNullOrEmpty(token)) { - return RedirectToAction("Index", "Login"); + return RedirectToAction("Login2", "Login"); } else { diff --git a/Controllers/LoginController.cs b/Controllers/LoginController.cs index 5afd124..4ec7357 100644 --- a/Controllers/LoginController.cs +++ b/Controllers/LoginController.cs @@ -20,7 +20,7 @@ namespace VirtualTask.Controllers { client = new HttpClient(); - helper = new SessionHelper(this); + // helper = new SessionHelper(this); _configuration = configuration; var key = _configuration["ApplicationInsights:rootUrlApi"]; apiUrl = key; @@ -32,40 +32,59 @@ namespace VirtualTask.Controllers [HttpPost] - public IActionResult Login(Login model) + public IActionResult Login2(Login model) { - string url = apiUrl + "loginTechnicalVT"; - Uri baseAddress = new Uri(url); - client.BaseAddress = baseAddress; - ViewBag.Error =string.Empty; - ViewBag.Admin = string.Empty; - LoginOut loginOut = new LoginOut(); - string data = JsonConvert.SerializeObject(model); - StringContent content = new StringContent(data, Encoding.UTF8, "application/json"); - HttpResponseMessage response = client.PostAsync(baseAddress, content).Result; - if (response.IsSuccessStatusCode) + if (ModelState.IsValid) { - string risultato = response.Content.ReadAsStringAsync().Result; - loginOut = JsonConvert.DeserializeObject(risultato); + helper = new SessionHelper(this); + string url = apiUrl + "loginTechnicalVT"; + Uri baseAddress = new Uri(url); + client.BaseAddress = baseAddress; + ViewBag.Error = string.Empty; + ViewBag.Admin = string.Empty; + + LoginOut loginOut = new LoginOut(); + string data = JsonConvert.SerializeObject(model); + StringContent content = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = client.PostAsync(baseAddress, content).Result; + if (response.IsSuccessStatusCode) + { + string risultato = response.Content.ReadAsStringAsync().Result; + loginOut = JsonConvert.DeserializeObject(risultato); + + helper.SetStringValue("tok", loginOut.Tok); + helper.SetStringValue("apiUrl", apiUrl); + helper.SetStringValue("tenant", model.Tenant); + helper.SetStringValue("tecnico", model.Username); + helper.SetStringValue("admin", loginOut.Tcsuper != null ? loginOut.Tcsuper : "N"); + + return RedirectToAction("Index", "Home"); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + loginOut = JsonConvert.DeserializeObject(errMes); + + helper.SetStringValue("errMsg", loginOut.err_detail); + ViewBag.Error = loginOut.err_detail; + return View(); + } - helper.SetStringValue("tok", loginOut.Tok); - helper.SetStringValue("apiUrl", apiUrl); - helper.SetStringValue("tenant", model.Tenant); - helper.SetStringValue("tecnico", model.Username); - helper.SetStringValue("admin", loginOut.Tcsuper != null ? loginOut.Tcsuper : "N"); - - return RedirectToAction("Index","Home"); } else { - errMes = response.Content.ReadAsStringAsync().Result; - loginOut = JsonConvert.DeserializeObject(errMes); + foreach (var Elemento in ModelState.Values) + { + foreach (var Errore in Elemento.Errors) + { + string ErroreRilevato = Errore.ErrorMessage; + } - helper.SetStringValue("errMsg", loginOut.err_detail); - ViewBag.Error = loginOut.err_detail; + } return View(); } + } public IActionResult Login2() diff --git a/Models/Login.cs b/Models/Login.cs index 7e412ee..bdd4e68 100644 --- a/Models/Login.cs +++ b/Models/Login.cs @@ -5,10 +5,12 @@ namespace VirtualTask.Models public class Login { [StringLength(20)] + [Display(Name = "Username"), Required(ErrorMessage = "Username obbligatorio")] /// Username public string? Username { get; set; } [StringLength(20)] + [Display(Name = "Password"), Required(ErrorMessage = "Password obbligatoria")] /// Password public string? Password { get; set; } diff --git a/Views/Login/Login2.cshtml b/Views/Login/Login2.cshtml index 5de8265..5bed08f 100644 --- a/Views/Login/Login2.cshtml +++ b/Views/Login/Login2.cshtml @@ -6,8 +6,9 @@

Login

-
+
+
@@ -22,13 +23,13 @@
-
 
+@*
 
-
+
*@
@@ -36,4 +37,9 @@
+
+
+
+ @ViewBag.Error +
\ No newline at end of file diff --git a/Views/Shared/_LayoutPortale.cshtml b/Views/Shared/_LayoutPortale.cshtml index 5068520..4d92474 100644 --- a/Views/Shared/_LayoutPortale.cshtml +++ b/Views/Shared/_LayoutPortale.cshtml @@ -237,7 +237,7 @@ Purchase:
@*agency*@ - agency + Virtual Task
diff --git a/appsettings.json b/appsettings.json index d3a348e..4460f4a 100644 --- a/appsettings.json +++ b/appsettings.json @@ -6,7 +6,8 @@ } }, "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/", "mittenteMail": "audiffredi@poloinformatico.it", "nomeMail": "Supporto Virtual Task", "pwdMail": "audicruz70",