Portal signin via Control Instance
This commit is contained in:
@@ -0,0 +1,189 @@
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.Controllers;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Helpers;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.Models.Account
|
||||
{
|
||||
//=======================================================================
|
||||
public class Model_UserAccount : SbmModel_Control
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public Model_UserAccount(SbmLocaliser localiser) :
|
||||
base(localiser)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Filter properties.
|
||||
public class FilterData
|
||||
{
|
||||
public string Search { get; set; }
|
||||
public string EmailAddress { get; set; }
|
||||
public string StatusCat { get; set; }
|
||||
public SbmcUserAccount.StatusCat GetStatusCat()
|
||||
{
|
||||
return EnumUtil.ParseEnum(StatusCat, SbmcUserAccount.StatusCat.NotDeleted);
|
||||
}
|
||||
}
|
||||
public FilterData Filter { get; } = new FilterData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Item properties.
|
||||
public class UserAccountData
|
||||
{
|
||||
public String Exists { get; set; }
|
||||
public string Id { get; set; }
|
||||
public string EmailAddress { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
public string Initials { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string PhoneMain { get; set; }
|
||||
public string PhoneMobile { get; set; }
|
||||
public string PhoneAlt { get; set; }
|
||||
public string StatusCode { get; set; }
|
||||
public SaStatus GetStatus() { return SacsSystem.GetStatusForCode(StatusCode); }
|
||||
}
|
||||
public UserAccountData User { get; } = new UserAccountData();
|
||||
// User emails.
|
||||
public string UserEmailAcountActivationPortal { get; set; }
|
||||
public string UserEmailRequestPasswordPortal { get; set; }
|
||||
public string UserEmailRequestPasswordControl { get; set; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validation.
|
||||
//-------------------------------------------------------------------
|
||||
// User.
|
||||
public bool ValidateUserData(Sacs.Web.Components.SaController.AjaxResponse_Data responseData)
|
||||
{
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposables = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// User email.
|
||||
if (User.EmailAddress != null)
|
||||
{
|
||||
string controlName = "UserEmailAddress";
|
||||
User.EmailAddress = User.EmailAddress.ToLowerInvariant();
|
||||
responseData.SetControlValue(controlName, User.EmailAddress);
|
||||
if (User.EmailAddress.IsBlank())
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.GetLength(User.EmailAddress) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_EmailAddress))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_EmailAddress)]);
|
||||
else if (!SacsDataValidationHelper.IsValidEmailAddress(User.EmailAddress))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
||||
else
|
||||
{
|
||||
// Check for duplicate email address.
|
||||
SbmcUserAccount.Params prmUserAccount = new SbmcUserAccount.Params();
|
||||
SysId userAccountId = User.Id.ToSysId();
|
||||
if (SysId.IsValid(userAccountId))
|
||||
prmUserAccount.IdsExcluded.Add(userAccountId);
|
||||
prmUserAccount.EmailAddress = User.EmailAddress;
|
||||
prmUserAccount.StatusCat = SbmcUserAccount.StatusCat.Any;
|
||||
if (ControlAccountMgr.GetUserAccountCount(prmUserAccount) > 0)
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.duplicate.value"]);
|
||||
}
|
||||
}
|
||||
|
||||
// User title.
|
||||
if (User.Title != null)
|
||||
{
|
||||
string controlName = "UserTitle";
|
||||
responseData.SetControlValue(controlName, User.Title);
|
||||
if (StringUtil.GetLength(User.Title) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_Title))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_Title)]);
|
||||
}
|
||||
|
||||
// User first name.
|
||||
if (User.FirstName != null)
|
||||
{
|
||||
string controlName = "UserFirstName";
|
||||
responseData.SetControlValue(controlName, User.FirstName);
|
||||
if (User.FirstName.IsBlank())
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.GetLength(User.FirstName) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_FirstName))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_FirstName)]);
|
||||
}
|
||||
|
||||
// User title.
|
||||
if (User.Initials != null)
|
||||
{
|
||||
string controlName = "UserInitials";
|
||||
responseData.SetControlValue(controlName, User.Initials);
|
||||
if (StringUtil.GetLength(User.Initials) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_Initials))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_Initials)]);
|
||||
}
|
||||
|
||||
// User last name.
|
||||
if (User.LastName != null)
|
||||
{
|
||||
string controlName = "UserLastName";
|
||||
responseData.SetControlValue(controlName, User.LastName);
|
||||
if (User.LastName.IsBlank())
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.GetLength(User.LastName) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_LastName))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_LastName)]);
|
||||
}
|
||||
|
||||
// Phone.
|
||||
if (User.PhoneMain != null)
|
||||
{
|
||||
string controlName = "UserPhoneMain";
|
||||
responseData.SetControlValue(controlName, User.PhoneMain);
|
||||
if (StringUtil.GetLength(User.PhoneMain) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneMain))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneMain)]);
|
||||
else if (!User.PhoneMain.IsEmpty() && !SacsDataValidationHelper.IsValidPhone(User.PhoneMain))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
|
||||
// Mobile Phone.
|
||||
if (User.PhoneMobile != null)
|
||||
{
|
||||
string controlName = "UserPhoneMobile";
|
||||
responseData.SetControlValue(controlName, User.PhoneMobile);
|
||||
if (StringUtil.GetLength(User.PhoneMobile) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneMobile))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneMobile)]);
|
||||
else if (!User.PhoneMobile.IsEmpty() && !SacsDataValidationHelper.IsValidPhone(User.PhoneMobile))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
|
||||
// Alt Phone.
|
||||
if (User.PhoneAlt != null)
|
||||
{
|
||||
string controlName = "UserPhoneAlt";
|
||||
responseData.SetControlValue(controlName, User.PhoneAlt);
|
||||
if (StringUtil.GetLength(User.PhoneAlt) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneAlt))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneAlt)]);
|
||||
else if (!User.PhoneAlt.IsEmpty() && !SacsDataValidationHelper.IsValidPhone(User.PhoneAlt))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
|
||||
// User status.
|
||||
if (User.StatusCode != null)
|
||||
{
|
||||
string controlName = "UserStatus";
|
||||
if (User.StatusCode.IsBlank())
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else if (!SbmcUserAccount.ValidStatuses.Contains(User.GetStatus()))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
}
|
||||
|
||||
return !responseData.HasControlErrors();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.Control.Models
|
||||
namespace Sarand.BusinessMgr.Web.Control.Models
|
||||
{
|
||||
public class ErrorViewModel
|
||||
{
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.Controllers;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Helpers;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.Models.Instance
|
||||
{
|
||||
//=======================================================================
|
||||
public class Model_Owner : SbmModel_Control
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public Model_Owner(SbmLocaliser localiser) :
|
||||
base(localiser)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Filter properties.
|
||||
public class FilterData
|
||||
{
|
||||
public String Search { get; set; }
|
||||
public String StatusCat { get; set; }
|
||||
public SbmcOwner.StatusCat GetStatusCat()
|
||||
{
|
||||
return EnumUtil.ParseEnum(StatusCat, SbmcOwner.StatusCat.NotDeleted);
|
||||
}
|
||||
}
|
||||
public FilterData Filter { get; } = new FilterData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Item properties.
|
||||
public class OwnerData
|
||||
{
|
||||
public String Exists { get; set; }
|
||||
public String Id { get; set; }
|
||||
public String Name { get; set; }
|
||||
public String ContactName { get; set; }
|
||||
public String ContactEmailAddress { get; set; }
|
||||
public String ContactPhoneMain { get; set; }
|
||||
public String ContactPhoneAlt { get; set; }
|
||||
public String StatusCode { get; set; }
|
||||
public SaStatus GetStatus() { return SacsSystem.GetStatusForCode(StatusCode); }
|
||||
}
|
||||
public OwnerData Owner { get; } = new OwnerData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validation.
|
||||
//-------------------------------------------------------------------
|
||||
// Owner.
|
||||
public bool ValidateOwnerData(SbmController_Base.AjaxResponse_Data responseData)
|
||||
{
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposables = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Owner name.
|
||||
if (Owner.Name != null)
|
||||
{
|
||||
String controlName = "OwnerName";
|
||||
responseData.SetControlValue(controlName, Owner.Name);
|
||||
if (StringUtil.IsBlank(Owner.Name))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.GetLength(Owner.Name) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Owner_Name))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Owner_Name)]);
|
||||
}
|
||||
|
||||
// Owner contact name.
|
||||
if (Owner.ContactName != null)
|
||||
{
|
||||
String controlName = "OwnerContactName";
|
||||
responseData.SetControlValue(controlName, Owner.ContactName);
|
||||
if (!StringUtil.IsBlank(Owner.ContactName))
|
||||
{
|
||||
if (StringUtil.GetLength(Owner.ContactName) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Owner_ContactName))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Owner_ContactName)]);
|
||||
}
|
||||
}
|
||||
|
||||
// Contact email.
|
||||
if (Owner.ContactEmailAddress != null)
|
||||
{
|
||||
String controlName = "OwnerContactEmailAddress";
|
||||
Owner.ContactEmailAddress = Owner.ContactEmailAddress.ToLowerInvariant();
|
||||
responseData.SetControlValue(controlName, Owner.ContactEmailAddress);
|
||||
if (!StringUtil.IsBlank(Owner.ContactEmailAddress))
|
||||
{
|
||||
if (StringUtil.GetLength(Owner.ContactEmailAddress) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Owner_ContactEmailAddress))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Owner_ContactEmailAddress)]);
|
||||
else if (!SacsDataValidationHelper.IsValidEmailAddress(Owner.ContactEmailAddress))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
}
|
||||
|
||||
// Contact Phone.
|
||||
if (Owner.ContactPhoneMain != null)
|
||||
{
|
||||
String controlName = "OwnerContactPhoneMain";
|
||||
responseData.SetControlValue(controlName, Owner.ContactPhoneMain);
|
||||
if (StringUtil.GetLength(Owner.ContactPhoneMain) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Owner_ContactPhoneMain))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Owner_ContactPhoneMain)]);
|
||||
else if (!StringUtil.IsEmpty(Owner.ContactPhoneMain) && !SacsDataValidationHelper.IsValidPhone(Owner.ContactPhoneMain))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
|
||||
// Contact Alt Phone.
|
||||
if (Owner.ContactPhoneAlt != null)
|
||||
{
|
||||
String controlName = "OwnerContactPhoneAlt";
|
||||
responseData.SetControlValue(controlName, Owner.ContactPhoneAlt);
|
||||
if (StringUtil.GetLength(Owner.ContactPhoneAlt) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Owner_ContactPhoneAlt))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Owner_ContactPhoneAlt)]);
|
||||
else if (!StringUtil.IsEmpty(Owner.ContactPhoneAlt) && !SacsDataValidationHelper.IsValidPhone(Owner.ContactPhoneAlt))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
|
||||
// Owner status.
|
||||
if (Owner.StatusCode != null)
|
||||
{
|
||||
String controlName = "OwnerStatus";
|
||||
if (StringUtil.IsBlank(Owner.StatusCode))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else if (!SbmcOwner.ValidStatuses.Contains(Owner.GetStatus()))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
}
|
||||
|
||||
return !responseData.HasControlErrors();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.Controllers;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Helpers;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.Models.Instance
|
||||
{
|
||||
//=======================================================================
|
||||
public class Model_Repository : SbmModel_Control
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public Model_Repository(SbmLocaliser localiser) :
|
||||
base(localiser)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Filter properties.
|
||||
public class FilterData
|
||||
{
|
||||
public String Search { get; set; }
|
||||
public String StatusCat { get; set; }
|
||||
public SbmcRepository.StatusCat GetStatusCat()
|
||||
{
|
||||
return EnumUtil.ParseEnum(StatusCat, SbmcRepository.StatusCat.NotDeleted);
|
||||
}
|
||||
}
|
||||
public FilterData Filter { get; } = new FilterData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Item properties.
|
||||
public class RepositoryData
|
||||
{
|
||||
public String Exists { get; set; }
|
||||
public String Id { get; set; }
|
||||
public String OwnerId { get; set; }
|
||||
public String Context { get; set; }
|
||||
public String ServerName { get; set; }
|
||||
public String InstanceName { get; set; }
|
||||
public String DatabaseName { get; set; }
|
||||
public String UserName { get; set; }
|
||||
public String Password { get; set; }
|
||||
public String StatusCode { get; set; }
|
||||
public SaStatus GetStatus() { return SacsSystem.GetStatusForCode(StatusCode); }
|
||||
}
|
||||
public RepositoryData Repository { get; } = new RepositoryData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validation.
|
||||
//-------------------------------------------------------------------
|
||||
// Repository.
|
||||
public bool ValidateRepositoryData(SbmController_Base.AjaxResponse_Data responseData)
|
||||
{
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposables = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Repository Owner.
|
||||
if (Repository.OwnerId != null)
|
||||
{
|
||||
String controlName = "RepositoryOwner";
|
||||
SysId ownerId = Repository.OwnerId.ToSysId();
|
||||
if (!SysId.IsValid(ownerId))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else
|
||||
{
|
||||
SbmcOwner owner = ControlInstanceMgr.GetOwnerById(ownerId);
|
||||
if (owner == null)
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Repository Context.
|
||||
if (Repository.Context != null)
|
||||
{
|
||||
String controlName = "RepositoryContext";
|
||||
responseData.SetControlValue(controlName, Repository.Context);
|
||||
if (StringUtil.IsBlank(Repository.Context))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.GetLength(Repository.Context) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Repository_Context))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Repository_Context)]);
|
||||
else
|
||||
{
|
||||
// Check for duplicate context.
|
||||
SbmcRepository.Params prmRepository = new SbmcRepository.Params();
|
||||
SysId repositoryId = Repository.Id.ToSysId();
|
||||
if (SysId.IsValid(repositoryId))
|
||||
prmRepository.IdsExcluded.Add(repositoryId);
|
||||
prmRepository.ContextsIncluded.Add(Repository.Context);
|
||||
prmRepository.StatusCat = SbmcRepository.StatusCat.Any;
|
||||
if (ControlInstanceMgr.GetRepositoryCount(prmRepository) > 0)
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.duplicate.value"]);
|
||||
}
|
||||
}
|
||||
|
||||
// Repository Server name.
|
||||
if (Repository.ServerName != null)
|
||||
{
|
||||
String controlName = "RepositoryServerName";
|
||||
responseData.SetControlValue(controlName, Repository.ServerName);
|
||||
if (StringUtil.IsBlank(Repository.ServerName))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.GetLength(Repository.ServerName) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Repository_ServerName))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Repository_ServerName)]);
|
||||
}
|
||||
|
||||
// Repository Instance name.
|
||||
if (Repository.InstanceName != null)
|
||||
{
|
||||
String controlName = "RepositoryInstanceName";
|
||||
responseData.SetControlValue(controlName, Repository.InstanceName);
|
||||
if (StringUtil.GetLength(Repository.InstanceName) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Repository_InstanceName))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Repository_InstanceName)]);
|
||||
}
|
||||
|
||||
// Repository Database name.
|
||||
if (Repository.DatabaseName != null)
|
||||
{
|
||||
String controlName = "RepositoryDatabaseName";
|
||||
responseData.SetControlValue(controlName, Repository.DatabaseName);
|
||||
if (StringUtil.IsBlank(Repository.DatabaseName))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.GetLength(Repository.DatabaseName) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Repository_DatabaseName))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Repository_DatabaseName)]);
|
||||
}
|
||||
|
||||
// Repository User name.
|
||||
if (Repository.UserName != null)
|
||||
{
|
||||
String controlName = "RepositoryUserName";
|
||||
responseData.SetControlValue(controlName, Repository.UserName);
|
||||
if (StringUtil.GetLength(Repository.UserName) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Repository_UserName))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Repository_UserName)]);
|
||||
}
|
||||
|
||||
// Repository password.
|
||||
if (Repository.Password != null)
|
||||
{
|
||||
String controlName = "RepositoryPassword";
|
||||
responseData.SetControlValue(controlName, Repository.Password);
|
||||
if (StringUtil.GetLength(Repository.Password) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Repository_Password))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.Repository_Password)]);
|
||||
}
|
||||
|
||||
// Repository status.
|
||||
if (Repository.StatusCode != null)
|
||||
{
|
||||
String controlName = "RepositoryStatus";
|
||||
if (StringUtil.IsBlank(Repository.StatusCode))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else if (!SbmcRepository.ValidStatuses.Contains(Repository.GetStatus()))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
}
|
||||
|
||||
return !responseData.HasControlErrors();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.Control.Models
|
||||
namespace Sarand.BusinessMgr.Web.Control.Models
|
||||
{
|
||||
//=======================================================================
|
||||
public class Model_Home : SbmModel_Control
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
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();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
using DocumentFormat.OpenXml.EMMA;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.Controllers;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.CodeTypes;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Helpers;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.Models.Param
|
||||
{
|
||||
//=======================================================================
|
||||
public class Model_Param : SbmModel_Control
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public Model_Param(SbmLocaliser localiser) :
|
||||
base(localiser)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>List of Item Types for dropdown.</summary>
|
||||
public IEnumerable<SelectListItem> GetParamItemTypesForSelect()
|
||||
{
|
||||
List<CodeDesc> codeTypes = new List<CodeDesc>();
|
||||
foreach (var itemType in SbmcItemParam.ValidItemTypes)
|
||||
codeTypes.Add(((int)itemType).ToString(), itemType.ToString());
|
||||
return new SelectList(codeTypes, "Code", "Desc");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Filter properties.
|
||||
public class FilterData
|
||||
{
|
||||
public string ItemType { get; set; }
|
||||
public string ItemId { get; set; }
|
||||
public string Search { get; set; }
|
||||
public string StatusCat { get; set; }
|
||||
public SbmcItemParam.StatusCat GetStatusCat()
|
||||
{
|
||||
return EnumUtil.ParseEnum(StatusCat, SbmcItemParam.StatusCat.NotDeleted);
|
||||
}
|
||||
}
|
||||
public FilterData Filter { get; } = new FilterData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Item properties.
|
||||
public class ItemParamData
|
||||
{
|
||||
public String Exists { get; set; }
|
||||
public string Id { get; set; }
|
||||
public string ItemType { get; set; }
|
||||
public string ItemId { get; set; }
|
||||
public string Context { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Value { get; set; }
|
||||
public string ValueChanged { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public string StatusCode { get; set; }
|
||||
public SaStatus GetStatus() { return SacsSystem.GetStatusForCode(StatusCode); }
|
||||
}
|
||||
public ItemParamData Param { get; } = new ItemParamData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validation.
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
public bool ValidateParamData(Sacs.Web.Components.SaController.AjaxResponse_Data responseData)
|
||||
{
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposables = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
// Check whether data suggests that Param exists.
|
||||
bool paramExists = StringUtil.ToBool(Param.Exists) && SysId.IsValid(Param.Id.ToSysId());
|
||||
|
||||
// Item.
|
||||
if (Param.ItemType != null || Param.ItemId != null)
|
||||
{
|
||||
string controlName = "ParamItem";
|
||||
ItemId itemId = new ItemId(StringUtil.ToShort(Param.ItemType), Param.ItemId.ToSysId());
|
||||
if (!paramExists && (Param.ItemType.IsBlank() || Param.ItemId.IsBlank()))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.IsBlank(ControlItemMgr.GetItemCaption(itemId)))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
|
||||
// Context.
|
||||
if (Param.Context != null)
|
||||
{
|
||||
string controlName = "ParamContext";
|
||||
responseData.SetControlValue(controlName, Param.Context);
|
||||
if (Param.Context.IsBlank())
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.GetLength(Param.Context) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.ItemParam_Context))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.ItemParam_Context)]);
|
||||
}
|
||||
|
||||
// Name.
|
||||
if (Param.Name != null)
|
||||
{
|
||||
string controlName = "ParamName";
|
||||
responseData.SetControlValue(controlName, Param.Name);
|
||||
if (Param.Name.IsBlank())
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.GetLength(Param.Name) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.ItemParam_Name))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.ItemParam_Name)]);
|
||||
}
|
||||
|
||||
// Value.
|
||||
if (Param.Value != null)
|
||||
{
|
||||
string controlName = "ParamValue";
|
||||
responseData.SetControlValue(controlName, Param.Value);
|
||||
if (StringUtil.GetLength(Param.Value) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.ItemParam_Value))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.ItemParam_Value)]);
|
||||
}
|
||||
|
||||
// Notes.
|
||||
if (Param.Notes != null)
|
||||
{
|
||||
string controlName = "ParamNotes";
|
||||
responseData.SetControlValue(controlName, Param.Notes);
|
||||
if (StringUtil.GetLength(Param.Notes) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.ItemParam_Notes))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.ItemParam_Notes)]);
|
||||
}
|
||||
|
||||
// User status.
|
||||
if (Param.StatusCode != null)
|
||||
{
|
||||
string controlName = "ParamStatus";
|
||||
if (Param.StatusCode.IsBlank())
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else if (!SbmcItemParam.ValidStatuses.Contains(Param.GetStatus()))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
}
|
||||
|
||||
return !responseData.HasControlErrors();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -1,19 +1,55 @@
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.Models;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
||||
using Sarand.BusinessMgr.Web.Control.App;
|
||||
using System;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.Control.Models
|
||||
namespace Sarand.BusinessMgr.Web.Control.Models
|
||||
{
|
||||
//=======================================================================
|
||||
public class SbmModel_Control : SbmModel_Base
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Protected construction.
|
||||
protected SbmModel_Control(SbmLocaliser localiser) :
|
||||
base(localiser)
|
||||
{
|
||||
}
|
||||
//=======================================================================
|
||||
public class SbmModel_Control : SbmModel_Base
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Protected construction.
|
||||
protected SbmModel_Control(SbmLocaliser localiser) :
|
||||
base(localiser)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public SbmSessionData_Control SessionData_Control { get { return SessionData as SbmSessionData_Control; } }
|
||||
public override ISbmUserContext_Core UserContext_Core { get { return new SbmUserContext_Control(SessionData_Control); } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Form control value max length - BusinessMgr tables.
|
||||
/// <para>In many cases the database columns allow plenty of extra space for the value, in case they need to be encrypted.</para>
|
||||
/// <para>Hence, several cases where the value entered in the control isn't allowed the full database length.</para>
|
||||
/// </summary>
|
||||
public int GetControlMaxLength(SbmDbDfn_Control.ColumnIdx column)
|
||||
{
|
||||
int maxLength = (int)SbmDbDfn_Control.GetColTextLen(column);
|
||||
switch (column)
|
||||
{
|
||||
case SbmDbDfn_Control.ColumnIdx.UserAccount_EmailAddress:
|
||||
return Math.Min(maxLength, 100);
|
||||
case SbmDbDfn_Control.ColumnIdx.UserAccount_FirstName:
|
||||
case SbmDbDfn_Control.ColumnIdx.UserAccount_LastName:
|
||||
return Math.Min(maxLength, 40);
|
||||
case SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneMain:
|
||||
case SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneMobile:
|
||||
case SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneAlt:
|
||||
return Math.Min(maxLength, 20);
|
||||
case SbmDbDfn_Control.ColumnIdx.ItemParam_Value:
|
||||
if (maxLength == 0 || maxLength > 2048) return 2048;
|
||||
break;
|
||||
}
|
||||
return maxLength;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user