public ActionResult ResetPassword() { var context = new SitecoreContext(); var model = context.GetCurrentItem <ResetPassword>(); if (Request.QueryString["email"] == null || Request.QueryString["resetid"] == null) { WebUtil.Redirect("/Home"); } model.email = Request.QueryString["email"]; model.resetid = FormatUtils.ConvertToGuid(Request.QueryString["resetid"]); SitecoreProfileService scProfileService = new SitecoreProfileService(); var scUserName = scProfileService.GetUserByEmail(model.email); ProfileService profileService = new ProfileService(); var user = scProfileService.GetUser(scUserName); if (Session["ResetPasswordError"] != null) { List <ModelErrorCollection> allerror = (List <ModelErrorCollection>)Session["ResetPasswordError"]; foreach (var item in allerror) { foreach (var subItem in item) { ModelState.AddModelError("", subItem.ErrorMessage.ToString()); } } Session["ResetPasswordError"] = null; } if (user != null && user.Profile != null) { Guid userResetId = FormatUtils.ConvertToGuid(user.Profile.GetCustomProperty("Forgot Password Unique Id")); var forgotPasswordTimestamp = user.Profile.GetCustomProperty("Forgot Password Timestamp"); if (Guid.Equals(userResetId, model.resetid)) { DateTime expireDate = DateUtil.ParseDateTime(forgotPasswordTimestamp, DateTime.MinValue); if (expireDate != DateTime.MinValue) { int forgotPasswordExpirationTime = Int32.Parse(Sitecore.Configuration.Settings.GetSetting("ForgotPasswordExpirationTime")); if (DateTime.Now > expireDate.AddHours(forgotPasswordExpirationTime)) { model.hideUIElement = true; ViewData["message"] = model.MessageLinkExpired; // WebUtil.Redirect("/Home"); } } } else { model.hideUIElement = true; ViewData["message"] = model.MessageLinkInvalid; //WebUtil.Redirect("/Home"); } } return(View(model)); }
public ActionResult Register(Registration registrationInfo) { var profileservice = new ProfileService(); if (registrationInfo.btnSubmit == "action:lookup") { foreach (var modelValue in ModelState.Values) { modelValue.Errors.Clear(); } if (string.IsNullOrEmpty(registrationInfo.txtLookupSSN) || string.IsNullOrEmpty(registrationInfo.txtLookupPhone)) { ModelState.AddModelError("", Sitecore.Globalization.Translate.Text("Register_AccountNotFound")); } else { var ownerId = profileservice.GetOwnerNumber(registrationInfo.txtLookupSSN, registrationInfo.txtLookupPhone); if (string.IsNullOrEmpty(ownerId)) { ModelState.AddModelError("", Sitecore.Globalization.Translate.Text("Register_AccountNotFound")); } else { ValueProviderResult temp = new ValueProviderResult(ownerId, ownerId, CultureInfo.InvariantCulture); ModelState["txtOwnerId"].Value = temp; } } } else if (registrationInfo.btnSubmit == "action:register") { if (ModelState.IsValid) { if (registrationInfo.txtPassword.Contains(" ")) { ModelState.AddModelError("", Sitecore.Globalization.Translate.Text("Profile_PasswordInvalid")); } else { RegisterServiceModel serviceModel = new Services.RegisterServiceModel(); SitecoreProfileService scProfileService = new SitecoreProfileService(); ProfileService profileService = new ProfileService(); var scUserName = scProfileService.AddDomainToUserName(registrationInfo.txtOwnerId); if (scProfileService.SitecoreExists(scUserName)) { var user = scProfileService.GetUser(scUserName); if (user.Profile.Email == registrationInfo.txtAcctEmail) { ModelState.AddModelError("", Sitecore.Globalization.Translate.Text("Register_EmailAlreadyRestierToSameOwner")); } else { ModelState.AddModelError("", Sitecore.Globalization.Translate.Text("Register_OwnerAlreadyRegister")); } } else { bool allowRegistration = false; var username = scProfileService.GetUserByEmail(registrationInfo.txtAcctEmail); if (string.IsNullOrEmpty(username)) { var legacyUser = profileService.GetOwnerDemographic(registrationInfo.txtAcctEmail, null); if (legacyUser == null) { allowRegistration = true; } else if (legacyUser.OwnerId == registrationInfo.txtOwnerId) { allowRegistration = true; } } //Verify if the email already exists if (allowRegistration) { serviceModel.Email = registrationInfo.txtAcctEmail; serviceModel.OwnerId = registrationInfo.txtOwnerId; serviceModel.Password = registrationInfo.txtPassword; serviceModel.Phone = registrationInfo.txtPhone; serviceModel.SSN = registrationInfo.txtSSN; if (profileservice.Register(serviceModel)) { var loginResponse = profileservice.LoginUser(registrationInfo.txtAcctEmail, registrationInfo.txtPassword, null, null, null, null); Session["LoginEmail"] = registrationInfo.txtAcctEmail; Session["LoginPassword"] = registrationInfo.txtPassword; Session["EnrollAcctNo"] = registrationInfo.txtOwnerId; Session["ownerACCT"] = registrationInfo.txtOwnerId; Session["ownerRegisterReferrer"] = "Register"; Response.Redirect(UrlMapper.Map(registrationInfo.PostbackSuccessPageUrl), false); return(null); //RedirectRegistrationConfirmation(UrlMapper.Map(registrationInfo.PostbackSuccessPageUrl)); } else { ViewData["ShowUnsuccessMessage"] = "true"; } } else { ModelState.AddModelError("", Sitecore.Globalization.Translate.Text("Register_EmailMustBeUnique")); } } } } } return(base.Index()); }
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); }