145 lines
6.2 KiB
C#
145 lines
6.2 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 MapoDb;
|
|
using System.Configuration;
|
|
|
|
namespace MoonProTablet.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 = "";
|
|
/// <summary>
|
|
/// caricamento pagina
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
// se ho user/dominio e matricola in sessione NON controllo coockie
|
|
if (user_std.UtSn.utente == "" || user_std.UtSn.dominio == "" || DataLayer.MatrOpr == 0)
|
|
{
|
|
// altrimenti controllo se c'è utente in sessione..
|
|
checkAuthCookieMoonProTablet();
|
|
}
|
|
// sistemo visualizzazione
|
|
postazione_IP = Request.UserHostName;
|
|
lblIpData.Text = postazione_IP;
|
|
lblData.Text = string.Format("{0:dd/MM/yy - HH:mm:ss}", DateTime.Now);
|
|
// cerco in sessione i vari dati disponibili...
|
|
string cognomeNome = "";
|
|
try
|
|
{
|
|
cognomeNome = user_std.UtSn.CognomeNome;
|
|
}
|
|
catch
|
|
{ }
|
|
string swData = "";
|
|
if (cognomeNome != "")
|
|
{
|
|
swData = cognomeNome;
|
|
}
|
|
else if (MapoDb.DataLayer.MatrOpr > 0)
|
|
{
|
|
swData = MapoDb.DataLayer.CognomeNomeOpr;
|
|
}
|
|
else
|
|
{
|
|
swData = "MoonProTablet";
|
|
}
|
|
lblSwData.Text = swData;
|
|
//lblVers.Text = string.Format("{0}.{1}", memLayer.ML.confReadString("mainRev"), memLayer.ML.confReadString("minRev"));
|
|
lblVers.Text = string.Format("v.{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);
|
|
}
|
|
/// <summary>
|
|
/// verifica al presenza di un cookie VALIDO per autorizzare il device
|
|
/// </summary>
|
|
private void checkAuthCookieMoonProTablet()
|
|
{
|
|
Uri MyUrl = Request.Url;
|
|
string delimStr = "/";
|
|
char[] delimiter = delimStr.ToCharArray();
|
|
string[] finalUrl = MyUrl.LocalPath.ToString().Split(delimiter);
|
|
int n = finalUrl.Length;
|
|
string _paginaCorrente = finalUrl[n - 1].ToString();
|
|
try
|
|
{
|
|
HttpCookie cookie = Request.Cookies[memLayer.ML.confReadString("cookieName")];
|
|
if (cookie == null || cookie.Value == "")
|
|
{
|
|
// rimando pagina x registrazione devices
|
|
logger.lg.scriviLog("Cookie non valido / non trovato", tipoLog.STARTUP);
|
|
Response.Redirect("~/regNewDevice.aspx");
|
|
}
|
|
else
|
|
{
|
|
// ricavo utente da cookie...
|
|
string devSecret = cookie.Value;
|
|
DS_devices.AnagDevicesRow device = null;
|
|
// cerco il device...ogni dipendente può averne + di 1 registrato a suo nome...
|
|
string UsrName = "";
|
|
string Dominio = "";
|
|
try
|
|
{
|
|
logger.lg.scriviLog(string.Format("Cookie trovato con devSecret {0}", devSecret), tipoLog.STARTUP);
|
|
device = DataWrap.DW.taAnagDev.getByDeviceSecret(devSecret)[0];
|
|
UsrName = device.User_Name;
|
|
Dominio = device.Dominio;
|
|
DataLayer.MatrOpr = device.MatrOpr; // salvo MatrOpr!
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog(string.Format("Errore recupero dati da cookie:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
|
}
|
|
if (UsrName != "" && Dominio != "")
|
|
{
|
|
logger.lg.scriviLog(string.Format("Dati utente da cookie: dominio {0}, user:{1}", Dominio, UsrName), tipoLog.STARTUP);
|
|
// 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
|
|
DataWrap.DW.taAnagDev.updateIP(device.IdxDevice, DateTime.Now, postazione_IP, userAgent);
|
|
}
|
|
// avvio utente...
|
|
user_std.UtSn.startUpUtente(Dominio, UsrName);
|
|
}
|
|
else
|
|
{
|
|
// svuoto cookie...
|
|
memLayer.ML.emptyCookieVal(memLayer.ML.confReadString("cookieName"));
|
|
// rimando pagina x registrazione devices
|
|
logger.lg.scriviLog(string.Format("Dominio / UsrName non validi / non trovati:{0}devSec:{1}{0}UsrName{2}{0}Dominio{3}", Environment.NewLine, devSecret, UsrName, Dominio), tipoLog.STARTUP);
|
|
Response.Redirect("~/regNewDevice.aspx");
|
|
}
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog(string.Format("Errore in checkAuthCookie:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// evento timer
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
lblData.Text = string.Format("{0:dd/MM/yyyy - HH:mm:ss}", DateTime.Now);
|
|
}
|
|
}
|
|
} |