예제 #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(Input.Email);

                if (user == null)
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(LocalRedirect(Routes.ForgotPasswordConfirmation));
                }

                var employee = await _employeeService.EmployeeQuery().FirstOrDefaultAsync(e => e.Email == Input.Email);

                var resetPasswordUrl = "/Account/ResetPassword";
                var emailBody        = $"Dear {Input.Email} <br/> Please reset your password by";

                var code = await _userManager.GeneratePasswordResetTokenAsync(user);

                var email       = Input.Email;
                var callbackUrl = Url.Page(
                    resetPasswordUrl,
                    pageHandler: null,
                    values: new { code, email },
                    protocol: Request.Scheme);

                await _emailSender.SendUserResetPasswordAsync(Input.Email, HtmlEncoder.Default.Encode(callbackUrl));

                return(LocalRedirect(Routes.ForgotPasswordConfirmation));
            }

            return(Page());
        }