Merge branch 'pr_2463' into dev-v7

This commit is contained in:
Sebastiaan Janssen
2018-07-14 18:47:42 +02:00
5 changed files with 31 additions and 5 deletions

View File

@@ -120,13 +120,22 @@ namespace Umbraco.Core.Models.Identity
set { _tracker.SetPropertyValueAndDetectChanges(value, ref _userName, Ps.Value.UserNameSelector); }
}
/// <summary>
/// LastPasswordChangeDateUtc so we can track changes to it
/// </summary>
public override DateTime? LastPasswordChangeDateUtc
{
get { return _lastPasswordChangeDateUtc; }
set { _tracker.SetPropertyValueAndDetectChanges(value, ref _lastPasswordChangeDateUtc, Ps.Value.LastPasswordChangeDateUtcSelector); }
}
/// <summary>
/// Override LastLoginDateUtc so we can track changes to it
/// </summary>
public override DateTime? LastLoginDateUtc
{
get { return _lastLoginDateUtc; }
set { _tracker.SetPropertyValueAndDetectChanges(value, ref _lastLoginDateUtc, Ps.Value.LastLoginDateUtcSelector); }
set { _tracker.SetPropertyValueAndDetectChanges(value, ref _lastLoginDateUtc, Ps.Value.LastLoginDateUtcSelector); }
}
/// <summary>
@@ -392,6 +401,7 @@ namespace Umbraco.Core.Models.Identity
public readonly PropertyInfo EmailSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, string>(x => x.Email);
public readonly PropertyInfo UserNameSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, string>(x => x.UserName);
public readonly PropertyInfo LastLoginDateUtcSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, DateTime?>(x => x.LastLoginDateUtc);
public readonly PropertyInfo LastPasswordChangeDateUtcSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, DateTime?>(x => x.LastPasswordChangeDateUtc);
public readonly PropertyInfo EmailConfirmedSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, bool>(x => x.EmailConfirmed);
public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, string>(x => x.Name);
public readonly PropertyInfo AccessFailedCountSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, int>(x => x.AccessFailedCount);
@@ -419,6 +429,7 @@ namespace Umbraco.Core.Models.Identity
private int _id;
private bool _hasIdentity = false;
private DateTime? _lastLoginDateUtc;
private DateTime? _lastPasswordChangeDateUtc;
private bool _emailConfirmed;
private string _name;
private int _accessFailedCount;
@@ -449,4 +460,4 @@ namespace Umbraco.Core.Models.Identity
}
}
}

View File

@@ -19,6 +19,7 @@ namespace Umbraco.Core.Models.Identity
})
.ConstructUsing(user => new BackOfficeIdentityUser(user.Id, user.Groups))
.ForMember(user => user.LastLoginDateUtc, expression => expression.MapFrom(user => user.LastLoginDate.ToUniversalTime()))
.ForMember(user => user.LastPasswordChangeDateUtc, expression => expression.MapFrom(user => user.LastPasswordChangeDate.ToUniversalTime()))
.ForMember(user => user.Email, expression => expression.MapFrom(user => user.Email))
.ForMember(user => user.EmailConfirmed, expression => expression.MapFrom(user => user.EmailConfirmedDate.HasValue))
.ForMember(user => user.Id, expression => expression.MapFrom(user => user.Id))

View File

@@ -83,6 +83,12 @@ namespace Umbraco.Core.Models.Identity
/// </summary>
public virtual DateTime? LockoutEndDateUtc { get; set; }
/// <summary>
/// DateTime in UTC when the password was last changed.
///
/// </summary>
public virtual DateTime? LastPasswordChangeDateUtc { get; set; }
/// <summary>
/// Is lockout enabled for this user
///
@@ -127,4 +133,4 @@ namespace Umbraco.Core.Models.Identity
}
}
}

View File

@@ -484,6 +484,7 @@ namespace Umbraco.Core.Security
/// </remarks>
protected override async Task<IdentityResult> UpdatePassword(IUserPasswordStore<T, int> passwordStore, T user, string newPassword)
{
user.LastPasswordChangeDateUtc = DateTime.UtcNow;
var userAwarePasswordHasher = PasswordHasher as IUserAwarePasswordHasher<BackOfficeIdentityUser, int>;
if (userAwarePasswordHasher == null)
return await base.UpdatePassword(passwordStore, user, newPassword);

View File

@@ -622,7 +622,7 @@ namespace Umbraco.Core.Security
private bool UpdateMemberProperties(IUser user, BackOfficeIdentityUser identityUser)
{
var anythingChanged = false;
//don't assign anything if nothing has changed as this will trigger the track changes of the model
if (identityUser.IsPropertyDirty("LastLoginDateUtc")
@@ -632,6 +632,13 @@ namespace Umbraco.Core.Security
anythingChanged = true;
user.LastLoginDate = identityUser.LastLoginDateUtc.Value.ToLocalTime();
}
if (identityUser.IsPropertyDirty("LastPasswordChangeDateUtc")
|| (user.LastPasswordChangeDate != default(DateTime) && identityUser.LastPasswordChangeDateUtc.HasValue == false)
|| identityUser.LastPasswordChangeDateUtc.HasValue && user.LastPasswordChangeDate.ToUniversalTime() != identityUser.LastPasswordChangeDateUtc.Value)
{
anythingChanged = true;
user.LastPasswordChangeDate = identityUser.LastPasswordChangeDateUtc.Value.ToLocalTime();
}
if (identityUser.IsPropertyDirty("EmailConfirmed")
|| (user.EmailConfirmedDate.HasValue && user.EmailConfirmedDate.Value != default(DateTime) && identityUser.EmailConfirmed == false)
|| ((user.EmailConfirmedDate.HasValue == false || user.EmailConfirmedDate.Value == default(DateTime)) && identityUser.EmailConfirmed))
@@ -765,4 +772,4 @@ namespace Umbraco.Core.Security
return Task.FromResult(false);
}
}
}
}