public ActionResult ChangePassword() { var context = new SitecoreContext(); var model = context.GetCurrentItem <ChangePassword>(); model.isPasswordPolicyFail = false; model.isShowPasswordUpdated = false; SitecoreProfileService scProfileService = new SitecoreProfileService(); if (Session["isShowPasswordUpdated"] != null) { model.isShowPasswordUpdated = (bool)Session["isShowPasswordUpdated"]; Session["isShowPasswordUpdated"] = null; } if (Session["ChangePasswordError"] != null) { List <ModelErrorCollection> allerror = (List <ModelErrorCollection>)Session["ChangePasswordError"]; foreach (var item in allerror) { foreach (var subItem in item) { ModelState.AddModelError("", subItem.ErrorMessage.ToString()); } } Session["ChangePasswordError"] = null; } if (scProfileService.CheckForDisableAccountUpdates()) { model.isAccountLocked = true; ModelState.AddModelError("", Sitecore.Globalization.Translate.Text("Profile_AccountNoUpdateAllow")); } else { model.isAccountLocked = false; if (Request.QueryString["PasswordRuleFail"] != "" && Request.QueryString["PasswordRuleFail"] == "true") { var membershipUser = scProfileService.GetCurrentMembershipUser(); ProfileService profileService = new ProfileService(); profileService.SetLoginWaitContext(membershipUser.Email, scProfileService.RemoveDomainToUserName(membershipUser.UserName), null, null); model.isPasswordPolicyFail = true; } else { //If the user acecss this page using Self service they MUST be authenticated If not we send them back to the Login page BlueGreenContext bgContext = new BlueGreenContext(); if (!bgContext.IsAuthenticated) { Response.Redirect(UrlMapper.Map(model.SiteSettings.SignInPage.Url)); } } } return(View(model)); }
public ActionResult ChangePasswordProcess(ChangePassword changePassword) { var context = new SitecoreContext(); ChangePassword model = context.GetCurrentItem <ChangePassword>(); if (!changePassword.isPasswordPolicyFail && !Context.User.IsAuthenticated) { Response.Redirect(UrlMapper.Map(model.SiteSettings.SignInPage.Url)); return(null); } model.isPasswordPolicyFail = changePassword.isPasswordPolicyFail; //Reset the default value if (ModelState.IsValid) { if (changePassword.txtNewPassword.Contains(" ")) { ModelState.AddModelError("", Sitecore.Globalization.Translate.Text("Profile_PasswordInvalid")); } else { SitecoreProfileService scProfileService = new SitecoreProfileService(); var membershipUser = scProfileService.GetCurrentMembershipUser(); if (membershipUser.ChangePassword(changePassword.txtCurrentPassword, changePassword.txtNewPassword)) { EmailManager.UpdatePassword(membershipUser.UserName, membershipUser.Email); if (changePassword.isPasswordPolicyFail)// Need to Complete the login Proces { Response.Redirect(UrlMapper.Map(model.SiteSettings.SignInWaitPage.Url)); return(null); } else { Session["isShowPasswordUpdated"] = true; // model.isShowPasswordUpdated = true; return(Redirect(UrlMapper.Map(SitecoreUtils.GetPageUrl(SitecoreItemReferences.ChangePasswordPageId)))); } } else { MembershipUser user = Membership.GetUser(Context.User.Name, false); if (user != null) { if (user.IsLockedOut) { var scUser = scProfileService.GetUser(Context.User.Name); Components.EmailManager.ResetEmail(Context.User.Name, scUser.Profile.Email); if (scUser != null && !scProfileService.CheckForPasswordLockedEmail(scUser)) { scUser.Profile.SetCustomProperty(SitecoreProfileService.PasswordLockedEmailId, "1"); scUser.Profile.Save(); } Session["SignInUiError"] = Sitecore.Globalization.Translate.Text("Profile_AccountLocked"); return(Redirect(UrlMapper.Map(model.SiteSettings.SignInPage.Url))); } } ModelState.AddModelError("", Sitecore.Globalization.Translate.Text("CurrentPassword_Current_NotCorrect")); } } } var errors = ModelState.Select(x => x.Value.Errors) .Where(y => y.Count > 0) .ToList(); if (errors != null && errors.Count > 0) { Session["ChangePasswordError"] = errors; } if (changePassword.isPasswordPolicyFail) { return(Redirect(UrlMapper.Map(SitecoreUtils.GetPageUrl(SitecoreItemReferences.ChangePasswordPageId)) + "?PasswordRuleFail=true")); } else { return(Redirect(UrlMapper.Map(SitecoreUtils.GetPageUrl(SitecoreItemReferences.ChangePasswordPageId)))); } //return View(model); }