Beispiel #1
0
        public async Task <ActionResult> ResetPassword(UserResetPasswordDto userResetPasswordDto)
        {
            string email = userResetPasswordDto.Email;
            User   user  = await _userManager.FindByEmailAsync(email);

            if (user == null)
            {
                string errorMessage = $"Unable to find user with the email '{email}'.";
                _logger.LogError(errorMessage);
                return(NotFound(errorMessage));
            }

            IdentityResult resetPassResult = await _userManager.ResetPasswordAsync(user, userResetPasswordDto.ResetToken, userResetPasswordDto.Password);

            if (!resetPassResult.Succeeded)
            {
                string errorMessage = $"Failed to reset the password associated with the user '{email}'.";
                _logger.LogError(errorMessage);
                return(BadRequest(errorMessage));
            }

            string successMessage = $"Successfully reset the password for the user with the email: '{email}'.";

            _logger.LogInformation(successMessage);
            return(Ok(successMessage));
        }
Beispiel #2
0
        public async Task <IActionResult> ResetPassword([FromBody] UserResetPasswordDto userResetPassword)
        {
            try
            {
                if (userResetPassword == null)
                {
                    return(BadRequest());
                }

                var user = await userManager.FindByEmailAsync(userResetPassword.Email);

                if (user == null)
                {
                    return(NotFound());
                }
                if (!user.IsEnabled)
                {
                    throw new ApplicationException("Usuario deshabilitado.");
                }

                var result = await userManager.ResetPasswordAsync(user, userResetPassword.Token, userResetPassword.NewPassword);

                if (!result.Succeeded)
                {
                    return(BadRequest(result.Errors.ToList()));
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = ex.Message }));
            }
        }
 public ActionResult ChangePassword(UserResetPasswordModel userResetPasswordModel)
 {
     if (!ModelState.IsValid)
     {
         return(View(userResetPasswordModel));
     }
     else
     {
         UserResetPasswordDto userResetPasswordDto = new UserResetPasswordDto();
         userResetPasswordDto.EmailId  = userResetPasswordModel.EmailId;
         userResetPasswordDto.Password = userResetPasswordModel.Password;
         bool existUser = userSignUpDal.CheckValidEmailId(userResetPasswordModel.EmailId);
         if (existUser == true)
         {
             int i = userSignUpDal.ResetPasswordForUser(userResetPasswordDto);
             if (i > 0)
             {
                 ViewBag.successText = "Successfully Updated Your Password";
             }
             else
             {
                 ViewBag.failureText = "Your Password has not updated. Please try some time ";
             }
         }
         else
         {
             ViewBag.failureText = "This MailId is not Exist.";
         }
         return(View());
     }
 }
Beispiel #4
0
        public async Task ResetPasswordAsync(string userId, UserResetPasswordDto model)
        {
            var user = await _userManager.FindByIdAsync(userId);

            var result = await _userManager.ResetPasswordAsync(user, model.Token, model.NewPassword);

            if (!result.Succeeded)
            {
                throw new AppException(result.ToString());
            }
        }
        public async Task <IActionResult> ResetPassword(UserResetPasswordDto resetPasswordDto)
        {
            try
            {
                await _authService.ResetPassword(resetPasswordDto.Token, resetPasswordDto.Password);
            }
            catch (Exception ex) when(ex is SecurityTokenExpiredException || ex is EntityNotFoundException)
            {
                return(BadRequest("The new password can not be provided: token expired or does not exist"));
            }

            return(NoContent());
        }
 public int ResetPasswordForUser(UserResetPasswordDto userResetPasswordDto)
 {
     try
     {
         SqlCommand cmd = new SqlCommand("UserResetPassword", connectionRepository.con);
         cmd.Parameters.AddWithValue("@EmailId", userResetPasswordDto.EmailId);
         cmd.Parameters.AddWithValue("@Password", userResetPasswordDto.Password);
         cmd.CommandType = CommandType.StoredProcedure;
         connectionRepository.con.Open();
         int i = cmd.ExecuteNonQuery();
         connectionRepository.con.Close();
         return(i);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #7
0
        public async Task <IActionResult> ResetPassword(string token, string email
                                                        , [FromBody] UserResetPasswordDto dto)
        {
            var decodedEmail = Encoding.UTF8.GetString(Convert.FromBase64String(email));
            var user         = await _userManager.FindByEmailAsync(decodedEmail);

            if (user is null)
            {
                return(BadRequest("Invalid user"));
            }

            var decodedBytes = Convert.FromBase64String(token);
            var decodedToken = Encoding.UTF8.GetString(decodedBytes);

            var resetResult = await _userManager.ResetPasswordAsync(user, decodedToken, dto.Password);

            if (!resetResult.Succeeded)
            {
                var errors = string.Join(" ", resetResult.Errors.Select(c => $"{c.Code} - {c.Description}"));
                return(BadRequest(errors));
            }
            return(Ok());
        }
Beispiel #8
0
        public async Task <IActionResult> ResetPassword(string userId, [FromBody] UserResetPasswordDto model)
        {
            await _userService.ResetPasswordAsync(userId, model);

            return(Ok());
        }