Exemplo n.º 1
0
        public async Task <ApiResponse <ForgotPasswordUserVM> > ForgotPasswordAsync(ForgotPasswordUserVM forgotPasswordUser)
        {
            try
            {
                var user = await _userManager.FindByEmailAsync(forgotPasswordUser.Email);

                if (user == null)
                {
                    return(new ApiResponse <ForgotPasswordUserVM>(StatusCodeType.Status401Unauthorized, "Email not found, please Register first", new[] { new KeyValuePair <string, string>("Email", "There is no User with this Email") }.ToLookup()));
                }
                if (!await _userManager.IsEmailConfirmedAsync(user))
                {
                    return(new ApiResponse <ForgotPasswordUserVM>(StatusCodeType.Status401Unauthorized, "Please Confirm your account first", new[] { new KeyValuePair <string, string>("Email", "Your account hasn't been confirmed yet") }.ToLookup()));
                }

                var code = (await _userManager.GeneratePasswordResetTokenAsync(user)).UTF8ToBase64SafeUrl();
                var sendResetEmailResponse = await _emailSender.SendPasswordResetEmailAsync(forgotPasswordUser.Email, code, forgotPasswordUser.ReturnUrl);

                if (sendResetEmailResponse.IsError)
                {
                    return(new ApiResponse <ForgotPasswordUserVM>(StatusCodeType.Status500InternalServerError, "Can't send Password Reset email. Try again later.", null, null, sendResetEmailResponse.ResponseException));
                }

                return(new ApiResponse <ForgotPasswordUserVM>(StatusCodeType.Status201Created, "Reset Password Email has been sent succesfully", null, forgotPasswordUser));
            }
            catch (Exception ex)
            {
                return(new ApiResponse <ForgotPasswordUserVM>(StatusCodeType.Status500InternalServerError, "Sending Reset Password Email Failed", null, null, ex));
            }
        }
Exemplo n.º 2
0
 public async Task <ApiResponse <ForgotPasswordUserVM> > ForgotPasswordAsync(ForgotPasswordUserVM forgotPasswordUser)
 {
     try
     {
         return(await _httpClient.PostJTokenAsync <ApiResponse <ForgotPasswordUserVM> >("api/account/forgotpassword", forgotPasswordUser));
     }
     catch (Exception ex)
     {
         return(new ApiResponse <ForgotPasswordUserVM>(StatusCodeType.Status500InternalServerError, "Api threw an Exception", null, null, ex));
     }
 }