source: PostgreSqlDotnetCore/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs

main
Last change on this file was 2aea0fd, checked in by ElenaMoskova <elena.moskova99@…>, 4 months ago

init commit Elena

  • Property mode set to 100644
File size: 1.8 KB
Line 
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
5using System;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9using Microsoft.AspNetCore.Authorization;
10using Microsoft.AspNetCore.Identity;
11using Microsoft.AspNetCore.Mvc;
12using Microsoft.AspNetCore.Mvc.RazorPages;
13using Microsoft.AspNetCore.WebUtilities;
14
15namespace 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}
Note: See TracBrowser for help on using the repository browser.