337 lines
8.4 KiB
C#
337 lines
8.4 KiB
C#
using SteamWare;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
namespace PUB.WebUserContols
|
|
{
|
|
public partial class tpl_header : SteamWare.UserControl
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
// altri controlli
|
|
if (!Page.IsPostBack)
|
|
{
|
|
Timer1.Interval = memLayer.ML.confReadInt("intUpdatePagina_ms");
|
|
Page.Title = titolo;// Request.Url.ToString();
|
|
// se ho cambiato pagina registro...)
|
|
if (devicesAuthProxy.pagPrecedente != titolo)
|
|
{
|
|
devicesAuthProxy.pagPrecedente = devicesAuthProxy.pagCorrente;
|
|
}
|
|
// salvo pagina corrente
|
|
devicesAuthProxy.pagCorrente = titolo;
|
|
}
|
|
// SOLO se la pagina NON E' "safe"...
|
|
if (memLayer.ML.confReadString("PageNoIndex").IndexOf(titolo) < 0)
|
|
{
|
|
bool userOk = checkUser();
|
|
bool pageOk = checkPageIsAuth() || checkUserHasRight();
|
|
// controllo se c'è utente in sessione..
|
|
if ((userOk))
|
|
{
|
|
// ora controllo pagina...
|
|
if (!pageOk)
|
|
{
|
|
if (devicesAuthProxy.stObj.isPageEnabled(devicesAuthProxy.pagPrecedente))
|
|
{
|
|
Response.Redirect(devicesAuthProxy.pagPrecedente);
|
|
}
|
|
else
|
|
{
|
|
Response.Redirect("~/MainMenu");
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// rimando pagina x registrazione devices
|
|
Response.Redirect(memLayer.ML.CRS("urlGestUtenti"));
|
|
}
|
|
}
|
|
// aggiorno
|
|
doUpdate();
|
|
}
|
|
|
|
public void doUpdate()
|
|
{
|
|
lnkPAM.Visible = false;
|
|
lnkPAZ.Visible = false;
|
|
lnkPBO.Visible = false;
|
|
lnkPCO.Visible = false;
|
|
switch (UserRole)
|
|
{
|
|
case "amministratore":
|
|
lnkPAM.Visible = true;
|
|
break;
|
|
case "azienda":
|
|
lnkPAZ.Visible = true;
|
|
break;
|
|
case "condomini.it":
|
|
lnkPBO.Visible = true;
|
|
break;
|
|
case "condominio":
|
|
lnkPCO.Visible = true;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
#if false
|
|
lnkPAM.Visible = isPAM;
|
|
lnkPAZ.Visible = isPAZ;
|
|
lnkPBO.Visible = isPBO;
|
|
lnkPCO.Visible = isPCO;
|
|
#endif
|
|
spUser.Attributes.Remove("class");
|
|
spUser.Attributes.Add("class", userClass);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ruolo utente
|
|
/// </summary>
|
|
public string UserRole
|
|
{
|
|
get
|
|
{
|
|
return memLayer.ML.StringSessionObj("UserRole");
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setSessionVal("UserRole", value);
|
|
}
|
|
}
|
|
|
|
public string userClass
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
switch (UserRole)
|
|
{
|
|
case "amministratore":
|
|
answ = "text-danger";
|
|
break;
|
|
case "azienda":
|
|
answ = "text-warning";
|
|
break;
|
|
case "condomini.it":
|
|
answ = "text-info";
|
|
break;
|
|
case "condominio":
|
|
answ = "text-primary";
|
|
break;
|
|
default:
|
|
answ = "text-primary";
|
|
break;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
public bool isPAM
|
|
{
|
|
get
|
|
{
|
|
return Page.Request.Url.AbsolutePath.Contains("/PAM/");
|
|
}
|
|
}
|
|
public bool isPAZ
|
|
{
|
|
get
|
|
{
|
|
return Page.Request.Url.AbsolutePath.Contains("/PAZ/");
|
|
}
|
|
}
|
|
public bool isPBO
|
|
{
|
|
get
|
|
{
|
|
return Page.Request.Url.AbsolutePath.Contains("/PBO/");
|
|
}
|
|
}
|
|
public bool isPCO
|
|
{
|
|
get
|
|
{
|
|
return Page.Request.Url.AbsolutePath.Contains("/PCO/");
|
|
}
|
|
}
|
|
|
|
protected void txtSearch_TextChanged(object sender, EventArgs e)
|
|
{
|
|
// salvo ricerca
|
|
memLayer.ML.setSessionVal("siteSearchVal", txtSearch.Text.Trim());
|
|
}
|
|
|
|
/// <summary>
|
|
/// verifica che l'utente ABBIA il diritto della sezione corrente (es PBO, PAM, ...)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private bool checkUserHasRight()
|
|
{
|
|
bool allOk = false;
|
|
if (isPAM)
|
|
{
|
|
allOk = devicesAuthProxy.stObj.userHasRight("PAM");
|
|
}
|
|
else if (isPAZ)
|
|
{
|
|
allOk = devicesAuthProxy.stObj.userHasRight("PAZ");
|
|
}
|
|
else if (isPBO)
|
|
{
|
|
allOk = devicesAuthProxy.stObj.userHasRight("PBO");
|
|
}
|
|
else if (isPCO)
|
|
{
|
|
allOk = devicesAuthProxy.stObj.userHasRight("PCO");
|
|
}
|
|
return allOk;
|
|
}
|
|
/// <summary>
|
|
/// verifica che la pagina sia tra quelle autorizzate x l'utente
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private bool checkPageIsAuth()
|
|
{
|
|
bool allOk = false;
|
|
bool pageSafe = (memLayer.ML.confReadString("PageNoIndex").IndexOf(titolo) >= 0);
|
|
bool pageAuth = devicesAuthProxy.stObj.isPageEnabled(titolo);
|
|
allOk = (pageSafe || pageAuth);
|
|
return allOk;
|
|
}
|
|
/// <summary>
|
|
/// verifica presenza utente autorizzato in sessione
|
|
/// </summary>
|
|
private bool checkUser()
|
|
{
|
|
bool allOk = devicesAuthProxy.stObj.isAuth;
|
|
if (!devicesAuthProxy.stObj.isAuth)
|
|
{
|
|
// controllo cookie device...
|
|
allOk = checkAuthCookie();
|
|
if (!allOk)
|
|
{
|
|
ResetUser();
|
|
}
|
|
}
|
|
return allOk;
|
|
}
|
|
/// <summary>
|
|
/// Restituisce cognome/nome da sessione...
|
|
/// </summary>
|
|
public string CognomeNome
|
|
{
|
|
get
|
|
{
|
|
string answ = "-";
|
|
try
|
|
{
|
|
answ = SteamWare.devicesAuthProxy.stObj.CognomeNome;
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Restituisce IP corrente
|
|
/// </summary>
|
|
public string currentIP
|
|
{
|
|
get
|
|
{
|
|
string answ = "0.0.0.0";
|
|
try
|
|
{
|
|
answ = Request.UserHostAddress;
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
}
|
|
public bool userIsAdmin
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = devicesAuthProxy.stObj.userHasRight("SuperAdmin");
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// verifica la presenza di un cookie VALIDO per autorizzare il device ed avvia utente...
|
|
/// </summary>
|
|
private bool checkAuthCookie()
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
HttpCookie cookie = Request.Cookies[devicesAuthProxy.AuthCookieName];
|
|
if (!(cookie == null || cookie.Value == ""))
|
|
{
|
|
// ricavo utente da cookie...
|
|
string userAgent = "";
|
|
string postazione_IP = "";
|
|
string devSecret = cookie.Value;
|
|
DS_Auth.AnagDevicesRow device = null;
|
|
// cerco il device...ogni dipendente può averne + di 1 registrato a suo nome...
|
|
string email = "";
|
|
try
|
|
{
|
|
device = devicesAuthProxy.stObj.taAnagDev.getByDeviceSecret(devSecret)[0];
|
|
email = device.USER_NAME;
|
|
}
|
|
catch (Exception exc)
|
|
{ }
|
|
if (email != "")
|
|
{
|
|
// aggiorno descrizione (user agent) ed IP...
|
|
userAgent = Request.UserAgent;
|
|
postazione_IP = Request.UserHostAddress;
|
|
// controllo IP e DeviceDescription x eventuale update
|
|
if ((device.lastIPv4 != postazione_IP) || (device.Description != userAgent))
|
|
{
|
|
// salvo ultimo "contatto" del device aggiornando descrizione ed IP
|
|
devicesAuthProxy.stObj.taAnagDev.updateIP(device.IdxDevice, DateTime.Now, postazione_IP, userAgent);
|
|
}
|
|
// salvo in sessione utente
|
|
memLayer.ML.setSessionVal("email", email);
|
|
// avvio utente...
|
|
devicesAuthProxy.stObj.startUpUtente(email);
|
|
// salvo gruppo...
|
|
if (devicesAuthProxy.stObj.isAuth)
|
|
{
|
|
// se tutto ok
|
|
memLayer.ML.setSessionVal("Gruppo", devicesAuthProxy.stObj.rigaUtente.CodGruppo);
|
|
answ = true;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog(string.Format("Errore in checkAuthCookie:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private void ResetUser()
|
|
{
|
|
devicesAuthProxy.stObj.clearAllUserData();
|
|
// svuoto cookie...
|
|
memLayer.ML.setCookieVal(devicesAuthProxy.AuthCookieName, "");
|
|
memLayer.ML.emptyCookieVal(devicesAuthProxy.AuthCookieName);
|
|
}
|
|
}
|
|
} |