From 886615e7403246a4b2333ecd21e94080a9f6e940 Mon Sep 17 00:00:00 2001 From: beam Date: Thu, 18 Oct 2018 01:25:46 +0700 Subject: [PATCH] fix issue #108 --- .../Pages/Account/ConfirmEmail.cshtml | 13 ++++++ .../Pages/Account/ConfirmEmail.cshtml.cs | 41 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/WebRazorPages/Pages/Account/ConfirmEmail.cshtml create mode 100644 src/WebRazorPages/Pages/Account/ConfirmEmail.cshtml.cs 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