Ejemplo n.º 1
0
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            model.RecaptchaSiteKey = SiteUtil.RecaptchaSiteKey;

            if (!IsValidateReCaptcha())
            {
                ModelState.AddModelError("", "Google reCaptcha validation failed.");
                return(View(model));
            }

            if (ModelState.IsValid)
            {
                // Check password format
                if (!ValidatePassword(model.NewPassword))
                {
                    ModelState.AddModelError("Password", "The password is not correct format");
                    return(View(model));
                }

                var login = _loginRepository.GetQueryable()
                            .Where(x => x.Username == model.Email).FirstOrDefault();

                if (login == null || login.PasswordHash != model.OldPassword)
                {
                    ModelState.AddModelError("", "Your account is invalid. " +
                                             "Please contact to support team!");
                    return(View(model));
                }

                if (!login.EmailAddressAuthorized)
                {
                    ModelState.AddModelError("", "Your email has not been verified. " +
                                             "Please check your inbox email or contact to support team!");
                    return(View(model));
                }

                if (login.IsDisabled)
                {
                    ModelState.AddModelError("", "Your account is disable. " +
                                             "Please contact to support team!");
                    return(View(model));
                }

                // everything is ok. update a new password
                _signUpService.ResetPassword(login, model.NewPassword);

                return(RedirectToAction("ResetPasswordSuccess"));
            }
            else
            {
                ModelState.AddModelError("", "Something went wrong. Please contact to support team!");
            }

            return(View(model));
        }