From ff966b2965ebfedc4fe9c65276ecafd70d749122 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 15 Feb 2023 17:15:50 +0800 Subject: [PATCH] Add `ShouldChangePasswordOnNextLogin` to `IdenttiyUser`. --- .../Volo/Abp/Identity/AspNetCore/AbpSignInManager.cs | 6 ++++++ .../Volo/Abp/Identity/IdentityUser.cs | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSignInManager.cs b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSignInManager.cs index bbba6e63ec..42ef9e5261 100644 --- a/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSignInManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSignInManager.cs @@ -85,6 +85,12 @@ public class AbpSignInManager : SignInManager return SignInResult.NotAllowed; } + if (user.ShouldChangePasswordOnNextLogin) + { + Logger.LogWarning($"The user should change password! (username: \"{user.UserName}\", id:\"{user.Id}\")"); + return SignInResult.NotAllowed; + } + return await base.PreSignInCheck(user); } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs index c7aceb7bf9..1e6eea7c35 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs @@ -112,6 +112,11 @@ public class IdentityUser : FullAuditedAggregateRoot, IUser, IHasEntityVer /// public virtual int AccessFailedCount { get; protected internal set; } + /// + /// Should change password on next login. + /// + public virtual bool ShouldChangePasswordOnNextLogin { get; protected internal set; } + /// /// A version value that is increased whenever the entity is changed. /// @@ -368,6 +373,11 @@ public class IdentityUser : FullAuditedAggregateRoot, IUser, IHasEntityVer IsActive = isActive; } + public virtual void SetShouldChangePasswordOnNextLogin(bool shouldChangePasswordOnNextLogin) + { + ShouldChangePasswordOnNextLogin = shouldChangePasswordOnNextLogin; + } + public override string ToString() { return $"{base.ToString()}, UserName = {UserName}";