Files
2021-03-26 17:17:28 +01:00

116 lines
4.3 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 GPW_data;
namespace GPW.WebUserControls
{
public partial class mod_title : System.Web.UI.UserControl
{
/// <summary>
/// user agent corrente
/// </summary>
protected string userAgent = "";
/// <summary>
/// IP corrente
/// </summary>
protected string postazione_IP = "";
protected void Page_Load(object sender, EventArgs e)
{
// controllo se c'è utente in sessione..
checkUser();
// sistemo visualizzazione
postazione_IP = Request.UserHostName;
lblIpData.Text = postazione_IP;
try
{
lblSwData.Text = memLayer.ML.StringSessionObj("cognomeNome");
}
catch
{
lblSwData.Text = "GPW";
}
//lblIpData.Text = memLayer.ML.StringSessionObj("cognomeNome");
}
/// <summary>
/// verifica presenza utente autorizzato in sessione
/// </summary>
private void checkUser()
{
if (!memLayer.ML.isInSessionObject("idxDipendente"))
{
// controllo cookie device...
checkAuthCookieGPW();
}
}
/// <summary>
/// verifica al presenza di un cookie VALIDO per autorizzare il device
/// </summary>
private void checkAuthCookieGPW()
{
try
{
HttpCookie cookie = Request.Cookies["AuthGPW"];
if (cookie == null || cookie.Value=="")
{
// rimando pagina x registrazione devices
Response.Redirect("~/A3/regNewDevice.aspx");
}
else
{
// ricavo utente da cookie...
string devSecret = cookie.Value;
DS_Applicazione.AnagDevicesRow device = null;
// cerco il device...ogni dipendente può averne + di 1 registrato a suo nome...
int idxDipendente = 0;
try
{
device = DataProxy.DP.taAnagDev.getByDeviceSecret(devSecret)[0];
idxDipendente = device.idxDipendente;
}
catch
{ }
if (idxDipendente > 0)
{
// aggiorno descrizione (user agent) ed IP...
userAgent = Request.UserAgent;
postazione_IP = Request.UserHostName;
// controllo IP e DeviceDescription x eventuale update
if ((device.lastIPv4 != postazione_IP) || (device.Description != userAgent))
{
// salvo ultimo "contatto" del device aggiornando descrizione ed IP
DataProxy.DP.taAnagDev.updateIP(device.IdxDevice, DateTime.Now, postazione_IP, userAgent);
}
// salvo in sessione utente
memLayer.ML.setSessionVal("idxDipendente", idxDipendente);
string CognomeNome = "";
try
{
DS_Applicazione.DipendentiRow rigaDip = DataProxy.DP.taDipendenti.getByIdx(idxDipendente)[0];
CognomeNome = string.Format("{0} {1}", rigaDip.Cognome, rigaDip.Nome);
}
catch
{ }
memLayer.ML.setSessionVal("cognomeNome", CognomeNome);
}
else
{
// svuoto cookie...
memLayer.ML.emptyCookieVal("AuthGPW");
// rimando pagina x registrazione devices
Response.Redirect("~/A3/regNewDevice.aspx");
}
}
}
catch(Exception exc)
{
logger.lg.scriviLog(string.Format("Errore in checkAuthCookie:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
}
}
}
}