2019-01-11 14:30:04 +11:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Web;
|
2014-02-26 16:49:35 +01:00
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Configuration;
|
|
|
|
|
|
using Umbraco.Core.Logging;
|
2018-04-06 13:51:54 +10:00
|
|
|
|
using Umbraco.Core.Services;
|
2014-03-24 18:44:18 +11:00
|
|
|
|
using Umbraco.Web.Cache;
|
2017-05-30 18:13:11 +02:00
|
|
|
|
using Umbraco.Web.Composing;
|
2014-02-26 16:49:35 +01:00
|
|
|
|
using Umbraco.Web.Install.Models;
|
|
|
|
|
|
using Umbraco.Web.Security;
|
2015-12-23 13:51:16 +01:00
|
|
|
|
|
2014-02-26 16:49:35 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Install.InstallSteps
|
|
|
|
|
|
{
|
2014-03-04 19:20:36 +11:00
|
|
|
|
[InstallSetupStep(InstallationType.NewInstall | InstallationType.Upgrade,
|
2020-02-10 16:21:03 +00:00
|
|
|
|
"UmbracoVersion", 50, "Installation is complete! Get ready to be redirected to your new CMS.",
|
2014-03-05 11:34:42 +11:00
|
|
|
|
PerformsAppRestart = true)]
|
2014-02-26 16:49:35 +01:00
|
|
|
|
internal class SetUmbracoVersionStep : InstallSetupStep<object>
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly HttpContextBase _httpContext;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
private readonly InstallHelper _installHelper;
|
2018-04-06 13:51:54 +10:00
|
|
|
|
private readonly IGlobalSettings _globalSettings;
|
|
|
|
|
|
private readonly IUserService _userService;
|
|
|
|
|
|
private readonly DistributedCache _distributedCache;
|
2014-02-26 16:49:35 +01:00
|
|
|
|
|
2018-04-06 13:51:54 +10:00
|
|
|
|
public SetUmbracoVersionStep(HttpContextBase httpContext, InstallHelper installHelper, IGlobalSettings globalSettings, IUserService userService, DistributedCache distributedCache)
|
2014-02-26 16:49:35 +01:00
|
|
|
|
{
|
|
|
|
|
|
_httpContext = httpContext;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
_installHelper = installHelper;
|
2018-04-06 13:51:54 +10:00
|
|
|
|
_globalSettings = globalSettings;
|
|
|
|
|
|
_userService = userService;
|
|
|
|
|
|
_distributedCache = distributedCache;
|
2014-02-26 16:49:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-11 14:30:04 +11:00
|
|
|
|
public override Task<InstallSetupResult> ExecuteAsync(object model)
|
2014-02-26 16:49:35 +01:00
|
|
|
|
{
|
2018-04-06 13:51:54 +10:00
|
|
|
|
var security = new WebSecurity(_httpContext, _userService, _globalSettings);
|
2019-05-10 09:06:16 +02:00
|
|
|
|
|
2018-04-06 13:51:54 +10:00
|
|
|
|
if (security.IsAuthenticated() == false && _globalSettings.ConfigurationStatus.IsNullOrWhiteSpace())
|
2016-01-28 18:02:22 +01:00
|
|
|
|
{
|
2018-03-21 14:49:10 +11:00
|
|
|
|
security.PerformLogin(-1);
|
2016-01-28 18:02:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-10 09:06:16 +02:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-02-26 16:49:35 +01:00
|
|
|
|
// Update configurationStatus
|
2018-04-06 13:51:54 +10:00
|
|
|
|
_globalSettings.ConfigurationStatus = UmbracoVersion.SemanticVersion.ToSemanticString();
|
2014-02-26 16:49:35 +01:00
|
|
|
|
|
2016-09-01 19:06:08 +02:00
|
|
|
|
//reports the ended install
|
|
|
|
|
|
_installHelper.InstallStatus(true, "");
|
2014-04-07 16:08:34 +02:00
|
|
|
|
|
2019-01-11 14:30:04 +11:00
|
|
|
|
return Task.FromResult<InstallSetupResult>(null);
|
2014-02-26 16:49:35 +01:00
|
|
|
|
}
|
2014-03-04 11:16:42 +11:00
|
|
|
|
|
2014-03-05 14:30:17 +11:00
|
|
|
|
public override bool RequiresExecution(object model)
|
2014-03-04 11:16:42 +11:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2014-02-26 16:49:35 +01:00
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|