Esempio n. 1
0
        /// <summary>
        ///     Returns true if the token is valid otherwise; false.
        /// </summary>
        /// <param name="userName">Username of the person who's password is being reset.</param>
        /// <param name="token">Token that came from the email that was sent out.</param>
        public async Task <StggResult <PasswordResetVm> > ValidateResetPasswordTokenAsync(string userName, string token)
        {
            // Find the user using the manager.
            var stggResult = new StggResult <PasswordResetVm>();
            var user       = await AppUserManager.FindByNameAsync(userName);

            // Return value

            if (!string.IsNullOrEmpty(user?.PasswordResetToken))
            {
                var passResetVm = new PasswordResetVm
                {
                    FirstName             = user.UserProfile.FirstName,
                    LastName              = user.UserProfile.LastName,
                    Email                 = user.Email,
                    Token                 = token,
                    IsValidResetPassToken = user.PasswordResetToken == token
                };

                stggResult.SetValue(passResetVm);
            }
            else
            {
                stggResult.AddError("User not found.");
            }

            return(stggResult);
        }
Esempio n. 2
0
        /// <summary>
        ///     Validates the token and reset (change) user account password.
        ///     Returns true if the password has been successfuly changed otherwise, false.
        /// </summary>
        /// <param name="passResetVm">Password reset view model that contains all the information needed to change the password.</param>
        public async Task <StggResult> ResetPasswordAsync(PasswordResetVm passResetVm)
        {
            var stggResult = new StggResult();

            if (passResetVm.Password != passResetVm.ConfirmPassword)
            {
                stggResult.AddError("Passwords do not match.");
                return(stggResult);
            }

            // Let's find the user we need more information about this user.
            var user = await AppUserManager.FindByEmailAsync(passResetVm.Email);

            // Make sure the user is not null and password token is not null;
            if (string.IsNullOrEmpty(user?.PasswordResetToken))
            {
                stggResult.AddError("User not found.");
                return(stggResult);
            }

            // Try resetting the password...
            var resetPassResult = await AppUserManager.ResetPasswordAsync(user.Id, passResetVm.Token, passResetVm.Password);

            stggResult.SetValue(resetPassResult.Succeeded);

            // Reset the token to null
            user.PasswordResetToken = null;
            AppUserManager.Update(user);

            return(stggResult);
        }
 public dynamic PasswordReset(PasswordResetVm model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(EntityState.GetErrors(ModelState)));
     }
     return(Ok(_userService.ResetPassword(model.ResetToken, model.NewPassword)
         ? "Sua senha foi alterada com sucesso."
         : "O token de redefinição de senha é inválido."));
 }
        public async Task <ActionResult> PasswordReset(PasswordResetVm passResetVm)
        {
            if (ModelState.IsValid)
            {
                // Change the account password.
                var stggResult = await Managers.UserAccountManager.ResetPasswordAsync(passResetVm);

                if (stggResult.Status == StggResultStatus.Succeeded)
                {
                    return(RedirectToAction("PasswordResetSuccess"));
                }
            }

            return(RedirectToAction("PasswordResetFailed"));
        }
Esempio n. 5
0
        public async Task <ApiResponse> ResetPassword(PasswordResetVm model)
        {
            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                throw new MyNotFoundException(ApiResponseDescription.USER_NOT_FOUND);
            }

            var codeDecodedBytes = WebEncoders.Base64UrlDecode(model.Token);
            var tokenDecoded     = Encoding.UTF8.GetString(codeDecodedBytes);

            var result = await _userManager.ResetPasswordAsync(user, tokenDecoded, model.Password);

            return(new ApiResponse(result.Succeeded));
        }
Esempio n. 6
0
 public async Task <IActionResult> ResetPassword(PasswordResetVm model) =>
 Ok(await _userService.ResetPassword(model));