Beispiel #1
0
        public async Task <IActionResult> ResetPassword([FromBody] ResetPasswordModel user)
        {
            bool isValid = true;

            if (string.IsNullOrWhiteSpace(user.EmailAddress) ||
                string.IsNullOrWhiteSpace(user.OldPassword) ||
                string.IsNullOrWhiteSpace(user.NewPassword) ||
                string.IsNullOrWhiteSpace(user.ConfirmNewPassword))
            {
                ErrorMessage = "Please fill all required fields.";
                return(BadRequest(ErrorMessage));
            }
            if (!_emailValidator.CheckRule(user.EmailAddress))
            {
                ErrorMessage = "Email invalid format.";
                return(BadRequest(ErrorMessage));
            }
            if (!_passwordValidator.CheckRule(user.NewPassword))
            {
                ErrorMessage += "*Password invalid format." +
                                " It must contains 8 characters, at least one letter and one digit.";
                isValid = false;
            }
            if (!user.NewPassword.Equals(user.ConfirmNewPassword))
            {
                ErrorMessage += "*Password mismatch.";
                isValid       = false;
            }
            try
            {
                if (isValid)
                {
                    await _userService.ResetPasswordAsync(user);

                    return(Ok("Password has been changed."));
                }
                else
                {
                    return(BadRequest(ErrorMessage));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }