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 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());
        }
        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);
        }