Ejemplo n.º 1
0
        public ActionResult SignInSitecore(SignIn signIn)
        {
            //Validate if the fields are populated
            if (string.IsNullOrEmpty(signIn.txtEmail) || string.IsNullOrEmpty(signIn.txtPassword))
            {
                var context = new SitecoreContext();
                var model   = context.GetCurrentItem <SignIn>();
                Response.Redirect(UrlMapper.Map(model.SiteSettings.SignInHelpPage.Url));
            }

            //Remove invalid characters from the Email
            if (signIn.txtEmail.Contains(","))
            {
                Session["SignInUiError"] = Sitecore.Globalization.Translate.Text("Profile_AccountNotFound");
                return(base.Index());
            }

            ActionResult result         = null;
            var          profileservice = new ProfileService();

            var loginResponse = profileservice.LoginUser(signIn.txtEmail, signIn.txtPassword, null, null, null, null);

            if (loginResponse.IsSuccessfull)
            {
                var context = new SitecoreContext();
                var model   = context.GetCurrentItem <SignIn>();
                //TODO: Enable Below code once owner object is completely ready
                //RedirectRegistrationConfirmation(UrlMapper.Map(registrationInfo.PostbackSuccessPageUrl));
                Response.Redirect(UrlMapper.Map(model.SiteSettings.SignInWaitPage.Url));
            }
            else
            {
                var context = new SitecoreContext();
                var model   = context.GetCurrentItem <SignIn>();
                if (loginResponse.errorCode == SignInResponse.errors.InvalidPassword)
                {
                    //Session["PasswordRuleFail"] = "true";  //TODO find another way to get this working
                    Response.Redirect("/mybluegreen/my-account/Change-Password?PasswordRuleFail=true", true);  //TODO define const for URL
                }
                SitecoreProfileService scProfileService = new SitecoreProfileService();
                var scUserName = scProfileService.GetUserByEmail(signIn.txtEmail);
                if (loginResponse.errorCode == SignInResponse.errors.LockedAccount && !scProfileService.CheckForDisableAccountUpdates(scUserName))
                {
                    Session["SignInUiError"] = Sitecore.Globalization.Translate.Text("Profile_AccountLocked");
                }
                else
                {
                    Session["SignInUiError"] = Sitecore.Globalization.Translate.Text("Profile_AccountNotFound");
                }
                result = base.Index();
            }

            return(result);
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
0
        public ActionResult ResetPasswordProcess(ResetPassword resetPassword)
        {
            bool isValid = true;

            if (resetPassword.txtNewPassword.Contains(" "))
            {
                if (ModelState.IsValid)
                {
                    ModelState.AddModelError("", Sitecore.Globalization.Translate.Text("Profile_PasswordInvalid"));
                }
                isValid = false;
            }

            if (ModelState.IsValid && isValid)
            {
                SitecoreProfileService scProfileService = new SitecoreProfileService();
                var            scUserName = scProfileService.GetUserByEmail(resetPassword.email);
                MembershipUser user       = scProfileService.GetMembershipUser(scUserName);
                if (user != null)
                {
                    user.UnlockUser();

                    scProfileService.ResetFlagPasswordLockedEmail(scUserName);
                    ProfileService profileService = new ProfileService();
                    if (!user.ChangePassword(user.ResetPassword(), resetPassword.txtNewPassword))
                    {
                        ModelState.AddModelError("", "ERROR");  //todo add error
                        return(base.Index());
                    }
                    else
                    {
                        EmailManager.UpdatePassword(scUserName, resetPassword.email);

                        var response = profileService.LoginUser(resetPassword.email, resetPassword.txtNewPassword, null, null, null, null);
                        if (response.IsSuccessfull)
                        {
                            var context = new SitecoreContext();
                            var model   = context.GetCurrentItem <SignIn>();
                            profileService.SetLoginWaitContext(resetPassword.email, null, null, null);
                            Response.Redirect(UrlMapper.Map(model.SiteSettings.SignInWaitPage.Url));
                        }
                        else
                        {
                            ModelState.AddModelError("", "ERROR");  //todo add error
                            return(base.Index());
                        }
                    }
                }
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors)
                             .Where(y => y.Count > 0)
                             .ToList();

                Session["ResetPasswordError"] = errors;

                Response.Redirect(string.Format("/reset-password?email={0}&resetid={1}", resetPassword.email, resetPassword.resetid));
            }
            return(null);
        }
Ejemplo n.º 5
0
        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));
        }