/// <summary> /// Reset user account lock status /// </summary> protected void btnResetLogonAttempts_Click(object sender, EventArgs e) { // Check "modify" permission if (!CurrentUser.IsAuthorizedPerResource("CMS.Users", "Modify")) { RedirectToAccessDenied("CMS.Users", "Modify"); } bool unlocked = false; if (ui.UserAccountLockReason == UserAccountLockCode.FromEnum(UserAccountLockEnum.MaximumInvalidLogonAttemptsReached)) { AuthenticationHelper.UnlockUserAccount(ui); unlocked = true; } else { ui.UserInvalidLogOnAttempts = 0; UserInfoProvider.SetUserInfo(ui); } LoadData(); lblInvalidLogonAttemptsNumber.Style.Clear(); ShowConfirmation(unlocked ? GetString("Administration-User.InvalidLogonAttemptsResetUnlock") : GetString("Administration-User.InvalidLogonAttemptsReset")); }
/// <summary> /// Reset user account lock status /// </summary> protected void btnExtendValidity_Click(object sender, EventArgs e) { // Check "modify" permission if (!CurrentUser.IsAuthorizedPerResource("CMS.Users", "Modify")) { RedirectToAccessDenied("CMS.Users", "Modify"); } bool unlocked = false; ui.UserPasswordLastChanged = DateTime.Now; if (ui.UserAccountLockReason == UserAccountLockCode.FromEnum(UserAccountLockEnum.PasswordExpired)) { AuthenticationHelper.UnlockUserAccount(ui); unlocked = true; } else { UserInfoProvider.SetUserInfo(ui); } LoadData(); if (unlocked) { ShowConfirmation(GetString("Administration-User.ExtendPasswordUnlock")); } else { ShowConfirmation(GetString("Administration-User.ExtendPassword")); } }
/// <summary> /// Load user password expiration /// </summary> /// <param name="ui">User info</param> protected void LoadPasswordExpiration(UserInfo ui) { int expDays = 0; lblExpireIn.Style.Clear(); lblPassExpiration.Text = GetString("Administration-User_Edit_General.PasswordExpireIn"); if (!AuthenticationHelper.IsPasswordExpirationEnabled(SiteContext.CurrentSiteName, out expDays)) { lblExpireIn.Text = GetString("security.never"); btnExtendValidity.Enabled = (ui.UserAccountLockReason == UserAccountLockCode.FromEnum(UserAccountLockEnum.PasswordExpired)); } else { // Get password expiration, negative number means not expired, positive means expired, DateTime.Min means not expired but never changed password int dayDiff = (ui.UserPasswordLastChanged == DateTime.MinValue) ? -expDays : ((DateTime.Now - ui.UserPasswordLastChanged).Days - expDays); if (dayDiff >= 0) { lblPassExpiration.Text = GetString("Administration-User_Edit_General.PasswordExpired"); lblExpireIn.Style.Add(HtmlTextWriterStyle.Color, "Red"); } lblExpireIn.Text = string.Format(GetString("general.validity.days"), Math.Abs(dayDiff)); } }
/// <summary> /// Loads data of edited user from DB into TextBoxes. /// </summary> protected void LoadData() { // Fill lstUICulture (loop over and localize them first) DataSet uiCultures = CultureInfoProvider.GetUICultures().OrderBy("CultureName"); LocalizeCultureNames(uiCultures); lstUICulture.DataSource = uiCultures.Tables[0].DefaultView; lstUICulture.DataTextField = "CultureName"; lstUICulture.DataValueField = "CultureID"; lstUICulture.DataBind(); lstUICulture.Items.Insert(0, GetString("Administration-User_Edit.Default")); lstUICulture.Items[0].Value = "0"; if (ui != null) { // Get user info properties txtEmail.Text = ui.Email; txtFirstName.Text = ui.FirstName; txtFullName.Text = ui.FullName; txtLastName.Text = ui.LastName; txtMiddleName.Text = ui.MiddleName; ucUserName.Value = ui.UserName; CheckBoxEnabled.Checked = ui.Enabled; chkIsExternal.Checked = ui.IsExternal; chkIsDomain.Checked = ui.UserIsDomain; chkIsHidden.Checked = ui.UserIsHidden; chkIsMFRequired.Checked = ui.UserMFRequired; // Privilege drop down check if (!CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin)) { // Disable for global admins if (ui.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin)) { drpPrivilege.Enabled = false; } else // Only global admin can manage other admins. if (ui.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin)) { // Allow manage only for user himself if (ui.UserID != CurrentUser.UserID) { drpPrivilege.Enabled = false; } else { drpPrivilege.ExcludedValues = ((int)UserPrivilegeLevelEnum.GlobalAdmin).ToString(); } } else { drpPrivilege.ExcludedValues = (int)UserPrivilegeLevelEnum.GlobalAdmin + ";" + (int)UserPrivilegeLevelEnum.Admin; } } if (ui.IsGlobalAdministrator) { drpPrivilege.Value = ui.UserGlobalAccessDisabled ? (int)UserPrivilegeLevelEnum.Admin : (int)UserPrivilegeLevelEnum.GlobalAdmin; } else if (ui.IsEditorInternal) { drpPrivilege.Value = (int)UserPrivilegeLevelEnum.Editor; } password = ui.GetValue("UserPassword").ToString(); // Disable username textbox for public user if (ui.IsPublic()) { ucUserName.Enabled = false; } myCulture = ui.PreferredCultureCode; myUICulture = ui.PreferredUICultureCode; lblInvalidLogonAttemptsNumber.Text = string.Format(GetString("general.attempts"), ui.UserInvalidLogOnAttempts); if (ui.UserInvalidLogOnAttempts > 0) { lblInvalidLogonAttemptsNumber.Style.Add(HtmlTextWriterStyle.Color, "Red"); } else { btnResetLogonAttempts.Enabled = (ui.UserAccountLockReason == UserAccountLockCode.FromEnum(UserAccountLockEnum.MaximumInvalidLogonAttemptsReached)); } LoadPasswordExpiration(ui); txtUserStartingPath.Text = ui.UserStartingAliasPath; } // Set content culture cultureSelector.Value = myCulture; if (!string.IsNullOrEmpty(myUICulture)) { // Set UI culture try { CultureInfo ciUI = CultureInfoProvider.GetCultureInfo(myUICulture); lstUICulture.SelectedIndex = lstUICulture.Items.IndexOf(lstUICulture.Items.FindByValue(ciUI.CultureID.ToString())); } catch { lstUICulture.SelectedIndex = lstUICulture.Items.IndexOf(lstUICulture.Items.FindByValue("0")); } } else { lstUICulture.SelectedIndex = lstUICulture.Items.IndexOf(lstUICulture.Items.FindByValue("0")); } if (ui != null) { // If new user lblCreatedInfo.Text = ui.UserCreated.ToString(); lblLastLogonTime.Text = ui.LastLogon.ToString(); LoadUserLogon(ui); if (ui.UserCreated == DateTimeHelper.ZERO_TIME) { lblCreatedInfo.Text = GetString("general.na"); } if (ui.LastLogon == DateTimeHelper.ZERO_TIME) { lblLastLogonTime.Text = GetString("general.na"); } } }
/// <summary> /// Saves data of edited user from TextBoxes into DB. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { UserPrivilegeLevelEnum privilegeLevel = (UserPrivilegeLevelEnum)drpPrivilege.Value.ToInteger(0); // Check "modify" permission if (!CurrentUser.IsAuthorizedPerResource("CMS.Users", "Modify")) { RedirectToAccessDenied("CMS.Users", "Modify"); } string result = ValidateGlobalAndDeskAdmin(userId); // Find whether user name is valid if (result == String.Empty) { if (!ucUserName.IsValid()) { result = ucUserName.ValidationError; } } String userName = ValidationHelper.GetString(ucUserName.Value, String.Empty); if (result == String.Empty) { // Finds whether required fields are not empty result = new Validator().NotEmpty(txtFullName.Text, GetString("Administration-User_New.RequiresFullName")).Result; } // Store the old display name var oldDisplayName = ui.Generalized.ObjectDisplayName; if ((result == String.Empty) && (ui != null)) { // If site prefixed allowed - ad site prefix if ((SiteID != 0) && UserInfoProvider.UserNameSitePrefixEnabled(SiteContext.CurrentSiteName)) { if (!UserInfoProvider.IsSitePrefixedUser(userName)) { userName = UserInfoProvider.EnsureSitePrefixUserName(userName, SiteContext.CurrentSite); } } // Validation for site prefixed users if (!UserInfoProvider.IsUserNamePrefixUnique(userName, ui.UserID)) { ShowError(GetString("Administration-User_New.siteprefixeduserexists")); return; } // Ensure same password password = ui.GetValue("UserPassword").ToString(); // Test for unique username UserInfo uiTest = UserInfoProvider.GetUserInfo(userName); if ((uiTest == null) || (uiTest.UserID == userId)) { if (ui == null) { ui = new UserInfo(); } bool globAdmin = ui.IsGlobalAdministrator; bool editor = ui.IsEditorInternal; // Email format validation string email = txtEmail.Text.Trim(); if ((email != string.Empty) && (!ValidationHelper.IsEmail(email))) { ShowError(GetString("Administration-User_New.WrongEmailFormat")); return; } bool oldGlobal = ui.IsGlobalAdministrator; bool oldEditor = ui.IsEditorInternal; // Define domain variable string domains = null; // Get all user sites DataTable ds = UserInfoProvider.GetUserSites(userId, null, null, 0, "SiteDomainName"); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Rows) { domains += ValidationHelper.GetString(dr["SiteDomainName"], string.Empty) + ";"; } // Remove ";" at the end if (domains != null) { domains = domains.Remove(domains.Length - 1); } } else { DataSet siteDs = SiteInfoProvider.GetSites().Columns("SiteDomainName"); if (!DataHelper.DataSourceIsEmpty(siteDs)) { // Create list of available site domains domains = TextHelper.Join(";", DataHelper.GetStringValues(siteDs.Tables[0], "SiteDomainName")); } } // Check limitations for Global administrator if (CurrentUser.IsGlobalAdministrator && ((privilegeLevel == UserPrivilegeLevelEnum.GlobalAdmin) || (privilegeLevel == UserPrivilegeLevelEnum.Admin)) && !oldGlobal) { if (!UserInfoProvider.LicenseVersionCheck(domains, FeatureEnum.Administrators, ObjectActionEnum.Insert, globAdmin)) { ShowError(GetString("License.MaxItemsReachedGlobal")); return; } } // Check limitations for editors if ((privilegeLevel == UserPrivilegeLevelEnum.Editor) && !oldEditor) { if (!UserInfoProvider.LicenseVersionCheck(domains, FeatureEnum.Editors, ObjectActionEnum.Insert, editor)) { ShowError(GetString("License.MaxItemsReachedEditor")); return; } } // Check whether email is unique if it is required if (!UserInfoProvider.IsEmailUnique(email, ui)) { ShowError(GetString("UserInfo.EmailAlreadyExist")); return; } // Set properties ui.Email = email; ui.FirstName = txtFirstName.Text.Trim(); ui.FullName = txtFullName.Text.Trim(); ui.LastName = txtLastName.Text.Trim(); ui.MiddleName = txtMiddleName.Text.Trim(); ui.UserName = userName; ui.Enabled = CheckBoxEnabled.Checked; ui.UserIsHidden = chkIsHidden.Checked; ui.IsExternal = chkIsExternal.Checked; ui.UserIsDomain = chkIsDomain.Checked; ui.SetValue("UserPassword", password); ui.UserID = userId; ui.UserStartingAliasPath = txtUserStartingPath.Text.Trim(); ui.UserMFRequired = chkIsMFRequired.Checked; // Global admin can set anything if (CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin) // Other users can set only editor and non privileges || ((privilegeLevel != UserPrivilegeLevelEnum.Admin) && (privilegeLevel != UserPrivilegeLevelEnum.GlobalAdmin)) // Admin can manage his own privilege || ((privilegeLevel == UserPrivilegeLevelEnum.Admin) && (CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin) && (CurrentUser.UserID == ui.UserID)))) { ui.SetPrivilegeLevel(privilegeLevel); } LoadUserLogon(ui); // Set values of cultures. string culture = ValidationHelper.GetString(cultureSelector.Value, ""); ui.PreferredCultureCode = culture; if (lstUICulture.SelectedValue == "0") { ui.PreferredUICultureCode = ""; } else { // Set preferred UI culture CultureInfo ci = CultureInfoProvider.GetCultureInfo(ValidationHelper.GetInteger(lstUICulture.SelectedValue, 0)); ui.PreferredUICultureCode = ci.CultureCode; } // Refresh page breadcrumbs if display name changed if (ui.Generalized.ObjectDisplayName != oldDisplayName) { ScriptHelper.RefreshTabHeader(Page, ui.FullName); } using (CMSActionContext context = new CMSActionContext()) { // Check whether the username of the currently logged user has been changed if (CurrentUserChangedUserName()) { // Ensure that an update search task will be created but NOT executed when updating the user context.EnableSmartSearchIndexer = false; } // Update the user UserInfoProvider.SetUserInfo(ui); // Check whether the username of the currently logged user has been changed if (CurrentUserChangedUserName()) { // Ensure that current user is not logged out if he changes his user name if (RequestHelper.IsFormsAuthentication()) { FormsAuthentication.SetAuthCookie(ui.UserName, false); // Update current user MembershipContext.AuthenticatedUser = new CurrentUserInfo(ui, true); // Reset current user CurrentUser = null; } } } ShowChangesSaved(); } else { // If user exists ShowError(GetString("Administration-User_New.UserExists")); } } else { ShowError(result); } if ((ui.UserInvalidLogOnAttempts == 0) && (ui.UserAccountLockReason != UserAccountLockCode.FromEnum(UserAccountLockEnum.MaximumInvalidLogonAttemptsReached))) { btnResetLogonAttempts.Enabled = false; } LoadPasswordExpiration(ui); }
/// <summary> /// Loads data of edited user from DB into TextBoxes. /// </summary> protected void LoadData() { // Fill lstUICulture (loop over and localize them first) DataSet uiCultures = UICultureInfoProvider.GetUICultures(null, "UICultureName ASC"); LocalizeCultureNames(uiCultures); lstUICulture.DataSource = uiCultures.Tables[0].DefaultView; lstUICulture.DataTextField = "UICultureName"; lstUICulture.DataValueField = "UICultureID"; lstUICulture.DataBind(); lstUICulture.Items.Insert(0, GetString("Administration-User_Edit.Default")); lstUICulture.Items[0].Value = "0"; if (ui != null) { // Get user info properties txtEmail.Text = ui.Email; txtFirstName.Text = ui.FirstName; txtFullName.Text = ui.FullName; txtLastName.Text = ui.LastName; txtMiddleName.Text = ui.MiddleName; ucUserName.Value = ui.UserName; CheckBoxEnabled.Checked = ui.Enabled; CheckBoxIsEditor.Checked = ui.IsEditor; CheckBoxLabelIsGlobalAdministrator.Checked = ui.IsGlobalAdministrator; chkIsExternal.Checked = ui.IsExternal; chkIsDomain.Checked = ui.UserIsDomain; chkIsHidden.Checked = ui.UserIsHidden; chkSiteManagerDisabled.Checked = ui.UserSiteManagerDisabled; password = ui.GetValue("UserPassword").ToString(); // Disable username textbox for public user if (ui.IsPublic()) { ucUserName.Enabled = false; } myCulture = ui.PreferredCultureCode; myUICulture = ui.PreferredUICultureCode; lblInvalidLogonAttemptsNumber.Text = string.Format(GetString("general.attempts"), ui.UserInvalidLogOnAttempts); if (ui.UserInvalidLogOnAttempts > 0) { lblInvalidLogonAttemptsNumber.Style.Add(HtmlTextWriterStyle.Color, "Red"); } else { btnResetLogonAttempts.Enabled = (ui.UserAccountLockReason == UserAccountLockCode.FromEnum(UserAccountLockEnum.MaximumInvalidLogonAttemptsReached)); } LoadPasswordExpiration(ui); txtUserStartingPath.Text = ui.UserStartingAliasPath; } // Set content culture cultureSelector.Value = myCulture; if (!string.IsNullOrEmpty(myUICulture)) { // Set UI culture try { UICultureInfo ciUI = UICultureInfoProvider.GetUICultureInfo(myUICulture); lstUICulture.SelectedIndex = lstUICulture.Items.IndexOf(lstUICulture.Items.FindByValue(ciUI.UICultureID.ToString())); } catch { lstUICulture.SelectedIndex = lstUICulture.Items.IndexOf(lstUICulture.Items.FindByValue("0")); } } else { lstUICulture.SelectedIndex = lstUICulture.Items.IndexOf(lstUICulture.Items.FindByValue("0")); } if (ui != null) { // If new user lblCreatedInfo.Text = ui.UserCreated.ToString(); lblLastLogonTime.Text = ui.LastLogon.ToString(); LoadUserLogon(ui); if (ui.UserCreated == DataHelper.DATETIME_NOT_SELECTED) { lblCreatedInfo.Text = GetString("general.na"); } if (ui.LastLogon == DataHelper.DATETIME_NOT_SELECTED) { lblLastLogonTime.Text = GetString("general.na"); } } }
/// <summary> /// Saves data of edited user from TextBoxes into DB. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { // Check "modify" permission if (!currentUser.IsAuthorizedPerResource("CMS.Users", "Modify")) { RedirectToAccessDenied("CMS.Users", "Modify"); } string result = ValidateGlobalAndDeskAdmin(userId); // Find whether user name is valid if (result == String.Empty) { if (!ucUserName.IsValid()) { result = ucUserName.ValidationError; } } String userName = ValidationHelper.GetString(ucUserName.Value, String.Empty); if (result == String.Empty) { // Finds whether required fields are not empty result = new Validator().NotEmpty(txtFullName.Text, GetString("Administration-User_New.RequiresFullName")).Result; } if ((result == String.Empty) && (ui != null)) { // If site prefixed allowed - ad site prefix if ((SiteID != 0) && UserInfoProvider.UserNameSitePrefixEnabled(CMSContext.CurrentSiteName)) { if (!UserInfoProvider.IsSitePrefixedUser(userName)) { userName = UserInfoProvider.EnsureSitePrefixUserName(userName, CMSContext.CurrentSite); } } // Validation for site prefixed users if (!UserInfoProvider.IsUserNamePrefixUnique(userName, ui.UserID)) { result = GetString("Administration-User_New.siteprefixeduserexists"); } // Ensure same password password = ui.GetValue("UserPassword").ToString(); // Test for unique username UserInfo uiTest = UserInfoProvider.GetUserInfo(userName); if ((uiTest == null) || (uiTest.UserID == userId)) { if (ui == null) { ui = new UserInfo(); } bool globAdmin = ui.IsGlobalAdministrator; bool editor = ui.IsEditor; // Email format validation string email = txtEmail.Text.Trim(); if ((email != string.Empty) && (!ValidationHelper.IsEmail(email))) { ShowError(GetString("Administration-User_New.WrongEmailFormat")); return; } bool oldGlobal = ui.IsGlobalAdministrator; bool oldEditor = ui.IsEditor; if (ui.UserName != userName) { // Refresh the breadcrumb ScriptHelper.RefreshTabHeader(Page, null); } // Define domain variable string domains = null; // Get all user sites DataTable ds = UserInfoProvider.GetUserSites(userId, null, null, 0, "SiteDomainName"); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Rows) { domains += ValidationHelper.GetString(dr["SiteDomainName"], string.Empty) + ";"; } // Remove ";" at the end if (domains != null) { domains = domains.Remove(domains.Length - 1); } } else { DataSet siteDs = SiteInfoProvider.GetSites(null, null, "SiteDomainName"); if (!DataHelper.DataSourceIsEmpty(siteDs)) { // Create list of available site domains domains = TextHelper.Join(";", SystemDataHelper.GetStringValues(siteDs.Tables[0], "SiteDomainName")); } } // Check limitations for Global administrator if (currentUser.IsGlobalAdministrator && CheckBoxLabelIsGlobalAdministrator.Checked && !oldGlobal) { if (!UserInfoProvider.LicenseVersionCheck(domains, FeatureEnum.GlobalAdmininistrators, VersionActionEnum.Insert, globAdmin)) { ShowError(GetString("License.MaxItemsReachedGlobal")); return; } } // Check limitations for editors if (CheckBoxIsEditor.Checked && !oldEditor) { if (!UserInfoProvider.LicenseVersionCheck(domains, FeatureEnum.Editors, VersionActionEnum.Insert, editor)) { ShowError(GetString("License.MaxItemsReachedEditor")); return; } } // Check whether email is unique if it is required if (!UserInfoProvider.IsEmailUnique(email, ui)) { ShowError(GetString("UserInfo.EmailAlreadyExist")); return; } // Set properties ui.Email = email; ui.FirstName = txtFirstName.Text.Trim(); ui.FullName = txtFullName.Text.Trim(); ui.LastName = txtLastName.Text.Trim(); ui.MiddleName = txtMiddleName.Text.Trim(); ui.UserName = userName; ui.Enabled = CheckBoxEnabled.Checked; ui.IsEditor = CheckBoxIsEditor.Checked; ui.UserIsHidden = chkIsHidden.Checked; // Only admins who have access to site manager can set this if (!currentUser.UserSiteManagerDisabled) { ui.UserSiteManagerDisabled = chkSiteManagerDisabled.Checked; // Only admin who have access to site manager can create another global admin ui.IsGlobalAdministrator = currentUser.IsGlobalAdministrator && CheckBoxLabelIsGlobalAdministrator.Checked; } ui.IsExternal = chkIsExternal.Checked; ui.UserIsDomain = chkIsDomain.Checked; ui.SetValue("UserPassword", password); ui.UserID = userId; ui.UserStartingAliasPath = txtUserStartingPath.Text.Trim(); LoadUserLogon(ui); // Set values of cultures. string culture = ValidationHelper.GetString(cultureSelector.Value, ""); ui.PreferredCultureCode = culture; if (lstUICulture.SelectedValue == "0") { ui.PreferredUICultureCode = ""; } else { // Set preferred UI culture UICultureInfo ciUI = UICultureInfoProvider.GetUICultureInfo(Convert.ToInt32(lstUICulture.SelectedValue)); ui.PreferredUICultureCode = ciUI.UICultureCode; } using (CMSActionContext context = new CMSActionContext()) { // Check whether the username of the currently logged user has been changed if ((currentUser != null) && (currentUser.UserID == ui.UserID) && (currentUser.UserName != ui.UserName)) { // Ensure that an update search task will be created but NOT executed when updating the user context.EnableSmartSearchIndexer = false; } // Update the user UserInfoProvider.SetUserInfo(ui); } ShowChangesSaved(); } else { // If user exists ShowError(GetString("Administration-User_New.UserExists")); } } else { ShowError(result); } if ((ui.UserInvalidLogOnAttempts == 0) && (ui.UserAccountLockReason != UserAccountLockCode.FromEnum(UserAccountLockEnum.MaximumInvalidLogonAttemptsReached))) { btnResetLogonAttempts.Enabled = false; } LoadPasswordExpiration(ui); }