Fixes new installation user login

This commit is contained in:
Shannon
2017-11-09 23:05:56 +11:00
parent fe2e689865
commit 2dc11f6fa1
4 changed files with 64 additions and 46 deletions
+47
View File
@@ -1,6 +1,7 @@
using System;
using System.Configuration;
using System.Threading;
using Semver;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.ObjectResolution;
@@ -341,6 +342,52 @@ namespace Umbraco.Core
}
}
/// <summary>
/// Gets the Current Version of the Umbraco Site before an upgrade
/// by using the last/most recent Umbraco Migration that has been run
/// </summary>
/// <returns>A SemVersion of the latest Umbraco DB Migration run</returns>
/// <remarks>
/// NOTE: This existed in the InstallHelper previously but should really be here so it can be re-used if necessary
/// </remarks>
internal SemVersion CurrentVersion()
{
//Set a default version of 0.0.0
var version = new SemVersion(0);
//If we have a db context available, if we don't then we are not installed anyways
if (DatabaseContext.IsDatabaseConfigured && DatabaseContext.CanConnect)
version = DatabaseContext.ValidateDatabaseSchema().DetermineInstalledVersionByMigrations(Services.MigrationEntryService);
if (version != new SemVersion(0))
return version;
// If we aren't able to get a result from the umbracoMigrations table then use the version in web.config, if it's available
if (string.IsNullOrWhiteSpace(GlobalSettings.ConfigurationStatus))
return version;
var configuredVersion = GlobalSettings.ConfigurationStatus;
string currentComment = null;
var current = configuredVersion.Split('-');
if (current.Length > 1)
currentComment = current[1];
Version currentVersion;
if (Version.TryParse(current[0], out currentVersion))
{
version = new SemVersion(
currentVersion.Major,
currentVersion.Minor,
currentVersion.Build,
string.IsNullOrWhiteSpace(currentComment) ? null : currentComment,
currentVersion.Revision > 0 ? currentVersion.Revision.ToString() : null);
}
return version;
}
private void AssertIsNotReady()
{
if (this.IsReady)
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Semver;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models.Identity;
@@ -31,6 +32,8 @@ namespace Umbraco.Core.Security
_appCtx = appCtx;
}
private static readonly SemVersion MinUmbracoVersionSupportingLoginSessions = new SemVersion(7, 8);
public override void ResponseSignIn(CookieResponseSignInContext context)
{
var backOfficeIdentity = context.Identity as UmbracoBackOfficeIdentity;
@@ -39,7 +42,10 @@ namespace Umbraco.Core.Security
//generate a session id and assign it
//create a session token - if we are configured and not in an upgrade state then use the db, otherwise just generate one
var session = _appCtx.IsConfigured && _appCtx.IsUpgrading == false
//NOTE - special check because when we are upgrading to 7.8 we cannot create a session since the db isn't ready and we'll get exceptions
var canAcquireSession = _appCtx.IsUpgrading == false || _appCtx.CurrentVersion() >= MinUmbracoVersionSupportingLoginSessions;
var session = canAcquireSession
? _appCtx.Services.UserService.CreateLoginSession((int)backOfficeIdentity.Id, context.OwinContext.GetCurrentRequestIpAddress())
: Guid.NewGuid();
+2 -2
View File
@@ -8,6 +8,7 @@ using System.Net.Http;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.UI;
using Semver;
using umbraco.BusinessLogic;
using Umbraco.Core;
using Umbraco.Core.Configuration;
@@ -30,7 +31,6 @@ namespace Umbraco.Web.Install
_umbContext = umbContext;
}
/// <summary>
/// Get the installer steps
/// </summary>
@@ -43,7 +43,7 @@ namespace Umbraco.Web.Install
return new List<InstallSetupStep>
{
new NewInstallStep(_umbContext.HttpContext, _umbContext.Application),
new UpgradeStep(),
new UpgradeStep(_umbContext.Application),
new FilePermissionsStep(),
new MajorVersion7UpgradeReport(_umbContext.Application),
new Version73FileCleanup(_umbContext.HttpContext, _umbContext.Application.ProfilingLogger.Logger),
@@ -14,6 +14,13 @@ namespace Umbraco.Web.Install.InstallSteps
"Upgrade", "upgrade", 1, "Upgrading Umbraco to the latest and greatest version.")]
internal class UpgradeStep : InstallSetupStep<object>
{
private readonly ApplicationContext _appCtx;
public UpgradeStep(ApplicationContext appCtx)
{
_appCtx = appCtx;
}
public override bool RequiresExecution(object model)
{
return true;
@@ -28,7 +35,7 @@ namespace Umbraco.Web.Install.InstallSteps
{
get
{
var currentVersion = CurrentVersion().GetVersion(3).ToString();
var currentVersion = _appCtx.CurrentVersion().GetVersion(3).ToString();
var newVersion = UmbracoVersion.Current.ToString();
var reportUrl = string.Format("https://our.umbraco.org/contribute/releases/compare?from={0}&to={1}&notes=1", currentVersion, newVersion);
@@ -42,47 +49,5 @@ namespace Umbraco.Web.Install.InstallSteps
}
}
/// <summary>
/// Gets the Current Version of the Umbraco Site before an upgrade
/// by using the last/most recent Umbraco Migration that has been run
/// </summary>
/// <returns>A SemVersion of the latest Umbraco DB Migration run</returns>
private SemVersion CurrentVersion()
{
//Set a default version of 0.0.0
var version = new SemVersion(0);
//If we have a db context available, if we don't then we are not installed anyways
if (ApplicationContext.Current.DatabaseContext.IsDatabaseConfigured && ApplicationContext.Current.DatabaseContext.CanConnect)
version = ApplicationContext.Current.DatabaseContext.ValidateDatabaseSchema().DetermineInstalledVersionByMigrations(ApplicationContext.Current.Services.MigrationEntryService);
if (version != new SemVersion(0))
return version;
// If we aren't able to get a result from the umbracoMigrations table then use the version in web.config, if it's available
if (string.IsNullOrWhiteSpace(GlobalSettings.ConfigurationStatus))
return version;
var configuredVersion = GlobalSettings.ConfigurationStatus;
string currentComment = null;
var current = configuredVersion.Split('-');
if (current.Length > 1)
currentComment = current[1];
Version currentVersion;
if (Version.TryParse(current[0], out currentVersion))
{
version = new SemVersion(
currentVersion.Major,
currentVersion.Minor,
currentVersion.Build,
string.IsNullOrWhiteSpace(currentComment) ? null : currentComment,
currentVersion.Revision > 0 ? currentVersion.Revision.ToString() : null);
}
return version;
}
}
}