135 lines
4.7 KiB
C#
135 lines
4.7 KiB
C#
using SteamWare;
|
|
using System;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
|
|
namespace MoonProTablet.WebUserControls
|
|
{
|
|
public partial class mod_enrollByAuthKey : BaseUserControl
|
|
{
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// prova a fare enroll device data chiave...
|
|
/// </summary>
|
|
/// <param name="MatrOpr"></param>
|
|
/// <param name="userAgent"></param>
|
|
/// <param name="fatto"></param>
|
|
/// <param name="DeviceName"></param>
|
|
/// <param name="IPv4"></param>
|
|
/// <param name="userKey"></param>
|
|
/// <returns></returns>
|
|
private bool tryEnroll(int MatrOpr, string userAgent, bool fatto, string DeviceName, string IPv4, string userKey)
|
|
{
|
|
try
|
|
{
|
|
fatto = DataLayerObj.enrollDevice(userKey, IPv4, DeviceName, userAgent, MatrOpr);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog(string.Format("Errore in registrazione nuovo device con AuthKey utente: {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// resetto tutto
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnAnnulla_Click(object sender, EventArgs e)
|
|
{
|
|
txtUserAuthKey.Text = "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// salvo nuovo device...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnConferma_Click(object sender, EventArgs e)
|
|
{
|
|
Page page = this.Page;
|
|
bool fatto = false;
|
|
// controllo se ho i dati...
|
|
string plainUserAuthKey = txtUserAuthKey.Text.Trim();
|
|
// in primis cerco il dipendente data la authKey...
|
|
int MatrOpr = 0;
|
|
string generOpr = "";
|
|
try
|
|
{
|
|
MatrOpr = Convert.ToInt32(ddlIdxDipendente.SelectedValue);
|
|
}
|
|
catch
|
|
{ }
|
|
try
|
|
{
|
|
// controllo dipendente... che sia selezionato uno valido
|
|
if (MatrOpr > 0)
|
|
{
|
|
// recupero dati...
|
|
string userAgent = "";
|
|
string DeviceName = "";
|
|
string IPv4 = "";
|
|
userAgent = Request.UserAgent;
|
|
DeviceName = Request.UserHostName;
|
|
IPv4 = Request.UserHostName;
|
|
// calcolo authKey MD5...
|
|
string md5UserAuthKey = SteamCrypto.EncryptString(plainUserAuthKey, memLayer.ML.CRS("cookieName"));
|
|
if (DataLayerObj.taOp.getByMatrAuthKey(MatrOpr, md5UserAuthKey).Rows.Count > 0)
|
|
{
|
|
fatto = tryEnroll(MatrOpr, userAgent, fatto, DeviceName, IPv4, md5UserAuthKey);
|
|
}
|
|
// provo con "plainUserKey"
|
|
else if (DataLayerObj.taOp.getByMatrAuthKey(MatrOpr, plainUserAuthKey).Rows.Count > 0)
|
|
{
|
|
fatto = tryEnroll(MatrOpr, userAgent, fatto, DeviceName, IPv4, plainUserAuthKey);
|
|
}
|
|
else
|
|
{
|
|
lblWarning.Text = "AuthKey non trovata! richiedere reset ad Admin.";
|
|
lblWarning.Visible = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lblWarning.Text = "Dipendente non trovato!";
|
|
lblWarning.Visible = true;
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog(string.Format("Errore in registrazione device: {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
|
}
|
|
if (fatto)
|
|
{
|
|
try
|
|
{
|
|
generOpr = controllerMapo.getCognomeNomeDaMatr(MatrOpr);
|
|
// registro login
|
|
DataLayerObj.taDiarioDich.insertQuery("UserLogin", "", DateTime.Now, MatrOpr, $"Login: {generOpr}");
|
|
}
|
|
catch
|
|
{ }
|
|
Response.Redirect(memLayer.ML.CRS("mainPage"), true);
|
|
HttpContext.Current.ApplicationInstance.CompleteRequest();
|
|
page.Visible = false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Page load (vuoto)
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
} |