Adding confirmEmail scaffolding
- Also updating the UrlHelpExtensions to not have a dependency on the AccountController
This commit is contained in:
12
src/Web/Areas/Identity/Pages/Account/ConfirmEmail.cshtml
Normal file
12
src/Web/Areas/Identity/Pages/Account/ConfirmEmail.cshtml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
@page
|
||||||
|
@model ConfirmEmailModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Confirm email";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>@ViewData["Title"]</h2>
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
Thank you for confirming your email.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
45
src/Web/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs
Normal file
45
src/Web/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs
Normal file
@@ -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<ApplicationUser> _userManager;
|
||||||
|
|
||||||
|
public ConfirmEmailModel(UserManager<ApplicationUser> userManager)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
using Microsoft.eShopWeb.Web.Controllers;
|
namespace Microsoft.AspNetCore.Mvc
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc
|
|
||||||
{
|
{
|
||||||
public static class UrlHelperExtensions
|
public static class UrlHelperExtensions
|
||||||
{
|
{
|
||||||
public static string EmailConfirmationLink(this IUrlHelper urlHelper, string userId, string code, string scheme)
|
public static string EmailConfirmationLink(this IUrlHelper urlHelper, string userId, string code, string scheme)
|
||||||
{
|
{
|
||||||
return urlHelper.Action(
|
return urlHelper.Action(
|
||||||
action: nameof(AccountController.ConfirmEmail),
|
action: "GET",
|
||||||
controller: "Account",
|
controller: "ConfirmEmail",
|
||||||
values: new { userId, code },
|
values: new { userId, code },
|
||||||
protocol: scheme);
|
protocol: scheme);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user