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.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Threading.Tasks;
|
---|
9 | using Microsoft.AspNetCore.Authorization;
|
---|
10 | using Microsoft.AspNetCore.Identity;
|
---|
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 | public class ConfirmEmailModel : PageModel
|
---|
18 | {
|
---|
19 | private readonly UserManager<IdentityUser> _userManager;
|
---|
20 |
|
---|
21 | public ConfirmEmailModel(UserManager<IdentityUser> userManager)
|
---|
22 | {
|
---|
23 | _userManager = userManager;
|
---|
24 | }
|
---|
25 |
|
---|
26 | /// <summary>
|
---|
27 | /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
|
---|
28 | /// directly from your code. This API may change or be removed in future releases.
|
---|
29 | /// </summary>
|
---|
30 | [TempData]
|
---|
31 | public string StatusMessage { get; set; }
|
---|
32 | public async Task<IActionResult> OnGetAsync(string userId, string code)
|
---|
33 | {
|
---|
34 | if (userId == null || code == null)
|
---|
35 | {
|
---|
36 | return RedirectToPage("/Index");
|
---|
37 | }
|
---|
38 |
|
---|
39 | var user = await _userManager.FindByIdAsync(userId);
|
---|
40 | if (user == null)
|
---|
41 | {
|
---|
42 | return NotFound($"Unable to load user with ID '{userId}'.");
|
---|
43 | }
|
---|
44 |
|
---|
45 | code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
|
---|
46 | var result = await _userManager.ConfirmEmailAsync(user, code);
|
---|
47 | StatusMessage = result.Succeeded ? "Thank you for confirming your email." : "Error confirming your email.";
|
---|
48 | return Page();
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|