diff --git a/src/WebRazorPages/Pages/Account/ConfirmEmail.cshtml b/src/WebRazorPages/Pages/Account/ConfirmEmail.cshtml new file mode 100644 index 0000000..5236616 --- /dev/null +++ b/src/WebRazorPages/Pages/Account/ConfirmEmail.cshtml @@ -0,0 +1,13 @@ + +@page +@model ConfirmEmailModel +@{ + ViewData["Title"] = "Confirm email"; +} + +

@ViewData["Title"]

+
+

+ Thank you for confirming your email. +

+
\ No newline at end of file diff --git a/src/WebRazorPages/Pages/Account/ConfirmEmail.cshtml.cs b/src/WebRazorPages/Pages/Account/ConfirmEmail.cshtml.cs new file mode 100644 index 0000000..9164e35 --- /dev/null +++ b/src/WebRazorPages/Pages/Account/ConfirmEmail.cshtml.cs @@ -0,0 +1,41 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.eShopWeb.Infrastructure.Identity; + +namespace Microsoft.eShopWeb.RazorPages.Pages.Account +{ + public class ConfirmEmailModel : PageModel + { + private readonly UserManager _userManager; + + public ConfirmEmailModel(UserManager userManager) + { + _userManager = userManager; + } + + public async Task OnGetAsync(string userId, string code) + { + if (userId == null || code == null) + { + return RedirectToPage("/Index"); + } + + var user = await _userManager.FindByIdAsync(userId); + if (user == null) + { + throw new ApplicationException($"Unable to load user with ID '{userId}'."); + } + + var result = await _userManager.ConfirmEmailAsync(user, code); + if (!result.Succeeded) + { + throw new ApplicationException($"Error confirming email for user with ID '{userId}':"); + } + + return Page(); + } + } +} \ No newline at end of file