c# - 在 ApplicationUser 中保持用户锁定状态的最佳方法是什么?
问题描述
我想在 Asp.Net Mvc(Core 或 NetFramework)中的 ApplicationUser(继承自 IdentityUser)中保存用户的锁定状态,那么从设计角度来看,哪种实现更好?
1. 分别具有 IsActive 属性和 LockoutReason 枚举属性的用户
class ApplicationUser: IdentityUser
{
// ...
public bool IsAcitve {get; set;}
public UserLockoutReason LockoutReason {get; set; }
}
enum UserLockoutReason
{
NotLocked,
LockedByAdmin,
MaximumWrongPasswordAttemptsReached,
...
}
2. 具有 ActiveStatus 枚举的用户
class ApplicationUser: IdentityUser
{
// ...
public UserActiveStatus ActiveStatus {get; set; }
}
enum UserActiveStatus
{
Active,
LockedByAdmin,
MaximumWrongPasswordAttemptsReached,
...
}
ps:这个设计将成为我们 IdentityProvider 的 UserManagement 的一部分,所以对我们来说实现最好的方式非常重要
解决方案
我会朝这个方向走:
class ApplicationUser: IdentityUser
{
// ...
public UserActiveStatus ActiveStatus {get; set; }
}
enum UserActiveStatus
{
Active,
LockedByAdmin,
MaximumWrongPasswordAttemptsReached,
...
}
由于这ActiveStatus
是您需要为用户提供的最终信息,因此需要user.IsActive
在 if-else 语句中进行分支,然后获取LockoutReason
以防万一它被锁定的帐户将是不必要的
推荐阅读
- vba - VBA:使用从 excel 到 Word 的过滤行运行宏
- javascript - JS在几句话后剪切文本
- python - matplotlib中x轴上的“原点”和点“0”之间的差距?
- python - 有效地从包的许多子模块中导入名称
- apache-spark - spark ML 管道为不同的运行提供不同的值
- scala - 如何将scala中的十六进制十进制列转换为int
- python-2.7 - 股票市场上的网络抓取 - AttributeError:“NoneType”对象没有属性“文本”
- json - 节点 events.js:167 throw er; // 未处理的“错误”事件
- android - Chromecast 自定义 MediaRouteChooserDialog
- javascript - 按住移动 DOM 元素/单击并拖动