1 | // Licensed to the .NET Foundation under one or more agreements.
|
---|
2 | // The .NET Foundation licenses this file to you under the MIT license.
|
---|
3 | #nullable disable
|
---|
4 |
|
---|
5 | using System;
|
---|
6 | using System.Text;
|
---|
7 | using System.Threading.Tasks;
|
---|
8 | using Microsoft.AspNetCore.Authorization;
|
---|
9 | using Microsoft.AspNetCore.Identity;
|
---|
10 | using Microsoft.AspNetCore.Identity.UI.Services;
|
---|
11 | using Microsoft.AspNetCore.Mvc;
|
---|
12 | using Microsoft.AspNetCore.Mvc.RazorPages;
|
---|
13 | using Microsoft.AspNetCore.WebUtilities;
|
---|
14 |
|
---|
15 | namespace PostgreSqlDotnetCore.Areas.Identity.Pages.Account
|
---|
16 | {
|
---|
17 | [AllowAnonymous]
|
---|
18 | public class RegisterConfirmationModel : PageModel
|
---|
19 | {
|
---|
20 | private readonly UserManager<IdentityUser> _userManager;
|
---|
21 | private readonly IEmailSender _sender;
|
---|
22 |
|
---|
23 | public RegisterConfirmationModel(UserManager<IdentityUser> userManager, IEmailSender sender)
|
---|
24 | {
|
---|
25 | _userManager = userManager;
|
---|
26 | _sender = sender;
|
---|
27 | }
|
---|
28 |
|
---|
29 | /// <summary>
|
---|
30 | /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
|
---|
31 | /// directly from your code. This API may change or be removed in future releases.
|
---|
32 | /// </summary>
|
---|
33 | public string Email { get; set; }
|
---|
34 |
|
---|
35 | /// <summary>
|
---|
36 | /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
|
---|
37 | /// directly from your code. This API may change or be removed in future releases.
|
---|
38 | /// </summary>
|
---|
39 | public bool DisplayConfirmAccountLink { get; set; }
|
---|
40 |
|
---|
41 | /// <summary>
|
---|
42 | /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
|
---|
43 | /// directly from your code. This API may change or be removed in future releases.
|
---|
44 | /// </summary>
|
---|
45 | public string EmailConfirmationUrl { get; set; }
|
---|
46 |
|
---|
47 | public async Task<IActionResult> OnGetAsync(string email, string returnUrl = null)
|
---|
48 | {
|
---|
49 | if (email == null)
|
---|
50 | {
|
---|
51 | return RedirectToPage("/Index");
|
---|
52 | }
|
---|
53 | returnUrl = returnUrl ?? Url.Content("~/");
|
---|
54 |
|
---|
55 | var user = await _userManager.FindByEmailAsync(email);
|
---|
56 | if (user == null)
|
---|
57 | {
|
---|
58 | return NotFound($"Unable to load user with email '{email}'.");
|
---|
59 | }
|
---|
60 |
|
---|
61 | Email = email;
|
---|
62 | // Once you add a real email sender, you should remove this code that lets you confirm the account
|
---|
63 | DisplayConfirmAccountLink = true;
|
---|
64 | if (DisplayConfirmAccountLink)
|
---|
65 | {
|
---|
66 | var userId = await _userManager.GetUserIdAsync(user);
|
---|
67 | var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
---|
68 | code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
|
---|
69 | EmailConfirmationUrl = Url.Page(
|
---|
70 | "/Account/ConfirmEmail",
|
---|
71 | pageHandler: null,
|
---|
72 | values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl },
|
---|
73 | protocol: Request.Scheme);
|
---|
74 | }
|
---|
75 |
|
---|
76 | return Page();
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|