简体   繁体   English

在 ApplicationUser 中保持用户锁定状态的最佳方法是什么?

[英]What is the best way to keep the User's Lockout status in ApplicationUser?

I want to save the user's lockout status in my ApplicationUser (inherited from IdentityUser) in Asp.Net Mvc (Core or NetFramework), so which implementation is better from the design perspective?我想在 Asp.Net Mvc(Core 或 NetFramework)中的 ApplicationUser(继承自 IdentityUser)中保存用户的锁定状态,那么从设计角度来看,哪种实现更好?

1. User with IsActive property and LockoutReason enum property, separately 1. 分别具有 IsActive 属性和 LockoutReason 枚举属性的用户

class ApplicationUser: IdentityUser
{
    // ...
    public bool IsAcitve {get;  set;}
    public UserLockoutReason LockoutReason {get; set; }
}

enum UserLockoutReason 
{
    NotLocked,
    LockedByAdmin,
    MaximumWrongPasswordAttemptsReached,
    ...
}

2. User with ActiveStatus enum 2. 具有 ActiveStatus 枚举的用户

class ApplicationUser: IdentityUser
{
    // ...
    public UserActiveStatus ActiveStatus {get; set; }
}

enum UserActiveStatus
{
    Active,
    LockedByAdmin,
    MaximumWrongPasswordAttemptsReached,        
    ...
}

ps: This design is going to be as an UserManagement's part to our IdentityProvider, so it's is so important to us to implement the best way we can ps:这个设计将成为我们 IdentityProvider 的 UserManagement 的一部分,所以对我们来说实现最好的方式非常重要

I would go in this direction:我会在这个方向上 go :

class ApplicationUser: IdentityUser
{
    // ...
    public UserActiveStatus ActiveStatus {get; set; }
}

enum UserActiveStatus
{
    Active,
    LockedByAdmin,
    MaximumWrongPasswordAttemptsReached,        
    ...
}

Since the ActiveStatus is the final information that you will need for the user, there will be need to branch of user.IsActive in if-else statements, and then getting the LockoutReason in case it's locked account won't be neccesary由于ActiveStatus是您需要为用户提供的最终信息,因此需要在 if-else 语句中对user.IsActive进行分支,然后获取LockoutReason以防帐户被锁定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM