Browse Source
Track and update user's last sign-in time
pull/24278/head
maliming
4 months ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
3 changed files with
24 additions and
1 deletions
-
modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSignInManager.cs
-
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs
-
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs
|
|
|
@ -1,4 +1,7 @@ |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Security.Claims; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Authentication; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.AspNetCore.Identity; |
|
|
|
@ -120,4 +123,11 @@ public class AbpSignInManager : SignInManager<IdentityUser> |
|
|
|
{ |
|
|
|
return await base.SignInOrTwoFactorAsync(user, isPersistent, loginProvider, bypassTwoFactor); |
|
|
|
} |
|
|
|
|
|
|
|
public override async Task SignInWithClaimsAsync(IdentityUser user, AuthenticationProperties authenticationProperties, IEnumerable<Claim> additionalClaims) |
|
|
|
{ |
|
|
|
user.SetLastSignInTime(DateTimeOffset.UtcNow); |
|
|
|
await UserManager.UpdateAsync(user); |
|
|
|
await base.SignInWithClaimsAsync(user, authenticationProperties, additionalClaims); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -127,6 +127,11 @@ public class IdentityUser : FullAuditedAggregateRoot<Guid>, IUser, IHasEntityVer |
|
|
|
/// </summary>
|
|
|
|
public virtual DateTimeOffset? LastPasswordChangeTime { get; protected set; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the last sign-in time for the user.
|
|
|
|
/// </summary>
|
|
|
|
public virtual DateTimeOffset? LastSignInTime { get; protected set; } |
|
|
|
|
|
|
|
//TODO: Can we make collections readonly collection, which will provide encapsulation. But... can work for all ORMs?
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -409,6 +414,11 @@ public class IdentityUser : FullAuditedAggregateRoot<Guid>, IUser, IHasEntityVer |
|
|
|
LastPasswordChangeTime = lastPasswordChangeTime; |
|
|
|
} |
|
|
|
|
|
|
|
public virtual void SetLastSignInTime(DateTimeOffset? lastSignInTime) |
|
|
|
{ |
|
|
|
LastSignInTime = lastSignInTime; |
|
|
|
} |
|
|
|
|
|
|
|
[CanBeNull] |
|
|
|
public virtual IdentityUserPasskey FindPasskey(byte[] credentialId) |
|
|
|
{ |
|
|
|
|
|
|
|
@ -405,6 +405,9 @@ public partial class TokenController |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
user.SetLastSignInTime(DateTimeOffset.UtcNow); |
|
|
|
await UserManager.UpdateAsync(user); |
|
|
|
|
|
|
|
return SignIn(principal, OpenIddictServerAspNetCoreDefaults.AuthenticationScheme); |
|
|
|
} |
|
|
|
|
|
|
|
|