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

                if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(RedirectToPage("./ForgotPasswordConfirmation"));
                }

                // For more information on how to enable account confirmation and password reset please
                // visit https://go.microsoft.com/fwlink/?LinkID=532713
                var code = await _userManager.GeneratePasswordResetTokenAsync(user);

                var callbackUrl = Url.Page(
                    "/Account/ResetPassword",
                    pageHandler: null,
                    values: new { code },
                    protocol: Request.Scheme);

                await _emailSender.SendEmailAsync(
                    Input.Email,
                    "Reset Password",
                    $"Please reset your password by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                return(RedirectToPage("./ForgotPasswordConfirmation"));
            }

            return(Page());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Register(RegisterViewModel registerViewModel)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser <Guid>(registerViewModel.Email);
                user.Email = registerViewModel.Email;
                var result = await _userManager.CreateAsync(user, registerViewModel.Password);

                if (result.Succeeded)
                {
                    var emailConfirmationToken = _userManager.GenerateEmailConfirmationTokenAsync(user);
                    var callbackUrl            = Url.Page(
                        pageName: $"/Profile/ConfirmEmail",
                        pageHandler: null,
                        values: new { userid = registerViewModel.Email, code = emailConfirmationToken },
                        protocol: Request.Scheme);

                    await _applicationEmailSender.SendEmailAsync(registerViewModel.Email, "Confirm your email",
                                                                 $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    //return RedirectToAction(nameof(ProfileController.Login), "Profile");
                }
                else
                {
                    AddErrors(result);
                }
            }
            return(View(registerViewModel));
        }