Files
2020-05-19 10:02:03 +02:00

97 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AppData;
using SteamWare;
namespace CompanyRegistration.WebUserControls
{
public partial class cmp_resetPwd : System.Web.UI.UserControl
{
protected DataLayer dl = new DataLayer();
protected void Page_Load(object sender, EventArgs e)
{
precompileData();
}
protected string email
{
get
{
return memLayer.ML.QSS("email");
}
}
protected string token
{
get
{
return memLayer.ML.QSS("token");
}
}
private void precompileData()
{
if (string.IsNullOrEmpty(email))
{
// errore manca email
lblEmailError.Text = "Errore: manca email";
lblEmailError.Visible = true;
}
else
{
if (string.IsNullOrEmpty(token))
{
// errore manca token
lblTokenError.Text = "Errore: manca token";
lblTokenError.Visible = true;
}
else
{
// controllo su DB token ed email...
var userFound = dl.taAnagUsers.getByKey(email);
if (userFound != null || userFound.Count == 1)
{
// verifico il token...
if (userFound[0].saltSeed != token)
{
// errore manca token
lblTokenError.Text = "Errore: token";
lblTokenError.Visible = true;
}
else
{
lblEmailError.Visible = false;
lblEmailError.Visible = false;
lblEmail.Text = email;
lblToken.Text = token;
}
}
else
{
lblEmailError.Text = "Errore: email";
lblEmailError.Visible = true;
}
}
}
}
protected void lbtSubmit_Click(object sender, EventArgs e)
{
string newPwd = txtPassword.Text.Trim();
Guid obj = Guid.NewGuid();
string saltSeed = obj.ToString();
string saltPwd = SteamWare.SteamCrypto.EncryptString(newPwd, saltSeed);
// salvo la nuova pwd...
dl.taAnagUsers.updatePasswd(email, saltSeed, saltPwd);
// effettuo login con salvataggio cookie
// TODO FIXME
// rimando a sito
Response.Redirect("Default");
}
}
}