feat: 添加用户状态效验及验证码
This commit is contained in:
@@ -41,6 +41,7 @@ namespace Yi.Framework.Rbac.Application.Services
|
||||
private IDistributedCache<CaptchaPhoneCacheItem, CaptchaPhoneCacheKey> _phoneCache;
|
||||
private readonly ICaptcha _captcha;
|
||||
private readonly IGuidGenerator _guidGenerator;
|
||||
private readonly RbacOptions _rbacOptions;
|
||||
public AccountService(IUserRepository userRepository,
|
||||
ICurrentUser currentUser,
|
||||
AccountManager accountManager,
|
||||
@@ -50,7 +51,8 @@ namespace Yi.Framework.Rbac.Application.Services
|
||||
IOptions<JwtOptions> jwtOptions,
|
||||
IDistributedCache<CaptchaPhoneCacheItem, CaptchaPhoneCacheKey> phoneCache,
|
||||
ICaptcha captcha,
|
||||
IGuidGenerator guidGenerator)
|
||||
IGuidGenerator guidGenerator,
|
||||
IOptions<RbacOptions> options)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
_currentUser = currentUser;
|
||||
@@ -62,6 +64,7 @@ namespace Yi.Framework.Rbac.Application.Services
|
||||
_phoneCache = phoneCache;
|
||||
_captcha = captcha;
|
||||
_guidGenerator = guidGenerator;
|
||||
_rbacOptions = options.Value;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,10 +82,13 @@ namespace Yi.Framework.Rbac.Application.Services
|
||||
/// </summary>
|
||||
private void ValidationImageCaptcha(LoginInputVo input)
|
||||
{
|
||||
//登录不想要验证码 ,可不效验
|
||||
if (!_captcha.Validate(input.Uuid, input.Code))
|
||||
if (_rbacOptions.EnableCaptcha)
|
||||
{
|
||||
throw new UserFriendlyException("验证码错误");
|
||||
//登录不想要验证码 ,可不效验
|
||||
if (!_captcha.Validate(input.Uuid, input.Code))
|
||||
{
|
||||
throw new UserFriendlyException("验证码错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +120,7 @@ namespace Yi.Framework.Rbac.Application.Services
|
||||
}
|
||||
|
||||
//效验验证码
|
||||
// ValidationImageCaptcha(input);
|
||||
ValidationImageCaptcha(input);
|
||||
|
||||
UserEntity user = new();
|
||||
//登录成功
|
||||
@@ -123,6 +129,12 @@ namespace Yi.Framework.Rbac.Application.Services
|
||||
//获取用户信息
|
||||
var userInfo = await _userRepository.GetUserAllInfoAsync(user.Id);
|
||||
|
||||
//判断用户状态
|
||||
if (userInfo.User.State == false)
|
||||
{
|
||||
throw new UserFriendlyException(UserConst.State_Is_State);
|
||||
}
|
||||
|
||||
if (userInfo.RoleCodes.Count == 0)
|
||||
{
|
||||
throw new UserFriendlyException(UserConst.No_Role);
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Yi.Framework.Rbac.Domain.Shared.Consts
|
||||
public const string Login_User_No_Exist = "登录失败!用户名不存在!";
|
||||
public const string Login_Passworld_Error = "密码为空,添加失败!";
|
||||
public const string User_Exist = "用户已经存在,添加失败!";
|
||||
public const string State_Is_State = "该用户已被禁用,请联系管理员进行恢复";
|
||||
public const string No_Permission = "登录禁用!该用户分配无任何权限,无意义登录!";
|
||||
public const string No_Role = "登录禁用!该用户分配无任何角色,无意义登录!";
|
||||
|
||||
|
||||
@@ -12,5 +12,10 @@ namespace Yi.Framework.Rbac.Domain.Shared.Options
|
||||
/// 超级管理员默认密码
|
||||
/// </summary>
|
||||
public string AdminPassword { get; set; } = "123456";
|
||||
|
||||
/// <summary>
|
||||
/// 是否开启登录验证码
|
||||
/// </summary>
|
||||
public bool EnableCaptcha { get; set; } = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user