using SteamWare; using System; namespace CMS_SC_Data { /// /// Classe gestione auth utente /// [Serializable] public class OpAuth { /// /// email (univoco) /// public string email { get; set; } /// /// Cognome - Nome /// public string CognomeNome { get; set; } /// /// numero autorizzazioni ancora possibili /// public int remAuth { get; set; } /// /// scadenza massima auth /// public DateTime scadAuth { get; set; } /// /// inizializzazione componente, default da web.config MA CON AUTH /// protected OpAuth() { // imposto valori di default (scaduti...) email = "NA"; CognomeNome = "NA"; remAuth = memLayer.ML.CRI("defRemAuth"); scadAuth = DateTime.Now.AddMinutes(memLayer.ML.CRI("defMinScad")); } /// /// Fornisce un oggetto OpAuth popolato da email calcolando il resto + lettura default da web.config /// /// /// /// public static OpAuth startOpAuth(string email, string CognomeNome) { OpAuth answ = new OpAuth(); if (email != "") { answ.email = email; answ.CognomeNome = CognomeNome; } currAuth = answ; return answ; } /// /// toglie auth utente /// public static void stopAuth() { memLayer.ML.emptySessionVal("OpAuth"); } /// /// Auth Corrente x operazioni User /// public static OpAuth currAuth { get { OpAuth answ = new OpAuth(); // cerco in sessione... if (memLayer.ML.isInSessionObject("OpAuth")) { answ = (OpAuth)memLayer.ML.objSessionObj("OpAuth"); } return answ; } set { memLayer.ML.setSessionVal("OpAuth", value); } } /// /// definisce si sia valida auth operatività utente, ovvero /// - valori in sessione /// - num auth > 0 /// - auth non scaduta /// public static bool isAuth { get { bool answ = false; // se ho valori in sessione if (memLayer.ML.isInSessionObject("OpAuth")) { // se ho num auth > 0 if (currAuth.remAuth > 0) { // se non è scaduta auth.. if (currAuth.scadAuth > DateTime.Now) { // se ho un email VALIDO if (currAuth.email != "") { answ = true; } } } } return answ; } } /// /// definisce se sia RICHEISTA OpAuth /// public static bool opAuthReq { get { // verifico SE devo fare controllo OpAuth... return memLayer.ML.CRB("enableOpAuth"); } } } }