using SteamWare; using System; namespace GMW_data { /// /// Classe gestione auth utente /// [Serializable] public class OpAuth { /// /// CodSoggetto (univoco) /// public string CodSoggetto { get; set; } /// /// Matricola OP (univoca) /// public int Matricola { 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...) CodSoggetto = ""; Matricola = 0; CognomeNome = "NA"; remAuth = memLayer.ML.CRI("defRemAuth"); scadAuth = DateTime.Now.AddMinutes(memLayer.ML.CRI("defMinScad")); } /// /// Fornisce un oggetto OpAuth popolato da CodSoggetto calcolando il resto + lettura default da web.config /// /// /// public static OpAuth startOpAuth(string CodSoggetto) { OpAuth answ = new OpAuth(); if (CodSoggetto != "") { answ.CodSoggetto = CodSoggetto; answ.CognomeNome = utils.obj.getOperatoreByCod(CodSoggetto); answ.Matricola = DataProxy.obj.taTrascSogg.getByKey(CodSoggetto, 0)[0].CodMatricola; } currAuth = answ; return answ; } /// /// Fornisce un oggetto OpAuth popolato da Matricola calcolando il resto + lettura default da web.config /// /// /// public static OpAuth startOpAuth(int Matricola) { OpAuth answ = new OpAuth(); if (Matricola > 0) { answ.CodSoggetto = DataProxy.obj.taTrascSogg.getByKey("", Matricola)[0].CodSoggetto; answ.CognomeNome = utils.obj.getOperatoreByCod(answ.CodSoggetto); answ.Matricola = Matricola; } 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 CodSoggetto VALIDO if (currAuth.CodSoggetto != "") { answ = true; } } } } return answ; } } /// /// definisce se sia richiesta OpAuth /// public static bool opAuthReq { get { // verifico SE devo fare controllo OpAuth... return memLayer.ML.CRB("enableOpAuth"); } } } }