107 lines
5.0 KiB
C#
107 lines
5.0 KiB
C#
using Sarand.BusinessMgr.Net.Core.Web.App;
|
|
using Sarand.BusinessMgr.Net.Core.Web.Controllers;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Helpers;
|
|
using Sarand.Net.Standard.Base.Helpers;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
|
|
namespace Sarand.BusinessMgr.Web.Control.Models
|
|
{
|
|
//=======================================================================
|
|
public class Model_Security : SbmModel_Control
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public Model_Security(SbmLocaliser localiser) :
|
|
base(localiser)
|
|
{
|
|
//AdditionalFiles_CSS.Add("css/sbc-sec.css");
|
|
AdditionalFiles_JS.Add("js/sbc-sec.js");
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Page configuration.
|
|
public bool RequestPasswordMode { get { return !StringUtil.IsEmpty(rpe); } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Form properties.
|
|
public String EmailAddress { get; set; }
|
|
public String PasswordCurrent { get; set; }
|
|
public String Password { get; set; }
|
|
public String PasswordConfirm { get; set; }
|
|
public bool KeepMeSignedIn { get; set; }
|
|
/// <summary>Request Password Encrypted params - to allow Change Password without session or requiring old password.</summary>
|
|
public String rpe { get; set; }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validation.
|
|
//-------------------------------------------------------------------
|
|
// Sign-in.
|
|
public bool ValidateSignInData(SbmController_Base.AjaxResponse_Data responseData)
|
|
{
|
|
// Email address.
|
|
responseData.SetControlValue(nameof(EmailAddress), EmailAddress);
|
|
if (StringUtil.IsEmpty(EmailAddress))
|
|
responseData.SetControlError(nameof(EmailAddress), Localiser["msg.validation.mandatory.value"]);
|
|
else if (!SacsDataValidationHelper.IsValidEmailAddress(EmailAddress))
|
|
responseData.SetControlError(nameof(EmailAddress), Localiser["msg.validation.invalid.value"]);
|
|
|
|
// Password.
|
|
// NB Do not return the password value in the response.
|
|
if (StringUtil.IsEmpty(Password))
|
|
responseData.SetControlError(nameof(Password), Localiser["msg.validation.mandatory.value"]);
|
|
return !responseData.HasControlErrors();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Change password.
|
|
public bool ValidateChangePasswordData(SbmcUserAccount userAccount, SbmController_Base.AjaxResponse_Data responseData)
|
|
{
|
|
// Validate Passwords.
|
|
// NB Do not return the password values in the response.
|
|
// NB Only validate populated values - any null values are not part of the form for this request.
|
|
// - 'Current' password is not shown when changing password from 'Request Password' email link.
|
|
if (PasswordCurrent != null && StringUtil.IsEmpty(PasswordCurrent))
|
|
responseData.SetControlError(nameof(PasswordCurrent), Localiser["msg.validation.mandatory.value"]);
|
|
if (StringUtil.IsEmpty(Password))
|
|
responseData.SetControlError(nameof(Password), Localiser["msg.validation.mandatory.value"]);
|
|
if (StringUtil.IsEmpty(PasswordConfirm))
|
|
responseData.SetControlError(nameof(PasswordConfirm), Localiser["msg.validation.mandatory.value"]);
|
|
if (!StringUtil.IsEmpty(Password) && !StringUtil.IsEmpty(PasswordConfirm))
|
|
{
|
|
if (!Password.Equals(PasswordConfirm))
|
|
responseData.SetControlError(nameof(PasswordConfirm), Localiser["msg.validation.invalid.value"]);
|
|
if (!SbmcPasswordHelper.IsValidPassword(Password))
|
|
responseData.SetControlError(nameof(PasswordConfirm), Localiser.GetText("msg.warn.password.invalid", new object[] { SbmcPasswordHelper.Params.MinLength, SbmcPasswordHelper.Params.MinLengthNoComplexity }));
|
|
}
|
|
|
|
if (!responseData.HasControlErrors())
|
|
{
|
|
if (PasswordCurrent != null && !SbmcPasswordHelper.VerifyHashedPassword(userAccount, PasswordCurrent))
|
|
responseData.SetControlError(nameof(PasswordCurrent), Localiser["security.change.password.current.invalid"]);
|
|
if (SbmcPasswordHelper.VerifyHashedPassword(userAccount, Password))
|
|
responseData.SetControlError(nameof(Password), Localiser["security.change.password.not.changed"]);
|
|
}
|
|
return !responseData.HasControlErrors();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Request Password.
|
|
public bool ValidateRequestPasswordData(SbmController_Base.AjaxResponse_Data responseData)
|
|
{
|
|
// Email address.
|
|
responseData.SetControlValue(nameof(EmailAddress), EmailAddress);
|
|
if (StringUtil.IsEmpty(EmailAddress))
|
|
responseData.SetControlError(nameof(EmailAddress), Localiser["msg.validation.mandatory.value"]);
|
|
else if (!SacsDataValidationHelper.IsValidEmailAddress(EmailAddress))
|
|
responseData.SetControlError(nameof(EmailAddress), Localiser["msg.validation.invalid.value"]);
|
|
|
|
return !responseData.HasControlErrors();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|