Example #1
0
        public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            ApplicationUserViewModel user = await _applicationUserService.FindByEmailAsync(model.Email);

            if (user == null || !await _applicationUserService.IsEmailConfirmedAsync(user))
            {
                return(NotFound(404));
            }

            string code1 = await _applicationUserService.GeneratePasswordResetTokenAsync(user);

            string callbackUrl = Url.RouteUrl("ResetPassword", new { userId = user.Id, code = code1 });
            string linkString  = $"<a href = \"{callbackUrl} \"> reset </a>";
            string messageBody = $"{COMPLITE} {linkString}";

            new EmailService().SendEmail(model.Email, MESSAGERESET, messageBody);

            return(Ok(200));
        }