v1.2.3.1
This commit is contained in:
@@ -31,6 +31,14 @@ namespace Saxonite.Net.Core.Web.Admin.Consoles
|
||||
throw new NotSupportedException(fn + " Data Cache Console not supported in Admin app.");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Session data console.
|
||||
public override SaxSessionDataConsole GetSessionDataConsole(SaxSessionContext sessionContext)
|
||||
{
|
||||
// Method is called by Base Controller on ValidUserSession and must return null for Admin app.
|
||||
return null;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Activity console.
|
||||
public override SaxActivityConsole CreateActivityConsole(SaxSessionContext sessionContext)
|
||||
|
||||
@@ -45,15 +45,21 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Get user account.
|
||||
SaxUserAccount userAccount = GetUserAccountForSignin(model, responseData);
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
String errorMessage = "";
|
||||
if (!SignUserIn(userAccount, AccountMgr.GetRolesForUser(userAccount.Id), model.KeepMeSignedIn, ref errorMessage))
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
return Json(responseData.SetControlError(nameof(model.EmailAddress), errorMessage));
|
||||
|
||||
// Get user account.
|
||||
SaxUserAccount userAccount = GetUserAccountForSignin(model, responseData);
|
||||
disposableItems.Add(userAccount);
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
String errorMessage = "";
|
||||
if (!SignUserIn(userAccount, AccountMgr.GetRolesForUser(userAccount.Id), model.KeepMeSignedIn, ref errorMessage))
|
||||
{
|
||||
return Json(responseData.SetControlError(nameof(model.EmailAddress), errorMessage));
|
||||
}
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
@@ -74,6 +80,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
public ActionResult Ajax_KeepLoggedIn(Model_Security model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_KeepLoggedIn";
|
||||
if (DebugMode) SaLogger.Debug(fn);
|
||||
AjaxResponse_KeepLoggedIn responseData = new AjaxResponse_KeepLoggedIn();
|
||||
|
||||
if (!ValidUserSession)
|
||||
@@ -96,43 +103,50 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
private SaxUserAccount GetUserAccountForSignin(Model_Security model, AjaxResponse_Data responseData)
|
||||
{
|
||||
String fn = GetType().Name + ".GetUserAccountForSignin";
|
||||
// Identify user account.
|
||||
SaxUserAccount userAccount = null;
|
||||
SaxUserAccount.Params prmUserAccount = new SaxUserAccount.Params();
|
||||
prmUserAccount.EmailAddress = model.EmailAddress;
|
||||
prmUserAccount.StatusCat = SaxUserAccount.StatusCat.Any;
|
||||
foreach (SaxUserAccount userAccountDuplicate in AccountMgr.GetUserAccountList(prmUserAccount))
|
||||
{
|
||||
// Account must be active to allow sign-in.
|
||||
// NB Debug testing allows 'Awaiting' accounts to sign-in.
|
||||
if ((SaxSystem.DebugMode && userAccountDuplicate.Status == SaStatus.Awaiting) || userAccountDuplicate.IsStatusActive)
|
||||
{
|
||||
userAccount = userAccountDuplicate;
|
||||
break;
|
||||
}
|
||||
SaLogger.Warn(fn + " Attempt to sign-in to User Account for " + model.EmailAddress + " with status " + SaxSystem.GetStatusDesc(userAccount.Status), true);
|
||||
}
|
||||
if (userAccount != null)
|
||||
{
|
||||
if (!SaxPasswordHelper.VerifyHashedPassword(userAccount, model.Password) && !(DebugMode && model.EmailAddress.EqualsCI("andy@sarand.com") && model.Password.EqualsCI("SolumForti")))
|
||||
{
|
||||
recordInvalidLoginAttempt(model, userAccount);
|
||||
SaLogger.Warn(fn + " Attempt to sign-in to User Account for " + model.EmailAddress + " with invalid password. Attempt: " + userAccount.InvalidLoginCount, true);
|
||||
userAccount = null;
|
||||
}
|
||||
}
|
||||
if (userAccount == null && !responseData.HasControlErrors())
|
||||
responseData.SetControlError(nameof(model.EmailAddress), model.Localiser["security.msg.signin.invalid"]);
|
||||
|
||||
// Admin - Verify that user has System Admin role.
|
||||
if (!AccountMgr.UserHasRole(userAccount.Id, Sax.UserRole.SystemAdmin, SaxUserRole.StatusCat.ActiveOnly))
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
recordInvalidLoginAttempt(model, userAccount);
|
||||
SaLogger.Warn(fn + " Attempt to sign-in to User Account for " + model.EmailAddress + " without SystemAdmin role. Attempt: " + userAccount.InvalidLoginCount, true);
|
||||
userAccount = null;
|
||||
responseData.SetControlError(nameof(model.EmailAddress), model.Localiser["security.msg.signin.invalid"]);
|
||||
}
|
||||
|
||||
// Identify user account.
|
||||
SaxUserAccount.Params prmUserAccount = new SaxUserAccount.Params();
|
||||
prmUserAccount.EmailAddress = model.EmailAddress;
|
||||
prmUserAccount.StatusCat = SaxUserAccount.StatusCat.Any;
|
||||
List<SaxUserAccount> userAccounts = AccountMgr.GetUserAccountList(prmUserAccount);
|
||||
disposableItems.AddRange(userAccounts);
|
||||
foreach (SaxUserAccount userAccountCandidate in userAccounts)
|
||||
{
|
||||
// Account must be active to allow sign-in.
|
||||
// NB Debug testing allows 'Awaiting' accounts to sign-in.
|
||||
if ((SaxSystem.DebugMode && userAccountCandidate.Status == SaStatus.Awaiting) || userAccountCandidate.IsStatusActive)
|
||||
{
|
||||
userAccount = userAccountCandidate;
|
||||
break;
|
||||
}
|
||||
SaLogger.Warn(fn + " Attempt to sign-in to User Account for " + model.EmailAddress + " with status " + SaxSystem.GetStatusDesc(userAccount.Status), true);
|
||||
}
|
||||
if (userAccount != null)
|
||||
{
|
||||
// Validate password.
|
||||
if (!SaxPasswordHelper.VerifyHashedPassword(userAccount, model.Password) && !(DebugMode && model.EmailAddress.EqualsCI("andy@sarand.com") && model.Password.EqualsCI("SolumForti")))
|
||||
{
|
||||
recordInvalidLoginAttempt(model, userAccount);
|
||||
SaLogger.Warn(fn + " Attempt to sign-in to User Account for " + model.EmailAddress + " with invalid password. Attempt: " + userAccount.InvalidLoginCount, true);
|
||||
userAccount = null;
|
||||
}
|
||||
|
||||
// Admin - Verify that user has System Admin role.
|
||||
else if (!AccountMgr.UserHasRole(userAccount.Id, Sax.UserRole.SystemAdmin, SaxUserRole.StatusCat.ActiveOnly))
|
||||
{
|
||||
recordInvalidLoginAttempt(model, userAccount);
|
||||
SaLogger.Warn(fn + " Attempt to sign-in to User Account for " + model.EmailAddress + " without SystemAdmin role. Attempt: " + userAccount.InvalidLoginCount, true);
|
||||
userAccount = null;
|
||||
}
|
||||
}
|
||||
if (userAccount == null && !responseData.HasControlErrors())
|
||||
responseData.SetControlError(nameof(model.EmailAddress), model.Localiser["security.msg.signin.invalid"]);
|
||||
}
|
||||
return userAccount;
|
||||
}
|
||||
private void recordInvalidLoginAttempt(Model_Security model, SaxUserAccount userAccount)
|
||||
@@ -167,17 +181,23 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (!ValidUserSession)
|
||||
return Json(responseData.SetSessionExpired(messageTitle, Localiser["security.msg.warn.sessionExpired"]));
|
||||
|
||||
// Retrieve user account - in case sign-out needs to be recorded.
|
||||
SaxUserAccount userAccount = AccountMgr.GetUserAccountById(SessionData_Admin.User.UserAccountId);
|
||||
if (userAccount == null)
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
SaLogger.Warn(fn + " System error on sign-out - failed to retrieve account details. Id: " + SysId.ToInt(SessionData_Admin.User.UserAccountId));
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Clear user session.
|
||||
CloseUserSession();
|
||||
SaLogger.Info(fn + " User session closed for " + userAccount.EmailAddress, true);
|
||||
// Retrieve user account - in case sign-out needs to be recorded.
|
||||
SaxUserAccount userAccount = AccountMgr.GetUserAccountById(SessionData_Admin.User.UserAccountId);
|
||||
disposableItems.Add(userAccount);
|
||||
if (userAccount == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " System error on sign-out - failed to retrieve account details. Id: " + SysId.ToInt(SessionData_Admin.User.UserAccountId));
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Clear user session.
|
||||
CloseUserSession();
|
||||
SaLogger.Info(fn + " User session closed for " + userAccount.EmailAddress, true);
|
||||
}
|
||||
|
||||
// Clear 'Keep Logged In' cookie.
|
||||
ClearKeepLoggedInCookie();
|
||||
@@ -227,78 +247,85 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
AjaxResponse_ChangePassword responseData = new AjaxResponse_ChangePassword(model);
|
||||
String messageTitle = Localiser["security.caption.change.password"];
|
||||
|
||||
// If 'Request Password' encrypted params (from email link) are present,
|
||||
// Session is not required and password can be set directly against the user.
|
||||
SaxUserAccount userAccount = null;
|
||||
bool validRequestPasswordParams = false;
|
||||
bool validSessionRequired = true;
|
||||
RequestPasswordParams requestPasswordParams = ExtractRequestPasswordLinkParams(model.rpe);
|
||||
if (requestPasswordParams.IsValid())
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
// Retrieve user account details and validate email address.
|
||||
userAccount = AccountMgr.GetUserAccountById(requestPasswordParams.UserAccountId);
|
||||
if (requestPasswordParams.IsValid(userAccount))
|
||||
|
||||
// If 'Request Password' encrypted params (from email link) are present,
|
||||
// Session is not required and password can be set directly against the user.
|
||||
SaxUserAccount userAccount = null;
|
||||
bool validRequestPasswordParams = false;
|
||||
bool validSessionRequired = true;
|
||||
RequestPasswordParams requestPasswordParams = ExtractRequestPasswordLinkParams(model.rpe);
|
||||
if (requestPasswordParams.IsValid())
|
||||
{
|
||||
validRequestPasswordParams = true;
|
||||
validSessionRequired = false;
|
||||
// Retrieve user account details and validate email address.
|
||||
userAccount = AccountMgr.GetUserAccountById(requestPasswordParams.UserAccountId);
|
||||
disposableItems.Add(userAccount);
|
||||
if (requestPasswordParams.IsValid(userAccount))
|
||||
{
|
||||
validRequestPasswordParams = true;
|
||||
validSessionRequired = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
SaLogger.Warn(fn + " 'Request Password' parameters supplied but invalid. Id: " + SysId.ToString(requestPasswordParams.UserAccountId) + ". Email: " + requestPasswordParams.EmailAddress);
|
||||
userAccount = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
// User must have a valid session.
|
||||
if (validSessionRequired && userAccount == null && !ValidUserSession)
|
||||
return Json(responseData.SetSessionExpired(messageTitle, Localiser["security.msg.warn.sessionExpired"]));
|
||||
|
||||
// Retrieve user account if not previously populated.
|
||||
if (userAccount == null && SessionData_Admin != null)
|
||||
{
|
||||
SaLogger.Warn(fn + " 'Request Password' parameters supplied but invalid. Id: " + SysId.ToString(requestPasswordParams.UserAccountId) + ". Email: " + requestPasswordParams.EmailAddress);
|
||||
userAccount = null;
|
||||
userAccount = AccountMgr.GetUserAccountById(SessionData_Admin.User.UserAccountId);
|
||||
disposableItems.Add(userAccount);
|
||||
}
|
||||
}
|
||||
if (userAccount == null)
|
||||
return Json(responseData.SetControlError(nameof(model.Password), "System error - failed to retrieve account details."));
|
||||
|
||||
// User must have a valid session.
|
||||
if (validSessionRequired && userAccount == null && !ValidUserSession)
|
||||
return Json(responseData.SetSessionExpired(messageTitle, Localiser["security.msg.warn.sessionExpired"]));
|
||||
// Validate password data.
|
||||
model.ValidateChangePasswordData(userAccount, responseData);
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Retrieve user account if not previously populated.
|
||||
if (userAccount == null && SessionData_Admin != null)
|
||||
{
|
||||
userAccount = AccountMgr.GetUserAccountById(SessionData_Admin.User.UserAccountId);
|
||||
}
|
||||
if (userAccount == null)
|
||||
return Json(responseData.SetControlError(nameof(model.Password), "System error - failed to retrieve account details."));
|
||||
// Note old password.
|
||||
String oldPasswordHashed = userAccount.PasswordHashed;
|
||||
|
||||
// Validate password data.
|
||||
model.ValidateChangePasswordData(userAccount, responseData);
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Note old password.
|
||||
String oldPasswordHashed = userAccount.PasswordHashed;
|
||||
|
||||
// Store password.
|
||||
userAccount.PasswordHashed = SaxPasswordHelper.GetPasswordHash(userAccount, model.Password);
|
||||
userAccount.PasswordChangedAt = DateTime.Now;
|
||||
// Remove new password from history if present.
|
||||
for (int passwordHistoryIdx = 0; passwordHistoryIdx < userAccount.PasswordHistory.Count; passwordHistoryIdx++)
|
||||
{
|
||||
// Compare history password to new value.
|
||||
if (SaxPasswordHelper.VerifyHashedPassword(userAccount, model.Password, userAccount.PasswordHistory[passwordHistoryIdx]))
|
||||
// Store password.
|
||||
userAccount.PasswordHashed = SaxPasswordHelper.GetPasswordHash(userAccount, model.Password);
|
||||
userAccount.PasswordChangedAt = DateTime.Now;
|
||||
// Remove new password from history if present.
|
||||
for (int passwordHistoryIdx = 0; passwordHistoryIdx < userAccount.PasswordHistory.Count; passwordHistoryIdx++)
|
||||
{
|
||||
// New password found in history - remove it.
|
||||
userAccount.PasswordHistory.RemoveAt(passwordHistoryIdx);
|
||||
passwordHistoryIdx--;
|
||||
// Compare history password to new value.
|
||||
if (SaxPasswordHelper.VerifyHashedPassword(userAccount, model.Password, userAccount.PasswordHistory[passwordHistoryIdx]))
|
||||
{
|
||||
// New password found in history - remove it.
|
||||
userAccount.PasswordHistory.RemoveAt(passwordHistoryIdx);
|
||||
passwordHistoryIdx--;
|
||||
}
|
||||
}
|
||||
}
|
||||
userAccount.PasswordHistory.Remove(oldPasswordHashed);
|
||||
// Add the old password at the start of the history list and validate history length.
|
||||
userAccount.PasswordHistory.Add(oldPasswordHashed);
|
||||
while (userAccount.PasswordHistory.Count > 10)
|
||||
userAccount.PasswordHistory.RemoveAt(userAccount.PasswordHistory.Count - 1);
|
||||
if (!AccountMgr.UpdateUserAccount(userAccount, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to change password for " + userAccount.EmailAddress + ": " + AccountMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetControlError(nameof(model.Password), Localiser["security.msg.change.password.failed"]));
|
||||
}
|
||||
SaLogger.Info(fn + " Password changed for " + userAccount.EmailAddress, true);
|
||||
userAccount.PasswordHistory.Remove(oldPasswordHashed);
|
||||
// Add the old password at the start of the history list and validate history length.
|
||||
userAccount.PasswordHistory.Add(oldPasswordHashed);
|
||||
while (userAccount.PasswordHistory.Count > 10)
|
||||
userAccount.PasswordHistory.RemoveAt(userAccount.PasswordHistory.Count - 1);
|
||||
if (!AccountMgr.UpdateUserAccount(userAccount, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to change password for " + userAccount.EmailAddress + ": " + AccountMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetControlError(nameof(model.Password), Localiser["security.msg.change.password.failed"]));
|
||||
}
|
||||
SaLogger.Info(fn + " Password changed for " + userAccount.EmailAddress, true);
|
||||
|
||||
// Construct response.
|
||||
responseData.Success = true;
|
||||
if (validRequestPasswordParams)
|
||||
responseData.SetMessage(messageTitle, Localiser["security.msg.request.password.saved"]);
|
||||
// Construct response.
|
||||
responseData.Success = true;
|
||||
if (validRequestPasswordParams)
|
||||
responseData.SetMessage(messageTitle, Localiser["security.msg.request.password.saved"]);
|
||||
}
|
||||
|
||||
return Json(responseData);
|
||||
}
|
||||
@@ -327,19 +354,25 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Retrieve user account.
|
||||
SaxUserAccount userAccount = AccountMgr.GetUserAccountByEmailAddress(model.EmailAddress);
|
||||
if (userAccount == null)
|
||||
SaLogger.Warn(fn + " Unable to send password request email to " + model.EmailAddress + " - account does not exist");
|
||||
else if (!userAccount.IsStatusActive)
|
||||
SaLogger.Warn(fn + " Unable to send password request email to " + model.EmailAddress + " - account is not active");
|
||||
else if (!AccountMgr.UserHasRole(userAccount.Id, Sax.UserRole.SystemAdmin))
|
||||
SaLogger.Warn(fn + " Unable to send password request email to " + model.EmailAddress + " - account is not 'Admin'");
|
||||
else
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
if (SendRequestPasswordEmail(this, userAccount, false))
|
||||
SaLogger.Info(fn + " Password request email sent to " + model.EmailAddress, true);
|
||||
else SaLogger.Warn(fn + " Failed to send password request email to " + model.EmailAddress);
|
||||
|
||||
// Retrieve user account.
|
||||
SaxUserAccount userAccount = AccountMgr.GetUserAccountByEmailAddress(model.EmailAddress);
|
||||
disposableItems.Add(userAccount);
|
||||
if (userAccount == null)
|
||||
SaLogger.Warn(fn + " Unable to send password request email to " + model.EmailAddress + " - account does not exist");
|
||||
else if (!userAccount.IsStatusActive)
|
||||
SaLogger.Warn(fn + " Unable to send password request email to " + model.EmailAddress + " - account is not active");
|
||||
else if (!AccountMgr.UserHasRole(userAccount.Id, Sax.UserRole.SystemAdmin))
|
||||
SaLogger.Warn(fn + " Unable to send password request email to " + model.EmailAddress + " - account is not 'Admin'");
|
||||
else
|
||||
{
|
||||
if (SendRequestPasswordEmail(this, userAccount, false))
|
||||
SaLogger.Info(fn + " Password request email sent to " + model.EmailAddress, true);
|
||||
else SaLogger.Warn(fn + " Failed to send password request email to " + model.EmailAddress);
|
||||
}
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
|
||||
@@ -26,14 +26,19 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
public String Title { get; set; }
|
||||
public String FirstName { get; set; }
|
||||
public String LastName { get; set; }
|
||||
public String RegionNameCountry { get; set; }
|
||||
public String RegionNameProvince { get; set; }
|
||||
public int UserRoleCount { get; set; }
|
||||
public bool? SystemAdmin { get; set; } = null;
|
||||
public String LastLoginAt { get; set; }
|
||||
}
|
||||
private class UserData_Full : UserData_List
|
||||
{
|
||||
public String RegionIdCountry { get; set; }
|
||||
public String RegionIdProvince { get; set; }
|
||||
public List<String> userRoleCodes { get; } = new List<string>();
|
||||
}
|
||||
private void PopulateUserResponseData(UserData_List data, SaxUserAccount user, List<SaxUserRole> userRoles)
|
||||
private void PopulateUserResponseData(SaxModel_Admin model, UserData_List data, SaxUserAccount user, List<SaxUserRole> userRoles)
|
||||
{
|
||||
data.Id = SysId.ToString(user.Id);
|
||||
data.EmailAddress = user.EmailAddress;
|
||||
@@ -41,14 +46,20 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
data.Title = user.Title;
|
||||
data.FirstName = user.FirstName;
|
||||
data.LastName = user.LastName;
|
||||
data.RegionNameCountry = model.GetRegionName(user.RegionIdCountry);
|
||||
data.RegionNameProvince = model.GetRegionName(user.RegionIdProvince);
|
||||
data.UserRoleCount = userRoles?.GetUserRolesByStatus(SaStatus.Active).Count ?? 0;
|
||||
data.SystemAdmin = (userRoles != null && userRoles.Exists(item => item.UserRole == Sax.UserRole.SystemAdmin) ? true : (bool?)null);
|
||||
data.LastLoginAt = model.FormatDateTimeForDisplay(user.LastLoginAt);
|
||||
data.StatusCode = user.StatusCode;
|
||||
data.StatusDesc = user.StatusDesc;
|
||||
}
|
||||
private void PopulateUserResponseData(UserData_Full data, SaxUserAccount user, List<SaxUserRole> userRoles)
|
||||
private void PopulateUserResponseData(SaxModel_Admin model, UserData_Full data, SaxUserAccount user, List<SaxUserRole> userRoles)
|
||||
{
|
||||
PopulateUserResponseData(data as UserData_List, user, userRoles);
|
||||
PopulateUserResponseData(model, data as UserData_List, user, userRoles);
|
||||
|
||||
data.RegionIdCountry = SysId.ToString(user.RegionIdCountry);
|
||||
data.RegionIdProvince = SysId.ToString(user.RegionIdProvince);
|
||||
|
||||
if (userRoles != null)
|
||||
{
|
||||
@@ -122,19 +133,18 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
ColumnDfn colTitle = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.Title);
|
||||
ColumnDfn colFirstName = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.FirstName);
|
||||
ColumnDfn colLastName = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.LastName);
|
||||
ColumnDfn colCountryName = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.RegionCountry_Name);
|
||||
ColumnDfn colProvinceName = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.RegionProvince_Name);
|
||||
ColumnDfn colUserRoleCount = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.UserRoleCount);
|
||||
ColumnDfn colSystemAdminUser = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.SystemAdminUser);
|
||||
ColumnDfn colLastLogin = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.LastLoginAt);
|
||||
ColumnDfn colStatus = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.Status);
|
||||
List<ColumnDfn> columns = new List<ColumnDfn>()
|
||||
{
|
||||
colId,
|
||||
colEmail,
|
||||
colTitle,
|
||||
colFirstName,
|
||||
colLastName,
|
||||
colUserRoleCount,
|
||||
colSystemAdminUser,
|
||||
colStatus
|
||||
colId, colEmail, colTitle, colFirstName, colLastName,
|
||||
colCountryName, colProvinceName,
|
||||
colUserRoleCount, colSystemAdminUser,
|
||||
colLastLogin, colStatus
|
||||
};
|
||||
|
||||
// Query items.
|
||||
@@ -150,8 +160,11 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
Title = values.GetString(colTitle.DataName),
|
||||
FirstName = values.GetString(colFirstName.DataName),
|
||||
LastName = values.GetString(colLastName.DataName),
|
||||
RegionNameCountry = values.GetString(colCountryName.DataName),
|
||||
RegionNameProvince = values.GetString(colProvinceName.DataName),
|
||||
UserRoleCount = StringUtil.ToInt(values.GetString(colUserRoleCount.DataName)),
|
||||
SystemAdmin = StringUtil.ToBool(values.GetString(colSystemAdminUser.DataName)),
|
||||
LastLoginAt = model.FormatDateTimeForDisplay(values.GetDateTime(colLastLogin.DataName)),
|
||||
StatusCode = values.GetString(colStatus.DataName),
|
||||
StatusDesc = SacsSystem.GetStatusDescForCode(values.GetString(colStatus.DataName))
|
||||
};
|
||||
@@ -193,22 +206,28 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Identify item.
|
||||
SysId userAccountId = model.UserAccountId.ToSysId();
|
||||
if (!SysId.IsValid(userAccountId))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"]));
|
||||
|
||||
// Retrieve item.
|
||||
SaxUserAccount user = AccountMgr.GetUserAccountById(userAccountId);
|
||||
if (user == null)
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve user for Id: '" + userAccountId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateUserResponseData(responseData.user, user, GetUserRoles(user.Id).GetUserRolesByStatus(SaStatus.Active));
|
||||
responseData.Success = true;
|
||||
// Identify item.
|
||||
SysId userAccountId = model.UserAccountId.ToSysId();
|
||||
if (!SysId.IsValid(userAccountId))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"]));
|
||||
|
||||
// Retrieve item.
|
||||
SaxUserAccount user = AccountMgr.GetUserAccountById(userAccountId);
|
||||
disposableItems.Add(user);
|
||||
if (user == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve user for Id: '" + userAccountId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateUserResponseData(model, responseData.user, user, GetUserRoles(user.Id).GetUserRolesByStatus(SaStatus.Active));
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
@@ -229,24 +248,30 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Identify user.
|
||||
if (StringUtil.IsEmpty(model.UserEmailAddress))
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
SaLogger.Warn(fn + " Attempt to get user details with blank email.");
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
// Retrieve user.
|
||||
SaxUserAccount user = AccountMgr.GetUserAccountByEmailAddress(model.UserEmailAddress);
|
||||
if (user == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve user for Email: " + model.UserEmailAddress);
|
||||
return Json(responseData);
|
||||
}
|
||||
// Identify user.
|
||||
if (StringUtil.IsEmpty(model.UserEmailAddress))
|
||||
{
|
||||
SaLogger.Warn(fn + " Attempt to get user details with blank email.");
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateUserResponseData(responseData.user, user, GetUserRoles(user.Id).GetUserRolesByStatus(SaStatus.Active));
|
||||
responseData.Success = true;
|
||||
// Retrieve user.
|
||||
SaxUserAccount user = AccountMgr.GetUserAccountByEmailAddress(model.UserEmailAddress);
|
||||
disposableItems.Add(user);
|
||||
if (user == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve user for Email: " + model.UserEmailAddress);
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateUserResponseData(model, responseData.user, user, GetUserRoles(user.Id).GetUserRolesByStatus(SaStatus.Active));
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
@@ -272,102 +297,113 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Retrieve existing item.
|
||||
SysId userAccountId = model.UserAccountId.ToSysId();
|
||||
SaxUserAccount user = AccountMgr.GetUserAccountById(userAccountId);
|
||||
if (user == null && SysId.IsValid(userAccountId))
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve user for Id: '" + model.UserAccountId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// User roles, including deleted in case of reassignment.
|
||||
List<SaxUserRole> userRoles = new List<SaxUserRole>();
|
||||
if (user != null) userRoles = GetUserRoles(user.Id, SaxUserRole.StatusCat.Any);
|
||||
if (model.UserRoleCodes != null)
|
||||
{
|
||||
List<String> userRoleCodes = model.GetUserRoleCodes();
|
||||
foreach (String userRoleCode in userRoleCodes)
|
||||
// Retrieve existing item.
|
||||
SysId userAccountId = model.UserAccountId.ToSysId();
|
||||
SaxUserAccount user = AccountMgr.GetUserAccountById(userAccountId);
|
||||
disposableItems.Add(user);
|
||||
if (user == null && SysId.IsValid(userAccountId))
|
||||
{
|
||||
// Role to activate.
|
||||
Sax.UserRole role = (Sax.UserRole)UserRoleCodes.GetTypeForCode(userRoleCode);
|
||||
SaxUserRole userRole = userRoles.GetUserRoleByRole(role);
|
||||
if (userRole == null)
|
||||
SaLogger.Warn(fn + " Failed to retrieve user for Id: '" + model.UserAccountId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// User roles, including deleted in case of reassignment.
|
||||
List<SaxUserRole> userRoles = new List<SaxUserRole>();
|
||||
if (user != null) userRoles = GetUserRoles(user.Id, SaxUserRole.StatusCat.Any);
|
||||
disposableItems.AddRange(userRoles);
|
||||
if (model.UserRoleCodes != null)
|
||||
{
|
||||
List<String> userRoleCodes = model.GetUserRoleCodes();
|
||||
foreach (String userRoleCode in userRoleCodes)
|
||||
{
|
||||
userRole = AccountMgr.CreateUserRole(user?.Id, role);
|
||||
userRoles.Add(userRole);
|
||||
// Role to activate.
|
||||
Sax.UserRole role = (Sax.UserRole)UserRoleCodes.GetTypeForCode(userRoleCode);
|
||||
SaxUserRole userRole = userRoles.GetUserRoleByRole(role);
|
||||
if (userRole == null)
|
||||
{
|
||||
userRole = AccountMgr.CreateUserRole(user?.Id, role);
|
||||
userRoles.Add(userRole);
|
||||
}
|
||||
userRole.Status = SaStatus.Active;
|
||||
}
|
||||
userRole.Status = SaStatus.Active;
|
||||
}
|
||||
// Roles to deactivate.
|
||||
foreach (SaxUserRole userRole in userRoles)
|
||||
{
|
||||
if (!userRoleCodes.Exists(item => item.EqualsCI(UserRoleCodes.GetCodeForType(userRole.UserRole))))
|
||||
userRole.Status = SaStatus.Inactive;
|
||||
}
|
||||
}
|
||||
|
||||
// Create new item if required.
|
||||
if (user == null)
|
||||
{
|
||||
user = AccountMgr.CreateUserAccount();
|
||||
if (model.UserEmailAddress != null)
|
||||
user.EmailAddress = model.UserEmailAddress;
|
||||
}
|
||||
|
||||
// Populate item properties.
|
||||
if (model.UserTitle != null)
|
||||
user.Title = model.UserTitle;
|
||||
if (model.UserFirstName != null)
|
||||
user.FirstName = model.UserFirstName;
|
||||
if (model.UserLastName != null)
|
||||
user.LastName = model.UserLastName;
|
||||
if (model.UserStatusCode != null)
|
||||
user.Status = model.UserStatus;
|
||||
|
||||
// Store item.
|
||||
if (!SysId.IsValid(user.Id))
|
||||
{
|
||||
if (!AccountMgr.InsertUserAccount(user, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to insert user: " + AccountMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.insert.failed"] + "\n\n" + AccountMgr.ErrorStateMessage));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!AccountMgr.UpdateUserAccount(user, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to update user [Id:" + SysId.ToString(user.Id) + "]: " + AccountMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.update.failed"] + "\n\n" + AccountMgr.ErrorStateMessage));
|
||||
}
|
||||
}
|
||||
|
||||
if (model.UserRoleCodes != null)
|
||||
{
|
||||
// Associated data - User Roles.
|
||||
foreach (SaxUserRole userRole in (userRoles))
|
||||
{
|
||||
// Store User Role.
|
||||
if (!SysId.IsValid(userRole.Id))
|
||||
// Roles to deactivate.
|
||||
foreach (SaxUserRole userRole in userRoles)
|
||||
{
|
||||
// Apply User Account Id if not yet done (for new user).
|
||||
if (!SysId.IsValid(userRole.UserAccountId))
|
||||
userRole.UserAccountId = user.Id;
|
||||
if (!AccountMgr.InsertUserRole(userRole, DbUpdateInfo))
|
||||
SaLogger.Warn(fn + " Failed to insert user role: " + AccountMgr.ErrorStateMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!AccountMgr.UpdateUserRole(userRole, DbUpdateInfo))
|
||||
SaLogger.Warn(fn + " Failed to update user role [Id:" + SysId.ToString(userRole.Id) + "]: " + AccountMgr.ErrorStateMessage);
|
||||
if (!userRoleCodes.Exists(item => item.EqualsCI(UserRoleCodes.GetCodeForType(userRole.UserRole))))
|
||||
userRole.Status = SaStatus.Inactive;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateUserResponseData(responseData.user, user, userRoles.GetUserRolesByStatus(SaStatus.Active));
|
||||
responseData.Success = true;
|
||||
// Create new item if required.
|
||||
if (user == null)
|
||||
{
|
||||
user = AccountMgr.CreateUserAccount();
|
||||
if (model.UserEmailAddress != null)
|
||||
user.EmailAddress = model.UserEmailAddress;
|
||||
}
|
||||
|
||||
// Populate item properties.
|
||||
if (model.UserTitle != null)
|
||||
user.Title = model.UserTitle;
|
||||
if (model.UserFirstName != null)
|
||||
user.FirstName = model.UserFirstName;
|
||||
if (model.UserLastName != null)
|
||||
user.LastName = model.UserLastName;
|
||||
if (model.UserRegionIdCountry != null)
|
||||
user.RegionIdCountry = model.UserRegionIdCountry.ToSysId();
|
||||
if (model.UserRegionIdProvince != null)
|
||||
user.RegionIdProvince = model.UserRegionIdProvince.ToSysId();
|
||||
if (model.UserStatusCode != null)
|
||||
user.Status = model.UserStatus;
|
||||
|
||||
// Store item.
|
||||
if (!SysId.IsValid(user.Id))
|
||||
{
|
||||
if (!AccountMgr.InsertUserAccount(user, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to insert user: " + AccountMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.insert.failed"] + "\n\n" + AccountMgr.ErrorStateMessage));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!AccountMgr.UpdateUserAccount(user, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to update user [Id:" + SysId.ToString(user.Id) + "]: " + AccountMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.update.failed"] + "\n\n" + AccountMgr.ErrorStateMessage));
|
||||
}
|
||||
}
|
||||
|
||||
if (model.UserRoleCodes != null)
|
||||
{
|
||||
// Associated data - User Roles.
|
||||
foreach (SaxUserRole userRole in (userRoles))
|
||||
{
|
||||
// Store User Role.
|
||||
if (!SysId.IsValid(userRole.Id))
|
||||
{
|
||||
// Apply User Account Id if not yet done (for new user).
|
||||
if (!SysId.IsValid(userRole.UserAccountId))
|
||||
userRole.UserAccountId = user.Id;
|
||||
if (!AccountMgr.InsertUserRole(userRole, DbUpdateInfo))
|
||||
SaLogger.Warn(fn + " Failed to insert user role: " + AccountMgr.ErrorStateMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!AccountMgr.UpdateUserRole(userRole, DbUpdateInfo))
|
||||
SaLogger.Warn(fn + " Failed to update user role [Id:" + SysId.ToString(userRole.Id) + "]: " + AccountMgr.ErrorStateMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateUserResponseData(model, responseData.user, user, userRoles.GetUserRolesByStatus(SaStatus.Active));
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
@@ -387,53 +423,60 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Retrieve user.
|
||||
SysId userAccountId = model.UserAccountId.ToSysId();
|
||||
SaxUserAccount userAccount = AccountMgr.GetUserAccountById(userAccountId);
|
||||
if (userAccount == null)
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve user for Id: '" + model.UserAccountId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// User roles.
|
||||
List<SaxUserRole> userRoles = GetUserRoles(userAccount.Id, SaxUserRole.StatusCat.Any);
|
||||
bool systemAdmin = userRoles.Exists(item => item.UserRole == Sax.UserRole.SystemAdmin);
|
||||
// Retrieve user.
|
||||
SysId userAccountId = model.UserAccountId.ToSysId();
|
||||
SaxUserAccount userAccount = AccountMgr.GetUserAccountById(userAccountId);
|
||||
disposableItems.Add(userAccount);
|
||||
if (userAccount == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve user for Id: '" + model.UserAccountId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// Email types to send.
|
||||
bool sendAcountActivationOnline = StringUtil.ToBool(model.UserEmailAcountActivationOnline);
|
||||
bool sendRequestPasswordOnline = StringUtil.ToBool(model.UserEmailRequestPasswordOnline);
|
||||
bool sendRequestPasswordAdmin = StringUtil.ToBool(model.UserEmailRequestPasswordAdmin);
|
||||
if (!sendAcountActivationOnline && !sendRequestPasswordOnline && !sendRequestPasswordAdmin)
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.validation.select.option"]));
|
||||
if (sendRequestPasswordAdmin && !systemAdmin)
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["user.msg.not.system.admin"]));
|
||||
// User roles.
|
||||
List<SaxUserRole> userRoles = GetUserRoles(userAccount.Id, SaxUserRole.StatusCat.Any);
|
||||
disposableItems.AddRange(userRoles);
|
||||
bool systemAdmin = userRoles.Exists(item => item.UserRole == Sax.UserRole.SystemAdmin);
|
||||
|
||||
// Send emails.
|
||||
int emailsSentCount = 0;
|
||||
if (sendAcountActivationOnline)
|
||||
{
|
||||
if (!OrganisationController.SendAccountActivatedEmail(this, userAccount))
|
||||
return Json(responseData.SetMessage(messageTitle, "Failed to send Online Accoutn Activation email."));
|
||||
emailsSentCount++;
|
||||
}
|
||||
if (sendRequestPasswordOnline)
|
||||
{
|
||||
if (!SecurityController.SendRequestPasswordEmail(this, userAccount, true))
|
||||
return Json(responseData.SetMessage(messageTitle, "Failed to send Online Request Password email."));
|
||||
emailsSentCount++;
|
||||
}
|
||||
if (sendRequestPasswordAdmin)
|
||||
{
|
||||
if (!SecurityController.SendRequestPasswordEmail(this, userAccount, false))
|
||||
return Json(responseData.SetMessage(messageTitle, "Failed to send Admin Request Password email."));
|
||||
emailsSentCount++;
|
||||
}
|
||||
// Email types to send.
|
||||
bool sendAcountActivationOnline = StringUtil.ToBool(model.UserEmailAcountActivationOnline);
|
||||
bool sendRequestPasswordOnline = StringUtil.ToBool(model.UserEmailRequestPasswordOnline);
|
||||
bool sendRequestPasswordAdmin = StringUtil.ToBool(model.UserEmailRequestPasswordAdmin);
|
||||
if (!sendAcountActivationOnline && !sendRequestPasswordOnline && !sendRequestPasswordAdmin)
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.validation.select.option"]));
|
||||
if (sendRequestPasswordAdmin && !systemAdmin)
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["user.msg.not.system.admin"]));
|
||||
|
||||
// Construct response.
|
||||
PopulateUserResponseData(responseData.user, userAccount, userRoles.GetUserRolesByStatus(SaStatus.Active));
|
||||
responseData.SetNotification(messageTitle, "Emails sent: " + emailsSentCount);
|
||||
responseData.Success = true;
|
||||
// Send emails.
|
||||
int emailsSentCount = 0;
|
||||
if (sendAcountActivationOnline)
|
||||
{
|
||||
if (!OrganisationController.SendAccountActivatedEmail(this, userAccount))
|
||||
return Json(responseData.SetMessage(messageTitle, "Failed to send Online Accoutn Activation email."));
|
||||
emailsSentCount++;
|
||||
}
|
||||
if (sendRequestPasswordOnline)
|
||||
{
|
||||
if (!SecurityController.SendRequestPasswordEmail(this, userAccount, true))
|
||||
return Json(responseData.SetMessage(messageTitle, "Failed to send Online Request Password email."));
|
||||
emailsSentCount++;
|
||||
}
|
||||
if (sendRequestPasswordAdmin)
|
||||
{
|
||||
if (!SecurityController.SendRequestPasswordEmail(this, userAccount, false))
|
||||
return Json(responseData.SetMessage(messageTitle, "Failed to send Admin Request Password email."));
|
||||
emailsSentCount++;
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateUserResponseData(model, responseData.user, userAccount, userRoles.GetUserRolesByStatus(SaStatus.Active));
|
||||
responseData.SetNotification(messageTitle, "Emails sent: " + emailsSentCount);
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Saxonite.Net.Core.Web.Admin.Models;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
{
|
||||
//=======================================================================
|
||||
partial class UsersOnlineController
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// User data.
|
||||
private class UserData_List : AjaxResponse_Data.ItemData_Base
|
||||
{
|
||||
public String EmailAddress { get; set; }
|
||||
public String DisplayName { get; set; }
|
||||
public String Title { get; set; }
|
||||
public String FirstName { get; set; }
|
||||
public String LastName { get; set; }
|
||||
public String LastLoginAt { get; set; }
|
||||
public String OnlineAt { get; set; }
|
||||
}
|
||||
private class UserData_Full : UserData_List
|
||||
{
|
||||
}
|
||||
private void PopulateUserResponseData(SaxModel_Admin model, UserData_List data, SaxUserAccount user, SaxUserOnline userOnline)
|
||||
{
|
||||
data.Id = SysId.ToString(user.Id);
|
||||
data.EmailAddress = user.EmailAddress;
|
||||
data.DisplayName = user.GetDisplayName();
|
||||
data.Title = user.Title;
|
||||
data.FirstName = user.FirstName;
|
||||
data.LastName = user.LastName;
|
||||
data.LastLoginAt = model.FormatDateTimeForDisplay(user.LastLoginAt);
|
||||
if (userOnline != null)
|
||||
data.OnlineAt = model.FormatDateTimeForDisplay(userOnline.OnlineAt);
|
||||
}
|
||||
private void PopulateUserResponseData(SaxModel_Admin model, UserData_Full data, SaxUserAccount user, SaxUserOnline userOnline)
|
||||
{
|
||||
PopulateUserResponseData(model, data as UserData_List, user, userOnline);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get User List ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_UserList : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_UserList(SaxModel_Admin model) : base(model) { }
|
||||
// User list.
|
||||
public List<UserData_List> Users { get; } = new List<UserData_List>();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("UsersOnline/Ajax/GetList")]
|
||||
[Route("UsersOnline/Ajax/GetUsers")]
|
||||
[Route("UsersOnline/Ajax/GetUserList")]
|
||||
public IActionResult Ajax_GetUsersOnlineList(Model_User model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_GetUsersOnlineList";
|
||||
String messageTitle = Localiser["label.users.online"];
|
||||
AjaxResponse_UserList responseData = new AjaxResponse_UserList(model);
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer) return Forbid();
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Item filter.
|
||||
SaxUserOnline.Params prmUserOnline = new SaxUserOnline.Params();
|
||||
prmUserOnline.UserFilterPartial = model.Filter.User;
|
||||
prmUserOnline.SportIdsIncluded.AddId(model.Filter.UserSportId.ToSysId());
|
||||
prmUserOnline.RegionIdsIncluded.AddId(model.Filter.UserRegionId.ToSysId());
|
||||
model.Paging.ItemTotal = (ulong)AccountMgr.GetUserOnlineCount(prmUserOnline);
|
||||
model.PopulatePagingTo(prmUserOnline.ResultsPaging);
|
||||
|
||||
// Item columns.
|
||||
ColumnDfn colUserAccountId = AccountMgr.GetUserOnlineColumnDfn(SaxUserOnline.Column.UserAccountId);
|
||||
ColumnDfn colEmail = AccountMgr.GetUserOnlineColumnDfn(SaxUserOnline.Column.EmailAddress);
|
||||
ColumnDfn colTitle = AccountMgr.GetUserOnlineColumnDfn(SaxUserOnline.Column.Title);
|
||||
ColumnDfn colFirstName = AccountMgr.GetUserOnlineColumnDfn(SaxUserOnline.Column.FirstName);
|
||||
ColumnDfn colLastName = AccountMgr.GetUserOnlineColumnDfn(SaxUserOnline.Column.LastName);
|
||||
ColumnDfn colLastLogin = AccountMgr.GetUserOnlineColumnDfn(SaxUserOnline.Column.LastLoginAt);
|
||||
ColumnDfn colOnlineAt = AccountMgr.GetUserOnlineColumnDfn(SaxUserOnline.Column.OnlineAt);
|
||||
List<ColumnDfn> columns = new List<ColumnDfn>()
|
||||
{
|
||||
colUserAccountId,
|
||||
colEmail, colTitle, colFirstName, colLastName,
|
||||
colLastLogin, colOnlineAt
|
||||
};
|
||||
|
||||
// Query items.
|
||||
using (DbResultSet resultSet = AccountMgr.ExecuteUserOnlineQuery(columns, prmUserOnline))
|
||||
{
|
||||
while (resultSet != null && resultSet.HasRows && resultSet.NextRecord())
|
||||
{
|
||||
NamedValue.Map values = resultSet.GetRecordValues();
|
||||
UserData_List userData = new UserData_List()
|
||||
{
|
||||
Id = values.GetString(colUserAccountId.DataName),
|
||||
EmailAddress = values.GetString(colEmail.DataName),
|
||||
Title = values.GetString(colTitle.DataName),
|
||||
FirstName = values.GetString(colFirstName.DataName),
|
||||
LastName = values.GetString(colLastName.DataName),
|
||||
LastLoginAt = model.FormatDateTimeForDisplay(values.GetDateTime(colLastLogin.DataName)),
|
||||
OnlineAt = model.FormatDateTimeForDisplay(values.GetDateTime(colOnlineAt.DataName)),
|
||||
};
|
||||
userData.DisplayName = SaxUserAccount.GetDisplayName(userData.Title, userData.FirstName, userData.LastName);
|
||||
responseData.Users.Add(userData);
|
||||
}
|
||||
}
|
||||
if (model.Paging.IsPaged)
|
||||
model.Paging.ItemCount = (ushort)responseData.Users.Count;
|
||||
|
||||
// Complete response.
|
||||
responseData.SetPaging(model);
|
||||
responseData.Success = true;
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get User ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_User : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_User(SaxModel_Admin model) : base(model) { }
|
||||
// User details.
|
||||
public UserData_Full user { get; } = new UserData_Full();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("UsersOnline/Ajax/GetItem")]
|
||||
[Route("UsersOnline/Ajax/GetUser")]
|
||||
public IActionResult Ajax_GetUser(Model_User model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_GetUser";
|
||||
String messageTitle = Localiser["user.caption.user"];
|
||||
AjaxResponse_User responseData = new AjaxResponse_User(model);
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer) return Forbid();
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Identify item.
|
||||
SysId userAccountId = model.UserAccountId.ToSysId();
|
||||
if (!SysId.IsValid(userAccountId))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"]));
|
||||
|
||||
// Retrieve item.
|
||||
SaxUserAccount user = AccountMgr.GetUserAccountById(userAccountId);
|
||||
disposableItems.Add(user);
|
||||
if (user == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve user for Id: '" + userAccountId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// User Online.
|
||||
SaxUserOnline userOnline = AccountMgr.GetUserOnlineByUserAccountId(user.Id);
|
||||
disposableItems.Add(userOnline);
|
||||
|
||||
// Construct response.
|
||||
PopulateUserResponseData(model, responseData.user, user, userOnline);
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Saxonite.Net.Core.Web.Admin.Models;
|
||||
using Saxonite.Net.Core.Web.Base.App;
|
||||
using Saxonite.Net.Core.Web.Base.Controllers;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
{
|
||||
//=======================================================================
|
||||
public partial class UsersOnlineController : SaxController_Admin
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public UsersOnlineController(SaxLocaliser localiser, ILogger<HomeController> logger) :
|
||||
base(localiser, logger)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
[HttpGet]
|
||||
public IActionResult Index(String sta)
|
||||
{
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return RedirectToAction("", "");
|
||||
|
||||
// Paging.
|
||||
Model_UsersOnline model = new Model_UsersOnline(Localiser);
|
||||
model.Paging.PageNo = 1;
|
||||
model.Paging.PageLength = 24;
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -67,6 +67,8 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
public String UserTitle { get; set; }
|
||||
public String UserFirstName { get; set; }
|
||||
public String UserLastName { get; set; }
|
||||
public String UserRegionIdCountry { get; set; }
|
||||
public String UserRegionIdProvince { get; set; }
|
||||
public String UserRoleCodeDelim = ",";
|
||||
public new List<String> UserRoleCodes { get; set; }
|
||||
public List<String> GetUserRoleCodes()
|
||||
@@ -92,63 +94,126 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
// User.
|
||||
public bool ValidateUserData(SaxController_Base.AjaxResponse_Data responseData)
|
||||
{
|
||||
// User email.
|
||||
if (UserEmailAddress != null)
|
||||
String fn = GetType().Name + ".ValidateUserData";
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
UserEmailAddress = UserEmailAddress.ToLowerInvariant();
|
||||
responseData.SetControlValue(nameof(UserEmailAddress), UserEmailAddress);
|
||||
if (StringUtil.IsEmpty(UserEmailAddress))
|
||||
responseData.SetControlError(nameof(UserEmailAddress), Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.GetLength(UserEmailAddress) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_EmailAddress))
|
||||
responseData.SetControlError(nameof(UserEmailAddress), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_EmailAddress)]);
|
||||
else if (!SacsDataValidationHelper.IsValidEmailAddress(UserEmailAddress))
|
||||
responseData.SetControlError(nameof(UserEmailAddress), Localiser["msg.validation.invalid.value"]);
|
||||
else
|
||||
|
||||
// User email.
|
||||
if (UserEmailAddress != null)
|
||||
{
|
||||
// Check for duplicate email address.
|
||||
SaxUserAccount.Params prmUserAccount = new SaxUserAccount.Params();
|
||||
SysId userAccountId = UserAccountId.ToSysId();
|
||||
if (SysId.IsValid(userAccountId))
|
||||
prmUserAccount.IdsExcluded.Add(userAccountId);
|
||||
prmUserAccount.EmailAddress = UserEmailAddress;
|
||||
prmUserAccount.StatusCat = SaxUserAccount.StatusCat.Any;
|
||||
if (AccountMgr.GetUserAccountCount(prmUserAccount) > 0)
|
||||
responseData.SetControlError(nameof(UserEmailAddress), Localiser["msg.validation.duplicate.value"]);
|
||||
UserEmailAddress = UserEmailAddress.ToLowerInvariant();
|
||||
responseData.SetControlValue(nameof(UserEmailAddress), UserEmailAddress);
|
||||
if (StringUtil.IsEmpty(UserEmailAddress))
|
||||
responseData.SetControlError(nameof(UserEmailAddress), Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.GetLength(UserEmailAddress) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_EmailAddress))
|
||||
responseData.SetControlError(nameof(UserEmailAddress), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_EmailAddress)]);
|
||||
else if (!SacsDataValidationHelper.IsValidEmailAddress(UserEmailAddress))
|
||||
responseData.SetControlError(nameof(UserEmailAddress), Localiser["msg.validation.invalid.value"]);
|
||||
else
|
||||
{
|
||||
// Check for duplicate email address.
|
||||
SaxUserAccount.Params prmUserAccount = new SaxUserAccount.Params();
|
||||
SysId userAccountId = UserAccountId.ToSysId();
|
||||
if (SysId.IsValid(userAccountId))
|
||||
prmUserAccount.IdsExcluded.Add(userAccountId);
|
||||
prmUserAccount.EmailAddress = UserEmailAddress;
|
||||
prmUserAccount.StatusCat = SaxUserAccount.StatusCat.Any;
|
||||
if (AccountMgr.GetUserAccountCount(prmUserAccount) > 0)
|
||||
responseData.SetControlError(nameof(UserEmailAddress), Localiser["msg.validation.duplicate.value"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// User title.
|
||||
if (UserTitle != null)
|
||||
{
|
||||
}
|
||||
// User title.
|
||||
if (UserTitle != null)
|
||||
{
|
||||
}
|
||||
|
||||
// User first name.
|
||||
if (UserFirstName != null)
|
||||
{
|
||||
responseData.SetControlValue(nameof(UserFirstName), UserFirstName);
|
||||
if (StringUtil.IsEmpty(UserFirstName))
|
||||
responseData.SetControlError(nameof(UserFirstName), Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.GetLength(UserFirstName) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_FirstName))
|
||||
responseData.SetControlError(nameof(UserFirstName), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_FirstName)]);
|
||||
}
|
||||
// User first name.
|
||||
if (UserFirstName != null)
|
||||
{
|
||||
responseData.SetControlValue(nameof(UserFirstName), UserFirstName);
|
||||
if (StringUtil.IsEmpty(UserFirstName))
|
||||
responseData.SetControlError(nameof(UserFirstName), Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.GetLength(UserFirstName) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_FirstName))
|
||||
responseData.SetControlError(nameof(UserFirstName), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_FirstName)]);
|
||||
}
|
||||
|
||||
// User last name.
|
||||
if (UserLastName != null)
|
||||
{
|
||||
responseData.SetControlValue(nameof(UserLastName), UserLastName);
|
||||
if (StringUtil.IsEmpty(UserLastName))
|
||||
responseData.SetControlError(nameof(UserLastName), Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.GetLength(UserLastName) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_LastName))
|
||||
responseData.SetControlError(nameof(UserLastName), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_LastName)]);
|
||||
}
|
||||
// User last name.
|
||||
if (UserLastName != null)
|
||||
{
|
||||
responseData.SetControlValue(nameof(UserLastName), UserLastName);
|
||||
if (StringUtil.IsEmpty(UserLastName))
|
||||
responseData.SetControlError(nameof(UserLastName), Localiser["msg.validation.mandatory.value"]);
|
||||
else if (StringUtil.GetLength(UserLastName) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_LastName))
|
||||
responseData.SetControlError(nameof(UserLastName), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_LastName)]);
|
||||
}
|
||||
|
||||
// Country region.
|
||||
SaxRegion regionCountry = null;
|
||||
if (UserRegionIdCountry != null)
|
||||
{
|
||||
if (!SysId.IsValid(UserRegionIdCountry.ToSysId()))
|
||||
responseData.SetControlError(nameof(UserRegionIdCountry), Localiser["msg.validation.mandatory.value"]);
|
||||
else
|
||||
{
|
||||
regionCountry = ReferenceMgr.GetRegionById(UserRegionIdCountry.ToSysId());
|
||||
disposableItems.Add(regionCountry);
|
||||
if (regionCountry != null)
|
||||
{
|
||||
if (regionCountry.RegionType != Sax.RegionType.Country)
|
||||
{
|
||||
SaLogger.Warn(fn + " Invalid region type. Expected: Country. Found: " + regionCountry.RegionType.ToString());
|
||||
responseData.SetControlError(nameof(UserRegionIdCountry), Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve region for Id: " + UserRegionIdCountry);
|
||||
responseData.SetControlError(nameof(UserRegionIdCountry), Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Province region.
|
||||
SaxRegion regionProvince = null;
|
||||
if (UserRegionIdProvince != null)
|
||||
{
|
||||
if (!UserRegionIdProvince.IsEmpty())
|
||||
{
|
||||
regionProvince = ReferenceMgr.GetRegionById(UserRegionIdProvince.ToSysId());
|
||||
disposableItems.Add(regionProvince);
|
||||
if (regionProvince != null)
|
||||
{
|
||||
if (regionProvince.RegionType != Sax.RegionType.Province)
|
||||
{
|
||||
SaLogger.Warn(fn + " Invalid region type. Expected: Province . Found: " + regionCountry.RegionType.ToString());
|
||||
responseData.SetControlError(nameof(UserRegionIdProvince), Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
else if (regionCountry != null && !regionProvince.RegionIdParent.Equals(regionCountry.Id))
|
||||
{
|
||||
SaLogger.Warn(fn + " Invalid province region parent. Expected: " + regionCountry.Id.ToString() + " . Found: " + regionCountry.RegionIdParent.ToString());
|
||||
responseData.SetControlError(nameof(UserRegionIdProvince), Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve region for Id: " + UserRegionIdProvince);
|
||||
responseData.SetControlError(nameof(UserRegionIdProvince), Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// User status.
|
||||
if (UserStatusCode != null)
|
||||
{
|
||||
if (StringUtil.IsEmpty(UserStatusCode))
|
||||
responseData.SetControlError(nameof(UserStatus), Localiser["msg.validation.mandatory.value"]);
|
||||
else if (!SaxUserAccount.ValidStatuses.Contains(UserStatus))
|
||||
responseData.SetControlError(nameof(UserStatus), Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
|
||||
// User status.
|
||||
if (UserStatusCode != null)
|
||||
{
|
||||
if (StringUtil.IsEmpty(UserStatusCode))
|
||||
responseData.SetControlError(nameof(UserStatus), Localiser["msg.validation.mandatory.value"]);
|
||||
else if (!SaxUserAccount.ValidStatuses.Contains(UserStatus))
|
||||
responseData.SetControlError(nameof(UserStatus), Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
|
||||
return !responseData.HasControlErrors();
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
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 Saxonite.Base.App;
|
||||
using Saxonite.Net.Core.Web.Base.App;
|
||||
using Saxonite.Net.Core.Web.Base.Controllers;
|
||||
using Saxonite.Net.Core.Web.Base.Models;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
{
|
||||
//=======================================================================
|
||||
public class Model_UsersOnline : SaxModel_Admin
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public Model_UsersOnline(SaxLocaliser localiser) :
|
||||
base(localiser)
|
||||
{
|
||||
AdditionalFiles_JS.Add("js/sax-usr-onl.js");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// User filter properties.
|
||||
public class FilterData
|
||||
{
|
||||
public String User { get; set; }
|
||||
public String UserSportId { get; set; }
|
||||
public String UserRegionId { get; set; }
|
||||
}
|
||||
public FilterData Filter { get; } = new FilterData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// User properties.
|
||||
public String UserId { get; set; }
|
||||
[EmailAddress]
|
||||
public String UserEmailAddress { get; set; }
|
||||
public String UserTitle { get; set; }
|
||||
public String UserFirstName { get; set; }
|
||||
public String UserLastName { get; set; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using Saxonite.Net.Core.Web.Admin.App;
|
||||
using Saxonite.Net.Core.Web.Base.App;
|
||||
using Saxonite.Net.Core.Web.Base.Models;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -26,6 +27,27 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
public SaxSessionData_Admin SessionData_Admin { get { return SessionData as SaxSessionData_Admin; } }
|
||||
public SysId UserAccountId { get { return SessionData_Admin?.User?.UserAccountId ?? null; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Reference data.
|
||||
//-------------------------------------------------------------------
|
||||
public String GetSportName(SysId sportId)
|
||||
{
|
||||
using (SaxSport sport = ReferenceMgr.GetSportById(sportId))
|
||||
{
|
||||
if (sport != null) return sport.Name;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String GetRegionName(SysId regionId)
|
||||
{
|
||||
using (SaxRegion region = ReferenceMgr.GetRegionById(regionId))
|
||||
{
|
||||
if (region != null) return region.Name;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
|
||||
@@ -330,6 +330,12 @@
|
||||
<data name="label.select" xml:space="preserve">
|
||||
<value>Select</value>
|
||||
</data>
|
||||
<data name="label.select.country" xml:space="preserve">
|
||||
<value>Select Country</value>
|
||||
</data>
|
||||
<data name="label.select.province" xml:space="preserve">
|
||||
<value>Select Province</value>
|
||||
</data>
|
||||
<data name="label.selected.count" xml:space="preserve">
|
||||
<value>{0} selected</value>
|
||||
</data>
|
||||
@@ -369,6 +375,9 @@
|
||||
<data name="label.user.roles" xml:space="preserve">
|
||||
<value>User roles</value>
|
||||
</data>
|
||||
<data name="label.users.online" xml:space="preserve">
|
||||
<value>Users online</value>
|
||||
</data>
|
||||
<data name="label.yes" xml:space="preserve">
|
||||
<value>Yes</value>
|
||||
</data>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<script type="text/javascript">
|
||||
sax.dlg.title.createOrganisation = '@Localiser.GetJavascriptText("organisation.caption.organisation.create")';
|
||||
sax.dlg.title.updateOrganisation = '@Localiser.GetJavascriptText("organisation.caption.organisation.update")';
|
||||
sax.dlg.title.selectRegion = '@Localiser.GetJavascriptText("region.caption.region.select")';
|
||||
sax.dlg.title.selectRegion = '@Localiser.GetJavascriptText("label.select.country")';
|
||||
sax.dlg.title.selectSport = '@Localiser.GetJavascriptText("sport.caption.sport.select")';
|
||||
</script>
|
||||
@using (@Html.BeginForm(FormMethod.Post, new { @id = "frmOrganisationId", @class = "sax-form" }))
|
||||
@@ -92,7 +92,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* Organisation region *@
|
||||
@* Organisation country *@
|
||||
<div class="sax-form-control OrganisationRegionIdCountry">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
@if (Model.ProhibitCache)
|
||||
{
|
||||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
|
||||
<meta http-equiv="Pragma" content="no-cache" />
|
||||
<meta http-equiv="Expires" content="0" />
|
||||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
|
||||
<meta http-equiv="Pragma" content="no-cache" />
|
||||
<meta http-equiv="Expires" content="0" />
|
||||
}
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<meta http-equiv="Content-Script-Type" content="application/javascript" />
|
||||
@@ -50,12 +50,12 @@
|
||||
<link rel="stylesheet" href="~/css/sax-form.css?@Model.HrefVersion" />
|
||||
@foreach (var cssFile in Model.AdditionalFiles_CSS)
|
||||
{
|
||||
<link rel="stylesheet" href="~/@cssFile?@Model.HrefVersion" />
|
||||
<link rel="stylesheet" href="~/@cssFile?@Model.HrefVersion" />
|
||||
}
|
||||
|
||||
@* Scripts *@
|
||||
<script>
|
||||
var sax = sax || { page: {}, mdl: {}, url: {}, links: {}, form: {}, data: {}, ajax: {}, msg: {}, lbl: {}, dlg: { title: {}, btn: {} }, $frm: {}, $dlg: {}, $pnl: {} };
|
||||
var sax = sax || { page: {}, mdl: {}, url: {}, links: {}, form: {}, data: {}, ajax: {}, msg: {}, lbl: {}, dlg: { title: {}, btn: {} }, $frm: {}, $dlg: {}, $pnl: {}, session: {}, kli: {} };
|
||||
sax.url.base = '@Model.RedirectLocation.Base';
|
||||
sax.url.home = '@Model.RedirectLocation.Home';
|
||||
sax.url.sessionExpired = '@Model.RedirectLocation.Home_SessionExpired';
|
||||
@@ -79,10 +79,10 @@
|
||||
sax.msg.dataRefreshing = '@Localiser.GetJavascriptText("msg.data.refreshing")';
|
||||
sax.msg.dataQuerying = '@Localiser.GetJavascriptText("msg.data.querying")';
|
||||
sax.msg.dataNoneFound = '@Localiser.GetJavascriptText("msg.data.noneFound")';
|
||||
sax.sessionCookieName = '@Model.SessionCookieName';
|
||||
sax.session.cookieName = '@Model.SessionCookieName';
|
||||
sax.awaitingLogin = @awaitingLogin;
|
||||
sax.keepLoggedIn = @keepLoggedIn;
|
||||
sax.keepLoggedInDelay = @(Sax.Config.Admin.Session.Cookie.KeepLoggedInTimeoutMillis);
|
||||
sax.kli.active = @keepLoggedIn;
|
||||
sax.kli.interval = @(Sax.Config.Admin.Session.Cookie.KeepLoggedInTimeoutMillis);
|
||||
sax.debugMode = @debug;
|
||||
</script>
|
||||
|
||||
@@ -109,52 +109,53 @@
|
||||
*@
|
||||
@if (Model.AwaitingLogin)
|
||||
{
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Policies" asp-action="Privacy">@Localiser["policies.caption.privacy"]</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Security" asp-action="">@Localiser["security.caption.signin"]</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Policies" asp-action="Privacy">@Localiser["policies.caption.privacy"]</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Security" asp-action="">@Localiser["security.caption.signin"]</a>
|
||||
</li>
|
||||
}
|
||||
else
|
||||
{
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link text-dark dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
@Localiser["label.reference"]
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('Sport');">@Localiser["sport.caption.sports"]</div>
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('Region');">@Localiser["region.caption.regions"]</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link text-dark dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
@Localiser["label.accounts"]
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('User');">@Localiser["user.caption.users"]</div>
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('Organisation');">@Localiser["organisation.caption.organisations"]</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link text-dark dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
@Localiser["label.system"]
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('System/Database');">@Localiser["label.database"]</div>
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('System/Logs');">@Localiser["label.logs"]</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link text-dark dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
@Localiser["label.security"]
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.navigateTo('Security/ChangePassword');">@Localiser["security.caption.change.password"]</div>
|
||||
<div class="dropdown-divider"></div>
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.onSignOut();">@Localiser["security.caption.signout"]</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link text-dark dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
@Localiser["label.reference"]
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('Sport');">@Localiser["sport.caption.sports"]</div>
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('Region');">@Localiser["region.caption.regions"]</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link text-dark dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
@Localiser["label.accounts"]
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('UsersOnline');">@Localiser["label.users.online"]</div>
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('User');">@Localiser["user.caption.users"]</div>
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('Organisation');">@Localiser["organisation.caption.organisations"]</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link text-dark dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
@Localiser["label.system"]
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('System/Database');">@Localiser["label.database"]</div>
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('System/Logs');">@Localiser["label.logs"]</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link text-dark dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
@Localiser["label.security"]
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.navigateTo('Security/ChangePassword');">@Localiser["security.caption.change.password"]</div>
|
||||
<div class="dropdown-divider"></div>
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.onSignOut();">@Localiser["security.caption.signout"]</div>
|
||||
</div>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
@@ -164,9 +165,9 @@
|
||||
@* Page caption *@
|
||||
@if (!StringUtil.IsEmpty(Model.PageCaption))
|
||||
{
|
||||
<div class="container">
|
||||
<div class="sax-page-caption">@(Model.PageCaption)</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
<div class="sax-page-caption">@(Model.PageCaption)</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
</header>
|
||||
@@ -220,11 +221,11 @@
|
||||
<script src="~/js/sax-main.js?@Model.HrefVersion"></script>
|
||||
@foreach (var jsFile in Model.AdditionalFiles_JS)
|
||||
{
|
||||
<script src="~/@jsFile?@Model.HrefVersion"></script>
|
||||
<script src="~/@jsFile?@Model.HrefVersion"></script>
|
||||
}
|
||||
@if (Model.IncludeGoogleAnalytics)
|
||||
{
|
||||
<partial name="~/Views/Shared/_GoogleAnalytics.cshtml" />
|
||||
<partial name="~/Views/Shared/_GoogleAnalytics.cshtml" />
|
||||
}
|
||||
@RenderSection("Scripts", required: false)
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@* Organisation Status *@
|
||||
@* User Status *@
|
||||
<div class="row pb4">
|
||||
<div class="col-sm-5 sax-label text-left text-sm-right">@Localiser["label.status"]</div>
|
||||
<div class="col-sm-7">
|
||||
@@ -134,12 +134,12 @@
|
||||
<div class="sax-content">
|
||||
<div class="row">
|
||||
<div class="col-sm-4"><span class="UserDisplayName"></span></div>
|
||||
<div class="col-sm-4"><div>Roles: <span class="UserRoleCount"></span></div></div>
|
||||
<div class="col-sm-4 right"><div class="StatusDesc"></div></div>
|
||||
<div class="col-sm-4"><div class="UserLastLogin">Last login: <span class="UserLastLoginAt"></span></div></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-4"></div>
|
||||
<div class="col-sm-4"><div class="UserRoles">Roles: <span class="UserRoleCount"></span></div></div>
|
||||
<div class="col-sm-4"><div class=""></div></div>
|
||||
<div class="col-sm-4 right"><div class="StatusDesc"></div></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
<script type="text/javascript">
|
||||
sax.dlg.title.createUser = '@Localiser.GetJavascriptText("user.caption.user.create")';
|
||||
sax.dlg.title.updateUser = '@Localiser.GetJavascriptText("user.caption.user.update")';
|
||||
sax.dlg.title.selectRegionCountry = '@Localiser.GetJavascriptText("label.select.country")';
|
||||
sax.dlg.title.selectRegionProvince = '@Localiser.GetJavascriptText("label.select.province")';
|
||||
sax.dlg.title.selectUserRoles = '@Localiser.GetJavascriptText("user.caption.select.user.roles")';
|
||||
sax.dlg.title.selectUserEmails = '@Localiser.GetJavascriptText("user.caption.select.user.emails")';
|
||||
sax.data.userRoleCodeDelim = '@Model.UserRoleCodeDelim';
|
||||
@@ -25,7 +27,7 @@
|
||||
@* User email *@
|
||||
<div class="sax-form-control UserEmailAddress">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<div class="col-sm-3">
|
||||
<div class="sax-label">
|
||||
<label for="ifUserEmailAddress"><span>@Localiser["label.email.address"]</span> <span class="required">*</span></label>
|
||||
</div>
|
||||
@@ -39,61 +41,103 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
/* Title */
|
||||
<div class="sax-form-control UserTitle">
|
||||
<div class="row">
|
||||
@* User Name *@
|
||||
<div class="row">
|
||||
|
||||
<div class="col-sm-3">
|
||||
<div class="sax-label d-none d-sm-block">
|
||||
<label for="ifAccountEmailAddress"><span>@Localiser["label.name"]</span></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm row">
|
||||
|
||||
<div class="col-sm-4">
|
||||
@* Title *@
|
||||
<div class="sax-form-control UserTitle pr8">
|
||||
<div class="sax-label">
|
||||
<label for="cbUserTitle"><span><span class="required"></span> @Localiser["label.title"]</span></label>
|
||||
</div>
|
||||
<div class="sax-control">
|
||||
@Html.DropDownListFor(model => model.UserTitle, Model.TitlesForSelect, Localiser["label.not.specified"], new { @id = "cbUserTitle", @class = "UserTitle sax-select" })
|
||||
</div>
|
||||
<div class="sax-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-4">
|
||||
@* User first name *@
|
||||
<div class="sax-form-control UserFirstName pr8">
|
||||
<div class="sax-label">
|
||||
<label for="ifUserFirstName"><span>@Localiser["label.first.name"]</span> <span class="required">*</span></label>
|
||||
</div>
|
||||
<div class="sax-control">
|
||||
@Html.TextBoxFor(model => model.UserFirstName, new { @id = "ifUserFirstName", @class = "UserFirstName sax-input", @maxlength = @Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_FirstName) })
|
||||
</div>
|
||||
<div class="sax-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-4">
|
||||
@* User last name *@
|
||||
<div class="sax-form-control UserLastName">
|
||||
<div class="sax-label">
|
||||
<label for="ifUserLastName"><span>@Localiser["label.last.name"]</span> <span class="required">*</span></label>
|
||||
</div>
|
||||
<div class="sax-control">
|
||||
@Html.TextBoxFor(model => model.UserLastName, new { @id = "ifUserLastName", @class = "UserLastName sax-input", @maxlength = @Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_LastName) })
|
||||
</div>
|
||||
<div class="sax-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* User country *@
|
||||
<div class="sax-form-control UserRegionIdCountry">
|
||||
<div class="row">
|
||||
<div class="col-sm-3">
|
||||
<div class="sax-label">
|
||||
<label for="cbUserTitle"><span><span class="required"></span> @Localiser["label.title"]</span></label>
|
||||
<label for="ifUserRegionCaptionCountry"><span>@Localiser["label.country"]</span> <span class="required">*</span></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<div class="sax-control">
|
||||
@Html.DropDownListFor(model => model.UserTitle, Model.TitlesForSelect, Localiser["label.not.specified"], new { @id = "cbUserTitle", @class = "UserTitle sax-select" })
|
||||
<div class="sax-control row">
|
||||
@Html.HiddenFor(model => model.UserRegionIdCountry, new { @id = "ifUserRegionIdCountry", @class = "UserRegionIdCountry" })
|
||||
<div class="col"><input type="text" id="ifUserRegionCaptionCountry" class="UserRegionCaptionCountry sax-input" readonly="readonly" ondblclick="sax.selectRegionCountry()" /> </div>
|
||||
<div class="fixed"><button id="pbSelectRegion" class="sax-button" style="min-width:auto;margin-left:4px;padding:4px 6px" onclick="sax.selectRegionCountry()">@Localiser["label.select"]</button></div>
|
||||
</div>
|
||||
<div class="sax-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* User first name *@
|
||||
<div class="sax-form-control UserFirstName">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<div class="sax-label">
|
||||
<label for="ifUserFirstName"><span>@Localiser["label.first.name"]</span> <span class="required">*</span></label>
|
||||
@* User province *@
|
||||
@*
|
||||
<div class="sax-form-control UserRegionIdProvince">
|
||||
<div class="row">
|
||||
<div class="col-sm-3">
|
||||
<div class="sax-label">
|
||||
<label for="ifUserRegionCaptionProvince"><span>@Localiser["label.province"]</span></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<div class="sax-control">
|
||||
@Html.TextBoxFor(model => model.UserFirstName, new { @id = "ifUserFirstName", @class = "UserFirstName sax-input", @maxlength = @Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_FirstName) })
|
||||
<div class="col-sm">
|
||||
<div class="sax-control row">
|
||||
@Html.HiddenFor(model => model.UserRegionIdProvince, new { @id = "ifUserRegionIdProvince", @class = "UserRegionIdProvince" })
|
||||
<div class="col"><input type="text" id="ifUserRegionCaptionProvince" class="UserRegionCaptionProvince sax-input" readonly="readonly" ondblclick="sax.selectRegionProvince()" /> </div>
|
||||
<div class="fixed"><button id="pbSelectRegion" class="sax-button" style="min-width:auto;margin-left:4px;padding:4px 6px" onclick="sax.selectRegionProvince()">@Localiser["label.select"]</button></div>
|
||||
</div>
|
||||
<div class="sax-message"></div>
|
||||
</div>
|
||||
<div class="sax-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* User last name *@
|
||||
<div class="sax-form-control UserLastName">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<div class="sax-label">
|
||||
<label for="ifUserLastName"><span>@Localiser["label.last.name"]</span> <span class="required">*</span></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<div class="sax-control">
|
||||
@Html.TextBoxFor(model => model.UserLastName, new { @id = "ifUserLastName", @class = "UserLastName sax-input", @maxlength = @Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_LastName) })
|
||||
</div>
|
||||
<div class="sax-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
*@
|
||||
|
||||
@* User roles *@
|
||||
<div class="sax-form-control UserRoles">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<div class="col-sm-3">
|
||||
<div class="sax-label">
|
||||
<label for="lbUserRoles"><span>@Localiser["label.user.roles"]</span></label>
|
||||
</div>
|
||||
@@ -112,7 +156,7 @@
|
||||
@* User status *@
|
||||
<div class="sax-form-control UserStatus">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<div class="col-sm-3">
|
||||
<div class="sax-label">
|
||||
<label for="cbUserStatus"><span>@Localiser["label.status"]</span> <span class="required">*</span></label>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
@model Model_UsersOnline
|
||||
@inject SaxLocaliser Localiser
|
||||
@{
|
||||
/* Users Online - Index */
|
||||
ViewData["Title"] = "Users Online";
|
||||
}
|
||||
|
||||
<div class="sax-panel Users">
|
||||
|
||||
<script type="text/javascript">
|
||||
sax.lbl.refresh = '@(Localiser.GetJavascriptText("label.refresh"))';
|
||||
sax.lbl.edit = '@(Localiser.GetJavascriptText("label.edit"))';
|
||||
</script>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-5 row">
|
||||
|
||||
<div class="col">
|
||||
|
||||
@* Filter Panel *@
|
||||
@using (@Html.BeginForm(FormMethod.Post, new { @id = "frmUserFilter", @class = "sax-form", @onSubmit = "return false;" }))
|
||||
{
|
||||
|
||||
<div class="sax-panel-filter">
|
||||
@* Header - Page caption, paging controls, actions. *@
|
||||
<div class="sax-header row">
|
||||
<div class="col"><div class="sax-caption">@Localiser["label.users.online"]</div></div>
|
||||
<div class="fixed row">
|
||||
<div class="col">
|
||||
<partial name="~/Views/Common/ResultsPaging.cshtml" />
|
||||
</div>
|
||||
<div class="fixed">
|
||||
@* Burger menu *@
|
||||
<ul class="nav navbar-nav navbar-dark navbar-right sax-burger">
|
||||
<li class="dropdown-toggle caret-off">
|
||||
<a href="#" class="dropdown" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="navbar-toggler-icon"></span></a>
|
||||
<ul class="dropdown-menu dropdown-menu-right sax-dropdown-menu">@* Menu items will be inserted here. *@</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sax-content">
|
||||
@* User filter - email, name etc. *@
|
||||
<div class="row pb4">
|
||||
<div class="col-sm-5 sax-label text-left text-sm-right">@Localiser["user.caption.user"]</div>
|
||||
<div class="col-sm-7">@Html.TextBoxFor(model => model.Filter.User, new { @id = "ifFilterUser", @class = "FilterUser", @maxlength = "32" })</div>
|
||||
</div>
|
||||
@* User sport *@
|
||||
<div class="row pb4">
|
||||
<div class="col-sm-5 sax-label text-left text-sm-right">@Localiser["label.sport"]</div>
|
||||
<div class="col-sm-7">
|
||||
<div class="row">
|
||||
@Html.HiddenFor(model => model.Filter.UserSportId, new { @id = "", @class = "FilterUserSportId" })
|
||||
<div class="col"><input type="text" class="FilterUserSportCaption sax-input" readonly="readonly" ondblclick="sax.selectFilterSport()" /> </div>
|
||||
<div class="fixed row">
|
||||
<div class="sax-action" onclick="sax.selectFilterSport();"><img src="~/img/action/search24.png" alt="@(Localiser["label.search"])" title="@(Localiser["label.search"])" /></div>
|
||||
<div class="sax-action" onclick="sax.clearFilterSport();"><img src="~/img/action/delete24.png" alt="@(Localiser["label.clear"])" title="@(Localiser["label.clear"])" /></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@* User region *@
|
||||
<div class="row pb4">
|
||||
<div class="col-sm-5 sax-label text-left text-sm-right">@Localiser["label.region"]</div>
|
||||
<div class="col-sm-7">
|
||||
<div class="row">
|
||||
@Html.HiddenFor(model => model.Filter.UserRegionId, new { @id = "", @class = "FilterUserRegionId" })
|
||||
<div class="col"><input type="text" class="FilterUserRegionCaption sax-input" readonly="readonly" ondblclick="sax.selectFilterRegion()" /> </div>
|
||||
<div class="fixed row">
|
||||
<div class="sax-action" onclick="sax.selectFilterRegion();"><img src="~/img/action/search24.png" alt="@(Localiser["label.search"])" title="@(Localiser["label.search"])" /></div>
|
||||
<div class="sax-action" onclick="sax.clearFilterRegion();"><img src="~/img/action/delete24.png" alt="@(Localiser["label.clear"])" title="@(Localiser["label.clear"])" /></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* Filter element templates *@
|
||||
<div class="sax-panel-item-template">
|
||||
@* Burger dropdown item template - ul is ignored *@
|
||||
<ul class="sax-dropdown-menu UserFilter">
|
||||
<li class="sax-dropdown-item sax-action"><div class="sax-label">XXX</div></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
}
|
||||
|
||||
</div>
|
||||
|
||||
@* Separate filter from results when alondside each other. *@
|
||||
<div class="fixed"><div class="d-none d-md-block" style="width:8px;"></div></div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-md">
|
||||
|
||||
@* Results Panel *@
|
||||
<div class="sax-panel-results">
|
||||
<div class="sax-panel-messages"></div>
|
||||
<div class="sax-panel-item-list"></div>
|
||||
|
||||
@* Element templates *@
|
||||
<div class="sax-panel-item-template">
|
||||
|
||||
@* User item template *@
|
||||
<div class="sax-panel-item User">
|
||||
<div class="sax-header row">
|
||||
<div class="col">
|
||||
@* User email *@
|
||||
<div class="sax-caption"><div class="sax-action sax-item-update UserEmailAddress"></div></div>
|
||||
</div>
|
||||
<div class="fixed sax-actions">
|
||||
@* Burger menu *@
|
||||
<ul class="nav navbar-nav navbar-light navbar-right sax-burger">
|
||||
<li class="dropdown-toggle caret-off">
|
||||
<a href="#" class="dropdown" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="navbar-toggler-icon"></span></a>
|
||||
<ul class="dropdown-menu dropdown-menu-right sax-dropdown-menu">@* Menu items will be inserted here. *@</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sax-content">
|
||||
<div class="row">
|
||||
<div class="col-sm-4"><span class="UserDisplayName"></span></div>
|
||||
<div class="col-sm-4"><div class="UserLastLogin">Login: <span class="UserLastLoginAt"></span></div></div>
|
||||
<div class="col-sm-4"><div class="UserLastLogin">Online: <span class="UserLastOnlineAt"></span></div></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* Burger dropdown item template - ul is ignored *@
|
||||
<ul class="sax-dropdown-menu User">
|
||||
<li class="sax-dropdown-item sax-action"><div class="sax-label">XXX</div></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<partial name="~/Views/Common/SelectItem.cshtml" />
|
||||
@@ -21,6 +21,10 @@
|
||||
{
|
||||
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||
}
|
||||
sax.getTime = function ()
|
||||
{
|
||||
return (new Date()).getTime();
|
||||
}
|
||||
sax.zeroPad = function (num, count)
|
||||
{
|
||||
var val = num + '';
|
||||
@@ -353,37 +357,35 @@
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Session.
|
||||
sax.configureKeepLoggedIn = function ()
|
||||
sax.configureKeepLoggedIn = function (single)
|
||||
{
|
||||
sax.debug('KeepLoggedIn Configuring');
|
||||
setTimeout(sax.doKeepLoggedIn, Math.max(30000, sax.keepLoggedInDelay || 300000));
|
||||
let kli = sax.kli;
|
||||
if (!kli.timeout) kli.timeout = setTimeout(function () { sax.doKeepLoggedIn(single); }, Math.max(30000, kli.interval || 300000));
|
||||
}
|
||||
sax.doKeepLoggedIn = function ()
|
||||
sax.doKeepLoggedIn = function (single)
|
||||
{
|
||||
//sax.debug('KeepLoggedIn Calling');
|
||||
sax.debug('KeepLoggedIn Calling');
|
||||
let kli = sax.kli;
|
||||
delete kli.timeout;
|
||||
var onKeepLoggedIn = function (response)
|
||||
{
|
||||
sax.debug('KeepLoggedIn Responded', response);
|
||||
sax.configureKeepLoggedIn();
|
||||
kli.lastAt = sax.getTime();
|
||||
if (!single) sax.configureKeepLoggedIn();
|
||||
}
|
||||
sax.doAjaxRequest({ url: sax.url.base + 'Security/Ajax/KeepLoggedIn', formId: 'frmNavigate', noWaitIcon: true, callbackFn: onKeepLoggedIn }, 1000)
|
||||
}
|
||||
sax.configureSessionRefresh = function ()
|
||||
{
|
||||
//sax.debug('SessionRefresh Configuring');
|
||||
sax.debug('SessionRefresh Configuring');
|
||||
$(document).on('mousedown mousemove touchstart scroll keydown', sax.triggeRefreshSession);
|
||||
}
|
||||
sax.triggeRefreshSession = function ()
|
||||
{
|
||||
//sax.session = sax.session || { refresh: {} };
|
||||
let ssr = sax.session.refresh;
|
||||
win.clearTimeout(ssr.timeout);
|
||||
ssr.timeout = setTimeout(function () { sax.refreshSession(); }, 150000);
|
||||
}
|
||||
sax.refreshSession = function ()
|
||||
{
|
||||
//sax.debug('sax.refreshSession');
|
||||
sax.doKeepLoggedIn();
|
||||
if (sax.kli.timeout) return;
|
||||
sax.debug('SessionRefresh Triggering');
|
||||
sax.configureKeepLoggedIn(1);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
@@ -499,7 +501,7 @@
|
||||
$(function ()
|
||||
{
|
||||
$('.sax-button-cta,.sax-button-action,.sax-action-link,.sax-social-icon.sax-action').prop('tabindex', 0);
|
||||
if (sax.keepLoggedIn)
|
||||
if (sax.kli.active)
|
||||
sax.configureKeepLoggedIn();
|
||||
else if (!sax.awaitingLogin)
|
||||
sax.configureSessionRefresh();
|
||||
|
||||
@@ -61,7 +61,12 @@
|
||||
$('.UserTitle', $item).text(item.title);
|
||||
$('.UserFirstName', $item).text(item.firstName);
|
||||
$('.UserLastName', $item).text(item.lastName);
|
||||
$('.UserRegionNameCountry', $item).text(item.regionNameCountry);
|
||||
$('.UserRegionNameProvince', $item).text(item.regionNameProvince);
|
||||
$('.UserRoleCount', $item).text(item.userRoleCount);
|
||||
$('.UserRoles', $item).toggle(!!item.userRoleCount);
|
||||
$('.UserLastLoginAt', $item).text(item.lastLoginAt);
|
||||
$('.UserLastLogin', $item).toggle(!!item.lastLoginAt);
|
||||
$('.StatusDesc', $item).text(item.statusDesc).addClass('sax-status-' + item.statusCode.toLowerCase());
|
||||
$('.sax-caption .sax-action').toggleClass('sax-action', !item.deleted);
|
||||
let $mnu = $('ul.sax-dropdown-menu', $item);
|
||||
@@ -104,6 +109,7 @@
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Sports.
|
||||
sax.selectFilterSport = function ()
|
||||
{
|
||||
if (!sax.data.sports)
|
||||
@@ -111,8 +117,10 @@
|
||||
let handleFilterSportsResponse = function (response)
|
||||
{
|
||||
if (response && response.success && response.sports)
|
||||
{
|
||||
sax.data.sports = response.sports;
|
||||
sax.showSelectFilterSport();
|
||||
sax.showSelectFilterSport();
|
||||
}
|
||||
}
|
||||
sax.ajax.filterSports = sax.ajax.filterSports || { url: sax.url.base + 'Sport/Ajax/GetList', formId: 'frmNavigate', callbackFn: handleFilterSportsResponse };
|
||||
sax.doAjaxRequest(sax.ajax.filterSports, 50);
|
||||
@@ -125,33 +133,41 @@
|
||||
}
|
||||
sax.onFilterSportSelected = function (spt)
|
||||
{
|
||||
//sax.debug('onFilterSportSelected', sax.$frm.filter)
|
||||
let $frm = sax.$frm.filter;
|
||||
$('.FilterUserSportId', $frm).val(spt.id);
|
||||
$('.FilterUserSportCaption', $frm).val(spt.name);
|
||||
//sax.debug('onFilterSportSelected', $frm.filter)
|
||||
let $frmFlt = $frm.filter;
|
||||
$('.FilterUserSportId', $frmFlt).val(spt.id);
|
||||
$('.FilterUserSportCaption', $frmFlt).val(spt.name);
|
||||
sax.refreshResults();
|
||||
}
|
||||
sax.clearFilterSport = function ()
|
||||
{
|
||||
$('.FilterUserSportId,.FilterUserSportCaption', sax.$frm.filter).val('');
|
||||
$('.FilterUserSportId,.FilterUserSportCaption', $frm.filter).val('');
|
||||
sax.refreshResults();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.selectFilterRegion = function ()
|
||||
// Regions.
|
||||
sax.populateRegions = function (fnCallback)
|
||||
{
|
||||
if (!sax.data.regions)
|
||||
{
|
||||
let handleFilterRegionsResponse = function (response)
|
||||
let handleRegionsResponse = function (response)
|
||||
{
|
||||
if (response && response.success && response.regions)
|
||||
{
|
||||
sax.data.regions = response.regions;
|
||||
sax.showSelectFilterRegion();
|
||||
if (fnCallback) fnCallback();
|
||||
}
|
||||
}
|
||||
sax.ajax.regions = sax.ajax.regions || { url: sax.url.base + 'Region/Ajax/GetList', formId: 'frmNavigate', callbackFn: handleFilterRegionsResponse };
|
||||
sax.ajax.regions = sax.ajax.regions || { url: sax.url.base + 'Region/Ajax/GetList', formId: 'frmNavigate', callbackFn: handleRegionsResponse };
|
||||
sax.doAjaxRequest(sax.ajax.regions, 50);
|
||||
}
|
||||
else sax.showSelectFilterRegion();
|
||||
else if (fnCallback) fnCallback();
|
||||
}
|
||||
// Filter region.
|
||||
sax.selectFilterRegion = function ()
|
||||
{
|
||||
sax.populateRegions(sax.showSelectFilterRegion);
|
||||
}
|
||||
sax.showSelectFilterRegion = function ()
|
||||
{
|
||||
@@ -160,14 +176,58 @@
|
||||
sax.onFilterRegionSelected = function (rgn)
|
||||
{
|
||||
//sax.debug('onFilterRegionSelected', rgn);
|
||||
let $frm = sax.$frm.filter;
|
||||
$('.FilterUserRegionId', $frm).val(rgn.id);
|
||||
$('.FilterUserRegionCaption', $frm).val(rgn.name);
|
||||
let $frmFlt = $frm.filter;
|
||||
$('.FilterUserRegionId', $frmFlt).val(rgn.id);
|
||||
$('.FilterUserRegionCaption', $frmFlt).val(rgn.name);
|
||||
sax.refreshResults();
|
||||
}
|
||||
sax.clearFilterRegion = function ()
|
||||
{
|
||||
$('.FilterUserRegionId,.FilterUserRegionCaption', sax.$frm.filter).val('');
|
||||
$('.FilterUserRegionId,.FilterUserRegionCaption', $frm.filter).val('');
|
||||
sax.refreshResults();
|
||||
}
|
||||
// Country region.
|
||||
sax.selectRegionCountry = function ()
|
||||
{
|
||||
sax.populateRegions(sax.showSelectRegionCountry);
|
||||
}
|
||||
sax.showSelectRegionCountry = function ()
|
||||
{
|
||||
sax.data.selectItem.fn.selectItem({ caption: sax.dlg.title.selectRegionCountry, items: sax.data.regions, fnCallback: sax.onRegionCountrySelected });
|
||||
}
|
||||
sax.onRegionCountrySelected = function (rgn)
|
||||
{
|
||||
//sax.debug('onRegionCountrySelected', rgn);
|
||||
let $frmUsr = $frm.user;
|
||||
$('.UserRegionIdCountry', $frmUsr).val(rgn.id);
|
||||
$('.UserRegionCaptionCountry', $frmUsr).val(rgn.name);
|
||||
sax.refreshResults();
|
||||
}
|
||||
sax.clearRegionCountry = function ()
|
||||
{
|
||||
$('.UserRegionIdCountry,.UserRegionCaptionCountry', $frm.user).val('');
|
||||
sax.refreshResults();
|
||||
}
|
||||
// Province region.
|
||||
sax.selectRegionProvince = function ()
|
||||
{
|
||||
sax.populateRegions(sax.showSelectRegionProvince);
|
||||
}
|
||||
sax.showSelectRegionProvince = function ()
|
||||
{
|
||||
sax.data.selectItem.fn.selectItem({ caption: sax.dlg.title.selectRegionProvince, items: sax.data.regions, fnCallback: sax.onRegionProvinceSelected });
|
||||
}
|
||||
sax.onRegionProvinceSelected = function (rgn)
|
||||
{
|
||||
//sax.debug('onRegionProvinceSelected', rgn);
|
||||
let $frmUsr = $frm.user;
|
||||
$('.UserRegionIdProvince', $frmUsr).val(rgn.id);
|
||||
$('.UserRegionCaptionProvince', $frmUsr).val(rgn.name);
|
||||
sax.refreshResults();
|
||||
}
|
||||
sax.clearRegionProvince = function ()
|
||||
{
|
||||
$('.UserRegionIdProvince,.UserRegionCaptionProvince', $frm.user).val('');
|
||||
sax.refreshResults();
|
||||
}
|
||||
|
||||
@@ -203,14 +263,18 @@
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.createItem = function ()
|
||||
{
|
||||
sax.clearUserData();
|
||||
$dlg.user.dialog('option', 'title', sax.dlg.title.createUser);
|
||||
sax.openDialog($dlg.user, 600, 480);
|
||||
}
|
||||
sax.clearUserData = function ()
|
||||
{
|
||||
let frm = $frm.user;
|
||||
$('.UserAccountId,.UserRoleCodes,input[type="text"],textarea,select', frm).val('');
|
||||
$('.UserAccountId,.UserRegionIdCountry,.UserRegionIdProvince,.UserRoleCodes,input[type="text"],textarea,select', frm).val('');
|
||||
$('.UserStatus', frm).val(sax.data.defaultStatusCode);
|
||||
sax.clearControlErrors();
|
||||
sax.userAccount = { userRoleCodes: [] };
|
||||
$dlg.user.dialog('option', 'title', sax.dlg.title.createUser);
|
||||
sax.openDialog($dlg.user, 600, 480);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
@@ -223,16 +287,19 @@
|
||||
sax.onUpdateItem = function (response)
|
||||
{
|
||||
//sax.debug('onUpdateItem', response);
|
||||
let frm = $frm.user;
|
||||
$('.UserAccountId,input[type="text"],textarea,select', frm).val('');
|
||||
sax.clearControlErrors();
|
||||
if (!response.success) return;
|
||||
sax.clearUserData();
|
||||
let item = sax.userAccount = response.user;
|
||||
let frm = $frm.user;
|
||||
$('.UserAccountId', frm).val(item.id);
|
||||
$('.UserEmailAddress', frm).val(item.emailAddress);
|
||||
$('.UserTitle', frm).val(item.title);
|
||||
$('.UserFirstName', frm).val(item.firstName);
|
||||
$('.UserLastName', frm).val(item.lastName);
|
||||
$('.UserRegionIdCountry', frm).val(item.regionIdCountry);
|
||||
$('.UserRegionCaptionCountry', frm).val(item.regionNameCountry);
|
||||
$('.UserRegionIdProvince', frm).val(item.regionIdProvince);
|
||||
$('.UserRegionCaptionProvince', frm).val(item.regionNameProvince);
|
||||
$('.UserRoles', frm).val(sax.getSelectedUserRoleDescs().join('\n'));
|
||||
$('#ifUserRoleCodes').val(item.userRoleCodes.join(sax.data.userRoleCodeDelim));
|
||||
$('.UserStatus', frm).val(item.statusCode);
|
||||
|
||||
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* Admin - Users Online page scripts.
|
||||
*/
|
||||
|
||||
(function (win, doc, undef)
|
||||
{
|
||||
"use strict";
|
||||
let $pnl = sax.$pnl, $frm = sax.$frm, $dlg = sax.$dlg;
|
||||
sax.itemIdPrefix = 'Itm_';
|
||||
sax.userAccount = {};
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.refreshResults = function (delay)
|
||||
{
|
||||
if (!sax.awaitingRefreshResponse)
|
||||
{
|
||||
$('.sax-burger', $pnl.filter).hide();
|
||||
var $items = $('.sax-panel-item-list', $pnl.results).fadeOut(200).empty();
|
||||
var $msgs = $('.sax-panel-messages', $pnl.results).hide().empty().append($('<div class="sax-message">' + sax.msg.dataQuerying + '</div>')).fadeIn(200);
|
||||
}
|
||||
sax.ajax.refreshResults = sax.ajax.refreshResults || { url: sax.url.base + 'UsersOnline/Ajax/GetList', formId: 'frmUserFilter', callbackFn: sax.doRefreshResults };
|
||||
sax.doAjaxRequest(sax.ajax.refreshResults, delay || 50);
|
||||
sax.awaitingRefreshResponse = true;
|
||||
}
|
||||
sax.doRefreshResults = function (response)
|
||||
{
|
||||
//sax.debug('doRefreshResults', response);
|
||||
delete sax.awaitingRefreshResponse;
|
||||
sax.refreshControlValues(response.controlValues);
|
||||
var $msgs = $('.sax-panel-messages', $pnl.results).hide().empty();
|
||||
var $items = $('.sax-panel-item-list', $pnl.results).hide().empty();
|
||||
sax.refreshPaging(response, '#frmUserFilter', sax.refreshResults);
|
||||
if (!response.success) return;
|
||||
// Reference data - Roles.
|
||||
if (response.userRoles && response.userRoles.length)
|
||||
sax.data.userRoles = response.userRoles;
|
||||
// Reference data - Statuses.
|
||||
if (response.defaultStatusCode) sax.data.defaultStatusCode = response.defaultStatusCode;
|
||||
if (response.statuses)
|
||||
sax.populateSelectCodeDesc('#cbUserStatus', response.statuses);
|
||||
// Menu.
|
||||
var $bgr = $('.sax-burger', $pnl.filter).hide();
|
||||
var $mnu = $('ul.sax-dropdown-menu', $bgr).empty();
|
||||
$mnu.append(sax.getFilterMenuOption(sax.lbl.refresh, function () { sax.refreshResults(); }));
|
||||
$bgr.toggle(!!$('.sax-dropdown-item', $mnu).length);
|
||||
// Items.
|
||||
var items = response.users;
|
||||
if (!items.length)
|
||||
return $msgs.append($('<div class="sax-message">' + sax.msg.dataNoneFound + '</div>')).fadeIn(500);
|
||||
for (let itemIdx = 0; itemIdx < items.length; itemIdx++)
|
||||
$items.append(sax.populateItem(sax.getItemTemplate(), items[itemIdx]));
|
||||
$items.fadeIn(50);
|
||||
}
|
||||
sax.populateItem = function ($item, item)
|
||||
{
|
||||
if (!item) return;
|
||||
$item.prop('id', sax.itemIdPrefix + item.id);
|
||||
$('.UserEmailAddress', $item).text(item.emailAddress);
|
||||
$('.UserDisplayName', $item).text(item.displayName);
|
||||
$('.UserLastLoginAt', $item).text(item.lastLoginAt);
|
||||
$('.UserLastOnlineAt', $item).text(item.onlineAt);
|
||||
$('.sax-caption .sax-action').toggleClass('sax-action', !item.deleted);
|
||||
let $mnu = $('ul.sax-dropdown-menu', $item);
|
||||
if (!item.deleted)
|
||||
{
|
||||
//$mnu.append(sax.getItemMenuOption(sax.lbl.edit, function () { sax.updateItem(item) }));
|
||||
//$('.sax-header .sax-action.sax-item-update', $item).off('click').on('click', function () { sax.updateItem(item) });
|
||||
//$item.off('dblclick').on('dblclick', function () { sax.updateItem(item) });
|
||||
}
|
||||
$('.sax-burger', $item).toggle(!!$('.sax-dropdown-item', $mnu).length);
|
||||
$('.sax-panel-messages', $pnl.results).hide().empty();
|
||||
return $item;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.getFilterDropdownTemplate = function ()
|
||||
{
|
||||
return $('.sax-panel-item-template .sax-dropdown-menu.UserFilter li.sax-dropdown-item', $pnl.filter).clone();
|
||||
}
|
||||
sax.getItemTemplate = function ()
|
||||
{
|
||||
return $('.sax-panel-item-template .sax-panel-item.User', $pnl.results).clone();
|
||||
}
|
||||
sax.getItemDropdownTemplate = function ()
|
||||
{
|
||||
return $('.sax-panel-item-template .sax-dropdown-menu.User li.sax-dropdown-item', $pnl.results).clone();
|
||||
}
|
||||
sax.getFilterMenuOption = function (lbl, fn)
|
||||
{
|
||||
return sax.getMenuOption(sax.getFilterDropdownTemplate(), lbl, fn);
|
||||
}
|
||||
sax.getItemMenuOption = function (lbl, fn)
|
||||
{
|
||||
return sax.getMenuOption(sax.getItemDropdownTemplate(), lbl, fn);
|
||||
}
|
||||
sax.getMenuOption = function ($opt, lbl, fn)
|
||||
{
|
||||
return $opt.find('div.sax-label').text(lbl).end().on('click', fn);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.selectFilterSport = function ()
|
||||
{
|
||||
if (!sax.data.sports)
|
||||
{
|
||||
let handleFilterSportsResponse = function (response)
|
||||
{
|
||||
if (response && response.success && response.sports)
|
||||
sax.data.sports = response.sports;
|
||||
sax.showSelectFilterSport();
|
||||
}
|
||||
sax.ajax.filterSports = sax.ajax.filterSports || { url: sax.url.base + 'Sport/Ajax/GetList', formId: 'frmNavigate', callbackFn: handleFilterSportsResponse };
|
||||
sax.doAjaxRequest(sax.ajax.filterSports, 50);
|
||||
}
|
||||
else sax.showSelectFilterSport();
|
||||
}
|
||||
sax.showSelectFilterSport = function ()
|
||||
{
|
||||
sax.data.selectItem.fn.selectItem({ caption: sax.dlg.title.selectSport, items: sax.data.sports, fnCallback: sax.onFilterSportSelected });
|
||||
}
|
||||
sax.onFilterSportSelected = function (spt)
|
||||
{
|
||||
//sax.debug('onFilterSportSelected', sax.$frm.filter)
|
||||
let $frm = sax.$frm.filter;
|
||||
$('.FilterUserSportId', $frm).val(spt.id);
|
||||
$('.FilterUserSportCaption', $frm).val(spt.name);
|
||||
sax.refreshResults();
|
||||
}
|
||||
sax.clearFilterSport = function ()
|
||||
{
|
||||
$('.FilterUserSportId,.FilterUserSportCaption', sax.$frm.filter).val('');
|
||||
sax.refreshResults();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.selectFilterRegion = function ()
|
||||
{
|
||||
if (!sax.data.regions)
|
||||
{
|
||||
let handleFilterRegionsResponse = function (response)
|
||||
{
|
||||
if (response && response.success && response.regions)
|
||||
sax.data.regions = response.regions;
|
||||
sax.showSelectFilterRegion();
|
||||
}
|
||||
sax.ajax.regions = sax.ajax.regions || { url: sax.url.base + 'Region/Ajax/GetList', formId: 'frmNavigate', callbackFn: handleFilterRegionsResponse };
|
||||
sax.doAjaxRequest(sax.ajax.regions, 50);
|
||||
}
|
||||
else sax.showSelectFilterRegion();
|
||||
}
|
||||
sax.showSelectFilterRegion = function ()
|
||||
{
|
||||
sax.data.selectItem.fn.selectItem({ caption: sax.dlg.title.selectFilterRegion, items: sax.data.regions, fnCallback: sax.onFilterRegionSelected });
|
||||
}
|
||||
sax.onFilterRegionSelected = function (rgn)
|
||||
{
|
||||
//sax.debug('onFilterRegionSelected', rgn);
|
||||
let $frm = sax.$frm.filter;
|
||||
$('.FilterUserRegionId', $frm).val(rgn.id);
|
||||
$('.FilterUserRegionCaption', $frm).val(rgn.name);
|
||||
sax.refreshResults();
|
||||
}
|
||||
sax.clearFilterRegion = function ()
|
||||
{
|
||||
$('.FilterUserRegionId,.FilterUserRegionCaption', sax.$frm.filter).val('');
|
||||
sax.refreshResults();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// User Roles.
|
||||
sax.selectUserRoles = function ()
|
||||
{
|
||||
//sax.debug('selectUserRoles');
|
||||
sax.selectUserRoleConfig = sax.selectUserRoleConfig || { caption: sax.dlg.title.selectUserRoles, width: 520, fnCallback: sax.updateUserRoles };
|
||||
sax.selectUserRoleConfig.codes = sax.data.userRoles;
|
||||
sax.selectUserRoleConfig.selectedCodes = sax.userAccount.userRoleCodes || [];
|
||||
sax.selectCode.fn.openSelectCode(sax.selectUserRoleConfig);
|
||||
}
|
||||
sax.updateUserRoles = function (userRoleCodes)
|
||||
{
|
||||
//sax.debug('updateUserRoles', userRoleCodes);
|
||||
sax.userAccount.userRoleCodes = userRoleCodes;
|
||||
$('#ifUserRoleCodes').val(userRoleCodes.join(sax.data.userRoleCodeDelim));
|
||||
$('#ifUserRoles').val(sax.getSelectedUserRoleDescs().join('\n'));
|
||||
}
|
||||
sax.getSelectedUserRoleDescs = function ()
|
||||
{
|
||||
let userRoles = [];
|
||||
sax.userAccount.userRoleCodes.forEach(function (value) { userRoles.push(sax.getUserRoleDesc(value)); })
|
||||
return userRoles.sortCI();
|
||||
}
|
||||
sax.getUserRoleDesc = function (roleCode)
|
||||
{
|
||||
let roleDesc = '';
|
||||
sax.data.userRoles.some(function (value) { if (value.code == roleCode) { roleDesc = value.desc; return true; } return false; })
|
||||
return roleDesc || roleCode;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.createItem = function ()
|
||||
{
|
||||
let frm = $frm.user;
|
||||
$('.UserAccountId,.UserRoleCodes,input[type="text"],textarea,select', frm).val('');
|
||||
$('.UserStatus', frm).val(sax.data.defaultStatusCode);
|
||||
sax.clearControlErrors();
|
||||
sax.userAccount = { userRoleCodes: [] };
|
||||
$dlg.user.dialog('option', 'title', sax.dlg.title.createUser);
|
||||
sax.openDialog($dlg.user, 600, 480);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.updateItem = function (item)
|
||||
{
|
||||
$('.UserAccountId', $frm.userId).val(item.id);
|
||||
sax.ajax.updateItem = sax.ajax.updateItem || { url: sax.url.base + 'User/Ajax/GetItem', formId: 'frmUserId', callbackFn: sax.onUpdateItem };
|
||||
sax.doAjaxRequest(sax.ajax.updateItem, 50);
|
||||
}
|
||||
sax.onUpdateItem = function (response)
|
||||
{
|
||||
//sax.debug('onUpdateItem', response);
|
||||
let frm = $frm.user;
|
||||
$('.UserAccountId,input[type="text"],textarea,select', frm).val('');
|
||||
sax.clearControlErrors();
|
||||
if (!response.success) return;
|
||||
let item = sax.userAccount = response.user;
|
||||
$('.UserAccountId', frm).val(item.id);
|
||||
$('.UserEmailAddress', frm).val(item.emailAddress);
|
||||
$('.UserTitle', frm).val(item.title);
|
||||
$('.UserFirstName', frm).val(item.firstName);
|
||||
$('.UserLastName', frm).val(item.lastName);
|
||||
$('.UserRoles', frm).val(sax.getSelectedUserRoleDescs().join('\n'));
|
||||
$('#ifUserRoleCodes').val(item.userRoleCodes.join(sax.data.userRoleCodeDelim));
|
||||
$('.UserStatus', frm).val(item.statusCode);
|
||||
$dlg.user.dialog('option', 'title', sax.dlg.title.updateUser);
|
||||
sax.openDialog($dlg.user, 600, 480);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.storeItem = function ()
|
||||
{
|
||||
sax.ajax.storeItem = sax.ajax.storeItem || { url: sax.url.base + 'User/Ajax/StoreItem', formId: 'frmUser', callbackFn: sax.onStoreItem };
|
||||
sax.doAjaxRequest(sax.ajax.storeItem, 50);
|
||||
}
|
||||
sax.onStoreItem = function (response)
|
||||
{
|
||||
//sax.debug('onStoreItem', response);
|
||||
sax.refreshControlValues(response.controlValues);
|
||||
if (!response.success) return;
|
||||
$dlg.user.dialog('close');
|
||||
|
||||
var item = response.user;
|
||||
var $item = $('#' + sax.itemIdPrefix + item.id);
|
||||
if (!$item.length)
|
||||
{
|
||||
$item = sax.getItemTemplate();
|
||||
$('.sax-panel-item-list', $pnl.results).prepend($item).show();
|
||||
}
|
||||
$item.replaceWith(sax.populateItem(sax.getItemTemplate(), item));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.userEmails = function (item)
|
||||
{
|
||||
sax.debug('userEmails', item);
|
||||
let frm = $frm.emailsl
|
||||
$('.UserAccountId', frm).val(item.id);
|
||||
$('.UserEmailAddress', frm).val(item.emailAddress);
|
||||
$('.UserDisplayName', frm).val(item.displayName);
|
||||
$('.RequestPasswordAdminOption', frm).toggle(item.systemAdmin);
|
||||
$('input[type="checkbox"]', frm).prop('checked', false);
|
||||
$dlg.emails.dialog('option', { 'title': sax.dlg.title.selectUserEmails });
|
||||
sax.openDialog($dlg.emails, 600, 360);
|
||||
}
|
||||
sax.sendUserEmails = function ()
|
||||
{
|
||||
sax.ajax.sendEmails = sax.ajax.sendEmails || { url: sax.url.base + 'User/Ajax/SendEmails', formId: 'frmUserEmails', callbackFn: sax.onUserEmails };
|
||||
sax.doAjaxRequest(sax.ajax.sendEmails, 50);
|
||||
}
|
||||
sax.onUserEmails = function (response)
|
||||
{
|
||||
if (!response || !response.success) return;
|
||||
$dlg.emails.dialog('close');
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
$(function ()
|
||||
{
|
||||
$pnl.users = $('.sax-panel.Users');
|
||||
$pnl.filter = $('.sax-panel-filter', $pnl.users);
|
||||
$pnl.results = $('.sax-panel-results', $pnl.users);
|
||||
|
||||
$frm.filter = $('#frmUserFilter');
|
||||
$('.FilterUser', $frm.filter).on('input', function () { sax.refreshResults(250); });
|
||||
$('.FilterUserStatusCategory', $frm.filter).on('change', function () { sax.refreshResults(50); });
|
||||
$frm.userId = $('#frmUserId');
|
||||
$frm.user = $('#frmUser');
|
||||
$('.sax-input, .sax-textarea', $frm.user).on('input', function () { sax.clearControlError(this); });
|
||||
$('.sax-select', $frm.user).on('change', function () { sax.clearControlError(this); });
|
||||
$frm.emails = $('#frmUserEmails');
|
||||
|
||||
var opt = sax.dlgOpts();
|
||||
opt.buttons[sax.dlg.btn.ok] = function () { sax.storeItem(); };
|
||||
opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); };
|
||||
$dlg.user = $('#dlgUser').dialog(opt);
|
||||
|
||||
opt = sax.dlgOpts();
|
||||
opt.buttons[sax.dlg.btn.ok] = function () { sax.sendUserEmails(); };
|
||||
opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); };
|
||||
$dlg.emails = $('#dlgUserEmails').dialog(opt);
|
||||
|
||||
setTimeout(sax.refreshResults, 250);
|
||||
});
|
||||
|
||||
}(window, window.document));
|
||||
|
||||
/* The End */
|
||||
Reference in New Issue
Block a user