Merge remote-tracking branch 'origin/netcore/netcore' into netcore/netcore

This commit is contained in:
Bjarke Berg
2020-09-23 14:29:42 +02:00
5 changed files with 18 additions and 17 deletions

View File

@@ -4,13 +4,12 @@ using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.Extensions.Options;
using Umbraco.Core;
using Umbraco.Core.BackOffice;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Logging;
using Umbraco.Core.Mapping;
@@ -54,6 +53,7 @@ namespace Umbraco.Web.BackOffice.Controllers
private readonly IEmailSender _emailSender;
private readonly Core.Hosting.IHostingEnvironment _hostingEnvironment;
private readonly IRequestAccessor _requestAccessor;
private readonly LinkGenerator _linkGenerator;
// TODO: We need to import the logic from Umbraco.Web.Editors.AuthenticationController
// TODO: We need to review all _userManager.Raise calls since many/most should be on the usermanager or signinmanager, very few should be here
@@ -72,7 +72,8 @@ namespace Umbraco.Web.BackOffice.Controllers
IOptions<UserPasswordConfigurationSettings> passwordConfiguration,
IEmailSender emailSender,
Core.Hosting.IHostingEnvironment hostingEnvironment,
IRequestAccessor requestAccessor)
IRequestAccessor requestAccessor,
LinkGenerator linkGenerator)
{
_backofficeSecurityAccessor = backofficeSecurityAccessor;
_userManager = backOfficeUserManager;
@@ -88,6 +89,7 @@ namespace Umbraco.Web.BackOffice.Controllers
_emailSender = emailSender;
_hostingEnvironment = hostingEnvironment;
_requestAccessor = requestAccessor;
_linkGenerator = linkGenerator;
}
/// <summary>
@@ -439,11 +441,10 @@ namespace Umbraco.Web.BackOffice.Controllers
private string ConstructCallbackUrl(int userId, string code)
{
// Get an mvc helper to get the url
var urlHelper = new UrlHelper(ControllerContext);
var action = urlHelper.Action(nameof(BackOfficeController.ValidatePasswordResetCode), ControllerExtensions.GetControllerName<BackOfficeController>(),
var action = _linkGenerator.GetPathByAction(nameof(BackOfficeController.ValidatePasswordResetCode), ControllerExtensions.GetControllerName<BackOfficeController>(),
new
{
area = _globalSettings.GetUmbracoMvcArea(_hostingEnvironment),
area = Constants.Web.Mvc.BackOfficeArea,
u = userId,
r = code
});

View File

@@ -16,6 +16,7 @@ using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Hosting;
using Umbraco.Core.Logging;
using Umbraco.Core.Security;
using Umbraco.Core.Serialization;
using Umbraco.Core.Services;
using Umbraco.Core.WebAssets;
using Umbraco.Extensions;
@@ -47,6 +48,7 @@ namespace Umbraco.Web.BackOffice.Controllers
private readonly BackOfficeSignInManager _signInManager;
private readonly IBackofficeSecurityAccessor _backofficeSecurityAccessor;
private readonly ILogger _logger;
private readonly IJsonSerializer _jsonSerializer;
public BackOfficeController(
IBackOfficeUserManager userManager,
@@ -59,7 +61,8 @@ namespace Umbraco.Web.BackOffice.Controllers
AppCaches appCaches,
BackOfficeSignInManager signInManager,
IBackofficeSecurityAccessor backofficeSecurityAccessor,
ILogger logger)
ILogger logger,
IJsonSerializer jsonSerializer)
{
_userManager = userManager;
_runtimeMinifier = runtimeMinifier;
@@ -72,6 +75,7 @@ namespace Umbraco.Web.BackOffice.Controllers
_signInManager = signInManager;
_backofficeSecurityAccessor = backofficeSecurityAccessor;
_logger = logger;
_jsonSerializer = jsonSerializer;
}
[HttpGet]
@@ -249,11 +253,11 @@ namespace Umbraco.Web.BackOffice.Controllers
var user = await _userManager.FindByIdAsync(userId.ToString());
if (user != null)
{
var result = await _userManager.VerifyUserTokenAsync(user, "ResetPassword", "ResetPassword", resetCode);
var result = await _userManager.VerifyUserTokenAsync(user, "Default", "ResetPassword", resetCode);
if (result)
{
//Add a flag and redirect for it to be displayed
TempData[ViewDataExtensions.TokenPasswordResetCode] = new ValidatePasswordResetCodeModel { UserId = userId, ResetCode = resetCode };
TempData[ViewDataExtensions.TokenPasswordResetCode] = _jsonSerializer.Serialize(new ValidatePasswordResetCodeModel { UserId = userId, ResetCode = resetCode });
return RedirectToLocal(Url.Action("Default", "BackOffice"));
}
}

View File

@@ -116,8 +116,7 @@ namespace Umbraco.Extensions
sb.AppendLine();
sb.AppendLine(@"var errors = [];");
var errors = val as IEnumerable<string>;
if (errors != null)
if (val is IEnumerable<string> errors)
{
foreach (var error in errors)
{
@@ -125,13 +124,10 @@ namespace Umbraco.Extensions
}
}
var resetCodeModel = val as ValidatePasswordResetCodeModel;
sb.AppendLine(@"app.value(""resetPasswordCodeInfo"", {");
sb.AppendLine(@"errors: errors,");
sb.Append(@"resetCodeModel: ");
sb.AppendLine(JsonConvert.SerializeObject(resetCodeModel));
sb.AppendLine(val?.ToString() ?? "null");
sb.AppendLine(@"});");
return html.Raw(sb.ToString());

View File

@@ -60,7 +60,7 @@
document.angularReady = function (app) {
@await Html.AngularValueExternalLoginInfoScriptAsync(signInManager, ViewData.GetExternalSignInError())
@Html.AngularValueResetPasswordCodeInfoScript(ViewData["PasswordResetCode"])
@Html.AngularValueResetPasswordCodeInfoScript(ViewData[ViewDataExtensions.TokenPasswordResetCode])
}
</script>

View File

@@ -110,7 +110,7 @@
<script>
document.angularReady = function(app) {
@await Html.AngularValueExternalLoginInfoScriptAsync(signInManager, ViewData.GetExternalSignInError())
@Html.AngularValueResetPasswordCodeInfoScript(ViewData["PasswordResetCode"])
@Html.AngularValueResetPasswordCodeInfoScript(ViewData[ViewDataExtensions.TokenPasswordResetCode])
@await Html.AngularValueTinyMceAssetsAsync(runtimeMinifier)
app.run(["iconHelper", function (iconHelper) {