public async Task <IActionResult> RequestPasswordReset(
            ResetPasswordRequestBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ApplicationUser user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                return(BadRequest());
            }

            string token = await _userManager.GeneratePasswordResetTokenAsync(user);

            string url = _options.ApiRootUrl + Url.Action(
                "ResetPassword", "Account",
                new { name = user.UserName, token });

            Message message = _messageBuilder.BuildMessage("reset-password",
                                                           new Dictionary <string, string>
            {
                ["UserName"] = user.UserName,
                ["ResetUrl"] = url
            });
            await _mailer.SendEmailAsync(user.Email, user.UserName, message);

            return(Ok());
        }
Beispiel #2
0
        public async Task <IHttpActionResult> ResetPasswordRequest(ResetPasswordRequestBindingModel model)
        {
            var currentUser = await UserManager.FindByEmailAsync(model.Email);

            if (currentUser == null)
            {
                return(BadRequest("Incorrect email"));
            }

            await UserManager.SendResetPasswordEmailAsync(currentUser.Id, model.ClientAppUrl);

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #3
0
        public async Task <IHttpActionResult> ResetPasswordRequest(ResetPasswordRequestBindingModel model)
        {
            var currentUser = await UserManager.FindByEmailAsync(model.Email);

            if (currentUser == null || currentUser.IsAnonymous)
            {
                return(BadRequest("Incorrect email"));
            }

            await UserManager.SendResetPasswordEmailAsync(currentUser.Id, model.ClientAppUrl);

            return(Ok(string.Empty));
        }
        public async Task <IActionResult> ForgetPassword([FromServices] string uiHost, [FromBody] ResetPasswordRequestBindingModel model)
        {
            await _userService.ForgotPassword($"{uiHost}/account/reset-password", model.Email);

            return(Ok());
        }