Esempio n. 1
0
        public ActionResult ConfirmResetAccount(ChangePasswordModel model)
        {
            ViewBag.Token = model.ConfirmationToken;
            ViewBag.User  = model.UserName;
            string recaptchaprivatekey = BgResources.Recaptcha_PrivateKeyHttp;

            try
            {
                if (!ReCaptcha.Validate(privateKey: recaptchaprivatekey))
                {
                    ModelState.AddModelError("recaptcha", Resources.AppMessages.Error_Recaptcha);
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError("recaptcha", Resources.AppMessages.Error_Recaptcha_Key);
            }

            if (ModelState.IsValid)
            {
                if (CodeFirstSecurity.ResetPassword(model.ConfirmationToken, model.NewPassword))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false);
                    return(RedirectToRoute("Default", new { controller = "Account", action = "ResetAccountSuccesfull" }));
                }
                else
                {
                    ModelState.AddModelError("", Resources.AppMessages.Error_ResetAccount);
                }
                ViewBag.Token    = model.ConfirmationToken;
                ViewBag.UserName = model.UserName;
            }
            return(View());
        }
Esempio n. 2
0
        public ActionResult ResetPasswordNew(ResetPasswordModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            if (HttpContext.Session["passwordresettoken"] == null)
            {
                return(View("ResetPassword"));
            }

            string token = HttpContext.Session["passwordresettoken"].ToString();

            if (CodeFirstSecurity.ResetPassword(token, model.NewPassword))
            {
                return(RedirectToAction("ResetPasswordSuccess"));
            }
            else
            {
                return(RedirectToAction("ResetPassword"));
            }
        }