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

@ViewData["Title"]

+
+

+ Thank you for confirming your email. +

+
diff --git a/src/Web/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs b/src/Web/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs new file mode 100644 index 0000000..b113768 --- /dev/null +++ b/src/Web/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.eShopWeb.Infrastructure.Identity; + +namespace Microsoft.eShopWeb.Web.Areas.Identity.Pages.Account +{ + [AllowAnonymous] + 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) + { + return NotFound($"Unable to load user with ID '{userId}'."); + } + + var result = await _userManager.ConfirmEmailAsync(user, code); + if (!result.Succeeded) + { + throw new InvalidOperationException($"Error confirming email for user with ID '{userId}':"); + } + + return Page(); + } + } +} diff --git a/src/Web/Extensions/UrlHelperExtensions.cs b/src/Web/Extensions/UrlHelperExtensions.cs index c5c940b..6edc697 100644 --- a/src/Web/Extensions/UrlHelperExtensions.cs +++ b/src/Web/Extensions/UrlHelperExtensions.cs @@ -1,14 +1,12 @@ -using Microsoft.eShopWeb.Web.Controllers; - -namespace Microsoft.AspNetCore.Mvc +namespace Microsoft.AspNetCore.Mvc { public static class UrlHelperExtensions { public static string EmailConfirmationLink(this IUrlHelper urlHelper, string userId, string code, string scheme) { return urlHelper.Action( - action: nameof(AccountController.ConfirmEmail), - controller: "Account", + action: "GET", + controller: "ConfirmEmail", values: new { userId, code }, protocol: scheme); }