From 5963d94057ebcabcd0273787c51d068636d7f7a7 Mon Sep 17 00:00:00 2001 From: michele Date: Tue, 16 Jul 2024 10:46:00 +0200 Subject: [PATCH] Michele: controllo token --- Controllers/DestinazioniController.cs | 13 +++++++++ Controllers/GiriChiudiController.cs | 25 ++++++++++++++++++ Controllers/GiriController.cs | 38 ++++++++++++++++++++++++++- Controllers/GiriEliminaController.cs | 16 +++++++++++ 4 files changed, 91 insertions(+), 1 deletion(-) diff --git a/Controllers/DestinazioniController.cs b/Controllers/DestinazioniController.cs index 693adc7..5b37a14 100644 --- a/Controllers/DestinazioniController.cs +++ b/Controllers/DestinazioniController.cs @@ -29,8 +29,14 @@ namespace SoftwayWeb.Controllers public IActionResult Index(string id, string? codAutista, DateTime dataGiro, string? codMezzo, int? page = 1) { helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } + string autista = string.Empty; string dataGi = string.Empty; string mezzo = string.Empty; @@ -103,6 +109,13 @@ namespace SoftwayWeb.Controllers { SessionHelper helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } + apiUrl = helper.GetStringValue("apiUrl"); urlBase = apiUrl + "Giri/listaDestinazioneBySerial"; urlBase = urlBase + "?seriale=" + serial; diff --git a/Controllers/GiriChiudiController.cs b/Controllers/GiriChiudiController.cs index d893fe7..7a77040 100644 --- a/Controllers/GiriChiudiController.cs +++ b/Controllers/GiriChiudiController.cs @@ -12,6 +12,7 @@ namespace SoftwayWeb.Controllers string apiUrl = string.Empty; string urlBase = string.Empty; string errMes = string.Empty; + string token = string.Empty; private readonly IConfiguration _configuration; HttpClient client; public GiriChiudiController(IConfiguration configuration) @@ -25,12 +26,28 @@ namespace SoftwayWeb.Controllers // GET: GiriChiudiController public ActionResult Index() { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } // return View(); return RedirectToAction("index", "giri"); } public ActionResult Chiudi(string id, int nbanc,decimal imp) { SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } + GiriConsegnaView model = new GiriConsegnaView(); List lst=new List(); @@ -67,6 +84,14 @@ namespace SoftwayWeb.Controllers { //https://api.poloinformatico.it:8000/api/Giri/closeGiro?serialeGiro=0000000002&bancaliRecuperati=11&importoRecuperato=100 SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } + apiUrl = helper.GetStringValue("apiUrl"); urlBase = apiUrl + "Giri/closeGiro?serialeGiro="; urlBase = urlBase + model.SerialeGiro; diff --git a/Controllers/GiriController.cs b/Controllers/GiriController.cs index 35ba858..0830ebb 100644 --- a/Controllers/GiriController.cs +++ b/Controllers/GiriController.cs @@ -34,6 +34,12 @@ namespace SoftwayWeb.Controllers { helper = new SessionHelper(this); token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } + urlBase = apiUrl + "Giri/listaGiri?aperto="+ aperto; //string url = apiUrl + "Giri/listaGiri"; //urlBase = url + "?token=" + token; @@ -104,6 +110,14 @@ namespace SoftwayWeb.Controllers public IActionResult Create(bool sel) { SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } + List modelList = new List(); apiUrl = helper.GetStringValue("apiUrl"); urlBase = apiUrl + "Giri/listaGiriDaCreare"; @@ -131,7 +145,15 @@ namespace SoftwayWeb.Controllers public IActionResult PostIndex(IList lst) { SessionHelper helper = new SessionHelper(this); - foreach(GiriConsegnaDaCreare g in lst) + + token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } + + foreach (GiriConsegnaDaCreare g in lst) { if(g.IsSelected==true) { @@ -164,6 +186,13 @@ namespace SoftwayWeb.Controllers { SessionHelper helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } + apiUrl = helper.GetStringValue("apiUrl"); urlBase = apiUrl + "Giri/listaGiri?aperto=" + aperto; Uri baseAddress = new Uri(urlBase); @@ -194,6 +223,13 @@ namespace SoftwayWeb.Controllers public IActionResult Bancali(GiriConsegnaView model) { SessionHelper helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } + apiUrl = helper.GetStringValue("apiUrl"); urlBase = apiUrl + "Giri/modGiro"; diff --git a/Controllers/GiriEliminaController.cs b/Controllers/GiriEliminaController.cs index 7636673..16dc9c9 100644 --- a/Controllers/GiriEliminaController.cs +++ b/Controllers/GiriEliminaController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; +using NuGet.Common; using SoftwayWeb.Models; using System.Collections.Generic; using System.Configuration; @@ -13,6 +14,7 @@ namespace SoftwayWeb.Controllers string apiUrl = string.Empty; string urlBase = string.Empty; string errMes = string.Empty; + string token = string.Empty; private readonly IConfiguration _configuration; HttpClient client; @@ -32,6 +34,13 @@ namespace SoftwayWeb.Controllers public IActionResult Elimina(string id) { SessionHelper helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } + GiriConsegnaView model = new GiriConsegnaView(); List modelList = new List(); @@ -66,6 +75,13 @@ namespace SoftwayWeb.Controllers { SessionHelper helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } + apiUrl = helper.GetStringValue("apiUrl"); urlBase = apiUrl + "Giri/delGiro?serialeGiro="; urlBase = urlBase + model.SerialeGiro.TrimEnd();