Fix procewdura login x MAG (stile TAB)
This commit is contained in:
+101
-1
@@ -1,4 +1,5 @@
|
||||
using SteamWare;
|
||||
using MapoDb;
|
||||
using SteamWare;
|
||||
using SteamWare.Logger;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -11,6 +12,29 @@ namespace MP_MAG.SMART
|
||||
{
|
||||
public partial class login : UserPage
|
||||
{
|
||||
#region Protected Fields
|
||||
|
||||
/// <summary>
|
||||
/// IP corrente
|
||||
/// </summary>
|
||||
protected string postazione_IP = "";
|
||||
|
||||
/// <summary>
|
||||
/// user agent corrente
|
||||
/// </summary>
|
||||
protected string userAgent = "";
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Internal Fields
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto datalayer specifico
|
||||
/// </summary>
|
||||
internal DataLayer DataLayerObj = new DataLayer();
|
||||
|
||||
#endregion Internal Fields
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
/// <summary>
|
||||
@@ -66,6 +90,72 @@ namespace MP_MAG.SMART
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// verifica al presenza di un cookie VALIDO per autorizzare il device (operatore SENZA email)
|
||||
/// </summary>
|
||||
private bool checkAuthCookieNoEmail()
|
||||
{
|
||||
bool checkOk = false;
|
||||
try
|
||||
{
|
||||
HttpCookie cookie = Request.Cookies[memLayer.ML.CRS("cookieName")];
|
||||
if (cookie == null || string.IsNullOrEmpty(cookie.Value))
|
||||
{
|
||||
// rimando pagina x registrazione devices
|
||||
logger.lg.scriviLog("Cookie non valido / non trovato", tipoLog.STARTUP);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ricavo utente da cookie...
|
||||
string devSecret = cookie.Value;
|
||||
DS_devices.AnagDevicesRow device = null;
|
||||
// cerco il device...ogni dipendente può averne + di 1 registrato a suo nome...
|
||||
string UsrName = "";
|
||||
string Dominio = "";
|
||||
try
|
||||
{
|
||||
logger.lg.scriviLog($"Cookie trovato con devSecret {devSecret}", tipoLog.STARTUP);
|
||||
device = DataWrap.DW.taAnagDev.getByDeviceSecret(devSecret)[0];
|
||||
UsrName = device.User_Name;
|
||||
Dominio = device.Dominio;
|
||||
DataLayerObj.MatrOpr = device.MatrOpr; // salvo MatrOpr!
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog($"Errore recupero dati da cookie:{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(UsrName) && !string.IsNullOrEmpty(Dominio))
|
||||
{
|
||||
logger.lg.scriviLog($"Dati utente da cookie: dominio {Dominio}, user:{UsrName}", tipoLog.STARTUP);
|
||||
// aggiorno descrizione (user agent) ed IP...
|
||||
userAgent = Request.UserAgent;
|
||||
postazione_IP = Request.UserHostName;
|
||||
// controllo IP e DeviceDescription x eventuale update
|
||||
if ((device.lastIPv4 != postazione_IP) || (device.Description != userAgent))
|
||||
{
|
||||
// salvo ultimo "contatto" del device aggiornando descrizione ed IP
|
||||
DataWrap.DW.taAnagDev.updateIP(device.IdxDevice, DateTime.Now, postazione_IP, userAgent);
|
||||
}
|
||||
// avvio utente...
|
||||
user_std.UtSn.startUpUtente(Dominio, UsrName);
|
||||
checkOk = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// svuoto cookie...
|
||||
memLayer.ML.emptyCookieVal(memLayer.ML.CRS("cookieName"));
|
||||
// rimando pagina x registrazione devices
|
||||
logger.lg.scriviLog($"Dominio / UsrName non validi / non trovati:{Environment.NewLine}devSec:{devSecret}{Environment.NewLine}UsrName{UsrName}{Environment.NewLine}Dominio{Dominio}", tipoLog.STARTUP);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog($"Errore in checkAuthCookie:{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
|
||||
}
|
||||
return checkOk;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// verifica che la pagina sia tra quelle autorizzate x l'utente
|
||||
/// </summary>
|
||||
@@ -91,6 +181,11 @@ namespace MP_MAG.SMART
|
||||
// provo con authCookiecookie device...
|
||||
allOk = devicesAuthProxy.stObj.checkAuthCookie();
|
||||
}
|
||||
if (!allOk)
|
||||
{
|
||||
// provo con authCookie modalità senza email (come MP TAB...)
|
||||
allOk = checkAuthCookieNoEmail();
|
||||
}
|
||||
else
|
||||
{
|
||||
// per sicurezza startup
|
||||
@@ -160,6 +255,11 @@ namespace MP_MAG.SMART
|
||||
logger.lg.scriviLog($"Login completed for user {devicesAuthProxy.stObj.email}");
|
||||
Response.Redirect("Default");
|
||||
}
|
||||
else if (user_std.UtSn.isAuth)
|
||||
{
|
||||
logger.lg.scriviLog($"Login completed for user {user_std.UtSn.CognomeNomeMatr}");
|
||||
Response.Redirect("Default");
|
||||
}
|
||||
else
|
||||
{
|
||||
string usrHostAddr = Request.UserHostAddress;
|
||||
|
||||
@@ -17,8 +17,17 @@
|
||||
<add key="webpages:Enabled" value="false" />
|
||||
<add key="ClientValidationEnabled" value="true" />
|
||||
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
|
||||
<!--Log-->
|
||||
<add key="_logDir" value="~/logs/" />
|
||||
<add key="_logLevel" value="5" />
|
||||
<add key="_logMaxMb" value="30" />
|
||||
<add key="logMitigSec" value="30" />
|
||||
<!--Auth e cookie-->
|
||||
<add key="devAuthReturnPage" value="EnrollDevice" />
|
||||
<add key="AuthCookieName" value="Auth_MP_MAG" />
|
||||
<add key="cookieName" value="Auth_MP_MAG" />
|
||||
<add key="cookieDayExpire" value="365" />
|
||||
<add key="mainPage" value="menu" />
|
||||
<add key="CodModulo" value="MP-MAG" />
|
||||
<add key="appName" value="MP-MAG" />
|
||||
<add key="maxAgeAppConf_min" value="5" />
|
||||
@@ -37,6 +46,9 @@
|
||||
<add key="DbConfConnectionString" value="Data Source=SQL2016DEV;Initial Catalog=MoonPro_MAG;Persist Security Info=True;User id=sa;Password=keyhammer16;" />
|
||||
<add key="DevicesConnectionString" value="Data Source=SQL2016DEV;Initial Catalog=MoonPro;Persist Security Info=True;User ID=sa;Password=keyhammer16;" />
|
||||
<add key="DevicesAuthConnectionString" value="Data Source=SQL2016DEV;Initial Catalog=MoonPro;Persist Security Info=True;User ID=sa;Password=keyhammer16;" />
|
||||
<add key="MoonProConnectionString" value="Data Source=SQL2016DEV;Initial Catalog=MoonPro;Persist Security Info=True;User ID=sa;Password=keyhammer16;" />
|
||||
<add key="MoonProConnectionStringArca" value="Data Source=SQL2016DEV;Initial Catalog=MoonPro_IS_EdilChim;Persist Security Info=True;User ID=sa;Password=keyhammer16;" />
|
||||
<add key="MoonProConnectionStringMAG" value="Data Source=SQL2016DEV;Initial Catalog=MoonPro_MAG;Persist Security Info=True;User ID=sa;Password=keyhammer16;" />
|
||||
<add key="PermessiConnectionString" value="Data Source=SQL2016DEV;Initial Catalog=MoonPro;Persist Security Info=True;User ID=sa;Password=keyhammer16;" />
|
||||
<add key="UtenteCdcConnectionString" value="Data Source=SQL2016DEV;Initial Catalog=MoonPro_Anagrafica;Persist Security Info=True;User ID=sa;Password=keyhammer16;" />
|
||||
<add key="VocabolarioConnectionString" value="Data Source=SQL2016DEV;Initial Catalog=MoonPro;Persist Security Info=True;User ID=sa;Password=keyhammer16;" />
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace MP_MAG.WebUserControls
|
||||
private void setClock()
|
||||
{
|
||||
lblDateTime.Text = DateTime.Now.ToString("ddd dd.MM.yyyy, HH:mm:ss");
|
||||
//lblCodOperatore.Text = $"{user_std.UtSn.CognomeNome} ({Page.User.Identity.Name})";
|
||||
lblCodOperatore.Text = $"{Page.User.Identity.Name}";
|
||||
lblCodOperatore.Text = $"{user_std.UtSn.CognomeNomeMatr}";
|
||||
//lblCodOperatore.Text = $"{Page.User.Identity.Name}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace MP_MAG.WebUserControls
|
||||
{
|
||||
if (safePages.IndexOf(Request.Url.Segments.LastOrDefault(), StringComparison.OrdinalIgnoreCase) < 0)
|
||||
{
|
||||
Response.Redirect("login");
|
||||
Response.Redirect("login", true);
|
||||
}
|
||||
XmlMenu.Data = File.ReadAllText(Server.MapPath("/Resources/DefaultMenu.xml"));
|
||||
}
|
||||
@@ -121,7 +121,7 @@ namespace MP_MAG.WebUserControls
|
||||
XmlMenu.XPath = "mainMenu/menu";
|
||||
XmlMenu.DataBind();
|
||||
}
|
||||
catch
|
||||
catch (Exception exc)
|
||||
{
|
||||
if (safePages.IndexOf(Request.Url.Segments.LastOrDefault(), StringComparison.OrdinalIgnoreCase) < 0)
|
||||
{
|
||||
|
||||
+8
-6
@@ -1420,27 +1420,29 @@ namespace MapoDb
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.lg.scriviLog(string.Format("non sono riuscito a recuperare RIGA utente per matricola {0}", matricola), tipoLog.ERROR);
|
||||
logger.lg.scriviLog($"Non sono riuscito a recuperare RIGA utente per matricola {matricola}", tipoLog.ERROR);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
logger.lg.scriviLog(string.Format("Eccezione! non sono riuscito a recuperare utente per matricola {0}", matricola), tipoLog.ERROR);
|
||||
logger.lg.scriviLog($"Eccezione! non sono riuscito a recuperare utente per matricola {matricola}", tipoLog.ERROR);
|
||||
Dominio = memLayer.ML.CRS("dominio");
|
||||
UsrName = memLayer.ML.CRS("user");
|
||||
}
|
||||
string cookieName = memLayer.ML.CRS("cookieName");
|
||||
DateTime expDate = DateTime.Now.AddDays(memLayer.ML.CRI("cookieDayExpire"));
|
||||
string Secret = authProxy.getSecret(Dominio, UsrName, matricola, DeviceName, adesso);
|
||||
string devSecret = SteamCrypto.EncryptString(Secret, memLayer.ML.CRS("cookieName"));
|
||||
string devSecret = SteamCrypto.EncryptString(Secret, cookieName);
|
||||
try
|
||||
{
|
||||
// creo device + cookie!
|
||||
fatto = authProxy.createNewCookie(Dominio, UsrName, matricola, DeviceName, Description, IPv4, memLayer.ML.CRS("cookieName"), DateTime.Now.AddDays(memLayer.ML.CRI("cookieDayExpire")));
|
||||
fatto = authProxy.createNewCookie(Dominio, UsrName, matricola, DeviceName, Description, IPv4, cookieName, expDate);
|
||||
// loggo!
|
||||
logger.lg.scriviLog(string.Format("Effettuato enroll nuovo device: utente {0}\\{1} | matricola {2} | DeviceName {3} | Descrizione {4} | IP {5} | nome cookcie {6} | valido sino a {7:yyyy/MM/dd}", Dominio, UsrName, matricola, DeviceName, Description, IPv4, memLayer.ML.CRS("cookieName"), DateTime.Now.AddDays(memLayer.ML.CRI("cookieDayExpire"))));
|
||||
logger.lg.scriviLog(string.Format("Effettuato enroll nuovo device: utente {0}\\{1} | matricola {2} | DeviceName {3} | Descrizione {4} | IP {5} | nome cookie {6} | valido sino a {7:yyyy/MM/dd HH:mm:ss}", Dominio, UsrName, matricola, DeviceName, Description, IPv4, cookieName, expDate));
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog(string.Format("Errore enroll nuovo device:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
||||
logger.lg.scriviLog($"Errore enroll nuovo device:{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
|
||||
Reference in New Issue
Block a user