144 lines
5.0 KiB
C#
144 lines
5.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using SteamWare;
|
|
using MedPred_Data;
|
|
|
|
namespace MedPred.WebUserControls
|
|
{
|
|
public partial class mod_header : System.Web.UI.UserControl
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
// altri controlli
|
|
if (!Page.IsPostBack)
|
|
{
|
|
Page.Title = Request.Url.ToString();
|
|
lblVers.Text = string.Format("v.{0}.{1}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Major, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Minor);
|
|
}
|
|
// SOLO se la apgina NON E' "safe"...
|
|
if (memLayer.ML.confReadString("PageNoIndex").IndexOf(titolo) < 0)
|
|
{
|
|
// controllo se c'è utente in sessione..
|
|
checkUser();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// stringa del paziente selezionato
|
|
/// </summary>
|
|
public string pazienteSel
|
|
{
|
|
get
|
|
{
|
|
string answ = "-";
|
|
if (memLayer.ML.isInSessionObject("Paziente"))
|
|
{
|
|
answ = memLayer.ML.StringSessionObj("Paziente");
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// stringa del paziente selezionato
|
|
/// </summary>
|
|
public string titolo
|
|
{
|
|
get
|
|
{
|
|
return Request.Url.LocalPath.Split('/').Last();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// verifica presenza utente autorizzato in sessione
|
|
/// </summary>
|
|
private void checkUser()
|
|
{
|
|
//if (!memLayer.ML.isInSessionObject("USER_NAME"))
|
|
if (!devicesAuthProxy.stObj.isAuth)
|
|
{
|
|
// controllo cookie device...
|
|
checkAuthCookieMedPred();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Restituisce cognome/nome da sessione...
|
|
/// </summary>
|
|
public string CognomeNome
|
|
{
|
|
get
|
|
{
|
|
string answ = "-";
|
|
try
|
|
{
|
|
answ = SteamWare.devicesAuthProxy.stObj.CognomeNome;
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// verifica al presenza di un cookie VALIDO per autorizzare il device
|
|
/// </summary>
|
|
private void checkAuthCookieMedPred()
|
|
{
|
|
try
|
|
{
|
|
HttpCookie cookie = Request.Cookies["AuthDevice"];
|
|
if (cookie == null || cookie.Value == "")
|
|
{
|
|
// rimando pagina x registrazione devices
|
|
Response.Redirect("UserAdmin");
|
|
}
|
|
else
|
|
{
|
|
// 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
|
|
{ }
|
|
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);
|
|
}
|
|
else
|
|
{
|
|
// svuoto cookie...
|
|
memLayer.ML.emptyCookieVal("AuthDevice");
|
|
// rimando pagina x registrazione devices
|
|
Response.Redirect("UserAdmin");
|
|
}
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog(string.Format("Errore in checkAuthCookie:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
|
}
|
|
}
|
|
}
|
|
} |