- Removed BackOfficeArea
- Injected IEmailSender
- Uses nameof instead of magic strings
- Uses GetControllerName instead of magic strings

Signed-off-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
Bjarke Berg
2020-10-22 13:37:47 +02:00
parent 785c3a34e9
commit ca8e54ffc6
7 changed files with 26 additions and 70 deletions

View File

@@ -34,7 +34,7 @@ using Microsoft.AspNetCore.Identity;
namespace Umbraco.Web.BackOffice.Controllers
{
// See
// See
// for a bigger example of this type of controller implementation in netcore:
// https://github.com/dotnet/AspNetCore.Docs/blob/2efb4554f8f659be97ee7cd5dd6143b871b330a5/aspnetcore/migration/1x-to-2x/samples/AspNetCoreDotNetCore2App/AspNetCoreDotNetCore2App/Controllers/AccountController.cs
// https://github.com/dotnet/AspNetCore.Docs/blob/ad16f5e1da6c04fa4996ee67b513f2a90fa0d712/aspnetcore/common/samples/WebApplication1/Controllers/AccountController.cs
@@ -378,18 +378,18 @@ namespace Umbraco.Web.BackOffice.Controllers
/// Used to retrieve the 2FA providers for code submission
/// </summary>
/// <returns></returns>
[SetAngularAntiForgeryTokens]
public async Task<IEnumerable<string>> Get2FAProviders()
[SetAngularAntiForgeryTokens]
public async Task<ActionResult<IEnumerable<string>>> Get2FAProviders()
{
var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
if (user == null)
{
_logger.LogWarning("Get2FAProviders :: No verified user found, returning 404");
throw new HttpResponseException(HttpStatusCode.NotFound);
return NotFound();
}
var userFactors = await _userManager.GetValidTwoFactorProvidersAsync(user);
return userFactors;
return new ObjectResult(userFactors);
}
[SetAngularAntiForgeryTokens]
@@ -470,7 +470,7 @@ namespace Umbraco.Web.BackOffice.Controllers
if (result.IsNotAllowed)
{
throw HttpResponseException.CreateValidationErrorResponse("User is not allowed");
}
}
throw HttpResponseException.CreateValidationErrorResponse("Invalid code");
}

View File

@@ -256,7 +256,7 @@ namespace Umbraco.Web.BackOffice.Controllers
{
if (redirectUrl == null)
{
redirectUrl = Url.Action("Default", "BackOffice");
redirectUrl = Url.Action(nameof(Default), this.GetControllerName());
}
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
@@ -273,7 +273,7 @@ namespace Umbraco.Web.BackOffice.Controllers
public ActionResult LinkLogin(string provider)
{
// Request a redirect to the external login provider to link a login for the current user
var redirectUrl = Url.Action("ExternalLinkLoginCallback", "BackOffice");
var redirectUrl = Url.Action(nameof(ExternalLinkLoginCallback), this.GetControllerName());
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, User.Identity.GetUserId());
return Challenge(properties, provider);
}
@@ -289,13 +289,13 @@ namespace Umbraco.Web.BackOffice.Controllers
{
//Add a flag and redirect for it to be displayed
TempData[ViewDataExtensions.TokenPasswordResetCode] = _jsonSerializer.Serialize(new ValidatePasswordResetCodeModel { UserId = userId, ResetCode = resetCode });
return RedirectToLocal(Url.Action("Default", "BackOffice"));
return RedirectToLocal(Url.Action(nameof(Default), this.GetControllerName()));
}
}
//Add error and redirect for it to be displayed
TempData[ViewDataExtensions.TokenPasswordResetCode] = new[] { _textService.Localize("login/resetCodeExpired") };
return RedirectToLocal(Url.Action("Default", "BackOffice"));
return RedirectToLocal(Url.Action(nameof(Default), this.GetControllerName()));
}
/// <summary>
@@ -311,7 +311,7 @@ namespace Umbraco.Web.BackOffice.Controllers
{
//Add error and redirect for it to be displayed
TempData[ViewDataExtensions.TokenExternalSignInError] = new[] { "An error occurred, could not get external login info" };
return RedirectToLocal(Url.Action("Default", "BackOffice"));
return RedirectToLocal(Url.Action(nameof(Default), this.GetControllerName()));
}
var user = await _userManager.FindByIdAsync(User.Identity.GetUserId());
@@ -319,7 +319,7 @@ namespace Umbraco.Web.BackOffice.Controllers
{
// ... this should really not happen
TempData[ViewDataExtensions.TokenExternalSignInError] = new[] { "Local user does not exist" };
return RedirectToLocal(Url.Action("Default", "BackOffice"));
return RedirectToLocal(Url.Action(nameof(Default), this.GetControllerName()));
}
var result2 = await _userManager.AddLoginAsync(user, loginInfo);
@@ -330,12 +330,12 @@ namespace Umbraco.Web.BackOffice.Controllers
// what this is for but we'll need to peek under the code here to figure out exactly what goes on.
//await _signInManager.UpdateExternalAuthenticationTokensAsync(loginInfo);
return RedirectToLocal(Url.Action("Default", "BackOffice"));
return RedirectToLocal(Url.Action(nameof(Default), this.GetControllerName()));
}
//Add errors and redirect for it to be displayed
TempData[ViewDataExtensions.TokenExternalSignInError] = result2.Errors;
return RedirectToLocal(Url.Action("Default", "BackOffice"));
return RedirectToLocal(Url.Action(nameof(Default), this.GetControllerName()));
}
/// <summary>