Skip to content

Commit

Permalink
Merge pull request dotnet-architecture#268 from dotnet-architecture/r…
Browse files Browse the repository at this point in the history
…emove-account-controller

Remove account controller
  • Loading branch information
efleming18 authored Jun 22, 2019
2 parents 86f65e3 + b3d8558 commit 4706682
Showing 5 changed files with 61 additions and 247 deletions.
12 changes: 12 additions & 0 deletions src/Web/Areas/Identity/Pages/Account/ConfirmEmail.cshtml
Original file line number Diff line number Diff line change
@@ -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 changes: 45 additions & 0 deletions src/Web/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
232 changes: 0 additions & 232 deletions src/Web/Controllers/AccountController.cs

This file was deleted.

17 changes: 3 additions & 14 deletions src/Web/Extensions/UrlHelperExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,23 +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",
values: new { userId, code },
protocol: scheme);
}

public static string ResetPasswordCallbackLink(this IUrlHelper urlHelper, string userId, string code, string scheme)
{
return urlHelper.Action(
action: nameof(AccountController.ResetPassword),
controller: "Account",
action: "GET",
controller: "ConfirmEmail",
values: new { userId, code },
protocol: scheme);
}
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ public async Task ReturnsSuccessfulSignInOnPostWithValidCredentials()
keyValues.Add(new KeyValuePair<string, string>("__RequestVerificationToken", token));
var formContent = new FormUrlEncodedContent(keyValues);

var postResponse = await Client.PostAsync("/account/sign-in", formContent);
var postResponse = await Client.PostAsync("/identity/account/login", formContent);
Assert.Equal(HttpStatusCode.Redirect, postResponse.StatusCode);
Assert.Equal(new System.Uri("/", UriKind.Relative), postResponse.Headers.Location);
}

0 comments on commit 4706682

Please sign in to comment.