Files
Samuele E. Locatelli d788a88d6c inclusione di REDIS
2018-02-14 13:49:07 +01:00

129 lines
3.7 KiB
C#

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