public string Redeem(string token, string emailAddress, string password)
        {
            var userToken = _context.UserTokens.FirstOrDefault(x => x.Token.Equals(token, StringComparison.OrdinalIgnoreCase));

            if (userToken == null)
            {
                return("Invalid Token. Please Request Reset Password Token Again!");
            }

            if (!userToken.User.EmailAddress.Equals(emailAddress, StringComparison.OrdinalIgnoreCase))
            {
                return("Invalid Token. This Token does not match the Email Address you entered!");
            }

            if (userToken.DateRedeemed.HasValue)
            {
                return("Invalid Token. This Token has already been used.");
            }

            _registartionService.ChangePassword(userToken.User.UserId, password);

            userToken.DateRedeemed = DateTime.Now;
            _context.SaveChanges();

            return(string.Empty);
        }
Esempio n. 2
0
        public ActionResult EditPassword(PasswordViewModel model)
        {
            if (ModelState.IsValid && !model.NewPassword.Equals(model.ConfirmPassword, StringComparison.OrdinalIgnoreCase))
            {
                ModelState.AddModelError("NewPasswordMismatch", "Your new password and confirm password do not match...");
            }

            if (!ModelState.IsValid)
            {
                model.NewPassword     = string.Empty;
                model.ConfirmPassword = string.Empty;

                return(View("_Password", model));
            }

            _registrationService.ChangePassword(UserHelper.UserId.Value, model.NewPassword);

            var websiteAddress = $@"http://{System.Web.HttpContext.Current.Request.Url.Authority}";

            EmailHelper.Send(new List <string> {
                UserHelper.EmailAddress
            }, "Account Notice", $"<p>Hello {UserHelper.FullName}</p><p>We just wanted to let you know that your password was changed at {websiteAddress}. If you didn't change your password, please let us know");

            return(Content("Refresh"));
        }
 public void ChangePassword(string newPassword)
 {
     registrationService.ChangePassword(userName, password, newPassword);
     password = newPassword;
 }