implements logic to log the user in on install
This commit is contained in:
@@ -24,7 +24,7 @@ namespace Umbraco.Web.Composing.CompositionExtensions
|
||||
// composition.Register<StarterKitInstallStep>(Lifetime.Scope);
|
||||
// composition.Register<StarterKitCleanupStep>(Lifetime.Scope);
|
||||
|
||||
composition.Register<SetUmbracoVersionStep>(Lifetime.Scope);
|
||||
composition.Register<CompleteInstallStep>(Lifetime.Scope);
|
||||
|
||||
composition.Register<InstallStepCollection>();
|
||||
composition.Register<InstallHelper>();
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace Umbraco.Web.Install
|
||||
private static HttpClient _httpClient;
|
||||
private readonly DatabaseBuilder _databaseBuilder;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private readonly IConnectionStrings _connectionStrings;
|
||||
private readonly IInstallationService _installationService;
|
||||
@@ -33,7 +32,6 @@ namespace Umbraco.Web.Install
|
||||
|
||||
public InstallHelper(DatabaseBuilder databaseBuilder,
|
||||
ILogger logger,
|
||||
IGlobalSettings globalSettings,
|
||||
IUmbracoVersion umbracoVersion,
|
||||
IConnectionStrings connectionStrings,
|
||||
IInstallationService installationService,
|
||||
@@ -43,7 +41,6 @@ namespace Umbraco.Web.Install
|
||||
IJsonSerializer jsonSerializer)
|
||||
{
|
||||
_logger = logger;
|
||||
_globalSettings = globalSettings;
|
||||
_umbracoVersion = umbracoVersion;
|
||||
_databaseBuilder = databaseBuilder;
|
||||
_connectionStrings = connectionStrings ?? throw new ArgumentNullException(nameof(connectionStrings));
|
||||
@@ -59,7 +56,7 @@ namespace Umbraco.Web.Install
|
||||
return _installationType ?? (_installationType = IsBrandNewInstall ? InstallationType.NewInstall : InstallationType.Upgrade).Value;
|
||||
}
|
||||
|
||||
public async Task InstallStatus(bool isCompleted, string errorMsg)
|
||||
public async Task SetInstallStatusAsync(bool isCompleted, string errorMsg)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Umbraco.Web.Install
|
||||
// a.OfType<StarterKitInstallStep>().First(),
|
||||
// a.OfType<StarterKitCleanupStep>().First(),
|
||||
|
||||
a.OfType<SetUmbracoVersionStep>().First(),
|
||||
a.OfType<CompleteInstallStep>().First(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
{
|
||||
[InstallSetupStep(InstallationType.NewInstall | InstallationType.Upgrade,
|
||||
"UmbracoVersion", 50, "Installation is complete! Get ready to be redirected to your new CMS.",
|
||||
PerformsAppRestart = true)]
|
||||
public class CompleteInstallStep : InstallSetupStep<object>
|
||||
{
|
||||
private readonly InstallHelper _installHelper;
|
||||
|
||||
public CompleteInstallStep(InstallHelper installHelper)
|
||||
{
|
||||
_installHelper = installHelper;
|
||||
}
|
||||
|
||||
public override async Task<InstallSetupResult> ExecuteAsync(object model)
|
||||
{
|
||||
//reports the ended install
|
||||
await _installHelper.SetInstallStatusAsync(true, "");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override bool RequiresExecution(object model)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Net;
|
||||
using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
{
|
||||
[InstallSetupStep(InstallationType.NewInstall | InstallationType.Upgrade,
|
||||
"UmbracoVersion", 50, "Installation is complete! Get ready to be redirected to your new CMS.",
|
||||
PerformsAppRestart = true)]
|
||||
public class SetUmbracoVersionStep : InstallSetupStep<object>
|
||||
{
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly InstallHelper _installHelper;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
|
||||
public SetUmbracoVersionStep(IUmbracoContextAccessor umbracoContextAccessor, InstallHelper installHelper,
|
||||
IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion)
|
||||
{
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_installHelper = installHelper;
|
||||
_globalSettings = globalSettings;
|
||||
_umbracoVersion = umbracoVersion;
|
||||
}
|
||||
|
||||
public override Task<InstallSetupResult> ExecuteAsync(object model)
|
||||
{
|
||||
//TODO: This needs to be reintroduced, when users are compatible with ASP.NET Core Identity.
|
||||
// var security = _umbracoContextAccessor.GetRequiredUmbracoContext().Security;
|
||||
// if (security.IsAuthenticated() == false && _globalSettings.ConfigurationStatus.IsNullOrWhiteSpace())
|
||||
// {
|
||||
// security.PerformLogin(-1);
|
||||
// }
|
||||
//
|
||||
// if (security.IsAuthenticated())
|
||||
// {
|
||||
// // when a user is already logged in, we need to check whether it's user 'zero'
|
||||
// // which is the legacy super user from v7 - and then we need to actually log the
|
||||
// // true super user in - but before that we need to log off, else audit events
|
||||
// // will try to reference user zero and fail
|
||||
// var userIdAttempt = security.GetUserId();
|
||||
// if (userIdAttempt && userIdAttempt.Result == 0)
|
||||
// {
|
||||
// security.ClearCurrentLogin();
|
||||
// security.PerformLogin(Constants.Security.SuperUserId);
|
||||
// }
|
||||
// }
|
||||
// else if (_globalSettings.ConfigurationStatus.IsNullOrWhiteSpace())
|
||||
// {
|
||||
// // for installs, we need to log the super user in
|
||||
// security.PerformLogin(Constants.Security.SuperUserId);
|
||||
// }
|
||||
|
||||
//reports the ended install
|
||||
_installHelper.InstallStatus(true, "");
|
||||
|
||||
return Task.FromResult<InstallSetupResult>(null);
|
||||
}
|
||||
|
||||
public override bool RequiresExecution(object model)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,11 +14,13 @@ using Umbraco.Web.Common.Attributes;
|
||||
using Umbraco.Web.Common.Exceptions;
|
||||
using Umbraco.Web.Common.Filters;
|
||||
using Umbraco.Web.Common.ModelBinding;
|
||||
using Umbraco.Web.Common.Security;
|
||||
using Umbraco.Web.Install;
|
||||
using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Common.Install
|
||||
{
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
|
||||
[UmbracoApiController]
|
||||
[TypeFilter(typeof(HttpResponseExceptionFilter))]
|
||||
@@ -30,19 +32,21 @@ namespace Umbraco.Web.Common.Install
|
||||
private readonly DatabaseBuilder _databaseBuilder;
|
||||
private readonly InstallStatusTracker _installStatusTracker;
|
||||
private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime;
|
||||
private readonly BackOfficeSignInManager _backOfficeSignInManager;
|
||||
private readonly InstallStepCollection _installSteps;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IProfilingLogger _proflog;
|
||||
|
||||
public InstallApiController(DatabaseBuilder databaseBuilder, IProfilingLogger proflog,
|
||||
InstallHelper installHelper, InstallStepCollection installSteps, InstallStatusTracker installStatusTracker,
|
||||
IUmbracoApplicationLifetime umbracoApplicationLifetime)
|
||||
IUmbracoApplicationLifetime umbracoApplicationLifetime, BackOfficeSignInManager backOfficeSignInManager)
|
||||
{
|
||||
_databaseBuilder = databaseBuilder ?? throw new ArgumentNullException(nameof(databaseBuilder));
|
||||
_proflog = proflog ?? throw new ArgumentNullException(nameof(proflog));
|
||||
_installSteps = installSteps;
|
||||
_installStatusTracker = installStatusTracker;
|
||||
_umbracoApplicationLifetime = umbracoApplicationLifetime;
|
||||
_backOfficeSignInManager = backOfficeSignInManager;
|
||||
InstallHelper = installHelper;
|
||||
_logger = _proflog;
|
||||
}
|
||||
@@ -85,10 +89,17 @@ namespace Umbraco.Web.Common.Install
|
||||
return starterKits;
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult CompleteInstall()
|
||||
public async Task<ActionResult> CompleteInstall()
|
||||
{
|
||||
// log the super user in if it's a new install
|
||||
var installType = InstallHelper.GetInstallationType();
|
||||
if (installType == InstallationType.NewInstall)
|
||||
{
|
||||
var user = await _backOfficeSignInManager.UserManager.FindByIdAsync(Constants.Security.SuperUserId.ToString());
|
||||
await _backOfficeSignInManager.SignInAsync(user, false);
|
||||
}
|
||||
|
||||
_umbracoApplicationLifetime.Restart();
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace Umbraco.Web.Common.Install
|
||||
|
||||
ViewData.SetUmbracoVersion(_umbracoVersion.SemanticVersion);
|
||||
|
||||
await _installHelper.InstallStatus(false, "");
|
||||
await _installHelper.SetInstallStatusAsync(false, "");
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user