コード例 #1
0
        public ActionResult ForgotPassword(ForgotPassword form)
        {
            if (ModelState.IsValid)
            {
                SitecoreProfileService scProfileService = new SitecoreProfileService();
                ProfileService         profileService   = new ProfileService();

                var scUser = scProfileService.GetUserByEmail(form.txtEmail);

                if (scProfileService.SitecoreExists(scUser))
                {
                    if (scProfileService.CheckForDisableAccountUpdates(scUser))
                    {
                        form.isAccountLocked = true;
                        ModelState.AddModelError("", Sitecore.Globalization.Translate.Text("Profile_AccountNoUpdateAllow"));
                    }
                    else
                    {
                        if (EmailManager.ResetEmail(scUser, form.txtEmail))
                        {
                            // ModelState.AddModelError("", Sitecore.Globalization.Translate.Text("Profile_forgotPassword_emailsend"));
                            ViewData["message"] = Sitecore.Globalization.Translate.Text("Profile_forgotPassword_emailsend");
                        }
                        else
                        {
                            ModelState.AddModelError("", Sitecore.Globalization.Translate.Text("profile_forgotPassword_emailfail"));
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", Sitecore.Globalization.Translate.Text("Profile_ForgotPassword_EmailDonotExist"));
                }
            }

            return(base.Index());
        }
コード例 #2
0
        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());
        }