修改代码
This commit is contained in:
@@ -8,6 +8,9 @@ using Panda.DynamicWebApi.Attributes;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using IRaCIS.Core.Infra.Common.Cache;
|
||||
using Microsoft.Identity.Client;
|
||||
using static IRaCIS.Core.Domain.Share.StaticData;
|
||||
|
||||
namespace IRaCIS.Application.Services
|
||||
{
|
||||
@@ -613,6 +616,38 @@ namespace IRaCIS.Application.Services
|
||||
[NonDynamicMethod]
|
||||
public async Task<IResponseOutput<LoginReturnDTO>> Login(string userName, string password)
|
||||
{
|
||||
|
||||
//const string cachePrefix = "login-failures:";
|
||||
//const int maxFailures = 3;
|
||||
//const int lockoutMinutes = 3;
|
||||
|
||||
//// 生成缓存键
|
||||
//string cacheKey = $"{cachePrefix}{userName}";
|
||||
|
||||
//// 从缓存中获取登录失败次数
|
||||
//int? failCount = _cache.Get<int?>(cacheKey);
|
||||
|
||||
|
||||
//if (failCount != null)
|
||||
//{
|
||||
|
||||
// _cache.Set(cacheKey + ":locked", true, TimeSpan.FromMinutes(lockoutMinutes));
|
||||
|
||||
// if (failCount >= maxFailures)
|
||||
// {
|
||||
// throw new BusinessValidationFailedException($"账号已被锁定,请等待 {lockoutMinutes} 分钟后再试。");
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
//if (failCount >= maxFailures)
|
||||
//{
|
||||
// // 如果登录失败次数达到了 3 次,则锁定用户
|
||||
// _cache.Set(cacheKey + ":locked", true, TimeSpan.FromMinutes(lockoutMinutes));
|
||||
//}
|
||||
|
||||
|
||||
|
||||
var userLoginReturnModel = new LoginReturnDTO();
|
||||
|
||||
|
||||
@@ -620,21 +655,30 @@ namespace IRaCIS.Application.Services
|
||||
|
||||
if (loginUser == null)
|
||||
{
|
||||
//此处下面 代码 为了支持医生也能登录 而且前端不加选择到底是管理用户 还是医生用户 奇怪的需求 无法理解
|
||||
|
||||
var loginDoctor = await _doctorRepository.Where(u => u.Phone == userName && u.Password == password).ProjectTo<UserBasicInfo>(_mapper.ConfigurationProvider).FirstOrDefaultAsync();
|
||||
#region 屏蔽代码,现在没用到
|
||||
////此处下面 代码 为了支持医生也能登录 而且前端不加选择到底是管理用户 还是医生用户 奇怪的需求 无法理解
|
||||
|
||||
if (loginDoctor == null)
|
||||
{
|
||||
return ResponseOutput.NotOk(_localizer["User_CheckNameOrPw"], new LoginReturnDTO());
|
||||
//var loginDoctor = await _doctorRepository.Where(u => u.Phone == userName && u.Password == password).ProjectTo<UserBasicInfo>(_mapper.ConfigurationProvider).FirstOrDefaultAsync();
|
||||
|
||||
}
|
||||
//if (loginDoctor == null)
|
||||
//{
|
||||
// return ResponseOutput.NotOk(_localizer["User_CheckNameOrPw"], new LoginReturnDTO());
|
||||
//}
|
||||
//userLoginReturnModel.BasicInfo = loginDoctor;
|
||||
|
||||
//登录 清除缓存
|
||||
//_cache.Remove(userLoginReturnModel.BasicInfo.Id.ToString());
|
||||
//return ResponseOutput.Ok(userLoginReturnModel);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
return ResponseOutput.NotOk(_localizer["User_CheckNameOrPw"], new LoginReturnDTO());
|
||||
|
||||
userLoginReturnModel.BasicInfo = loginDoctor;
|
||||
|
||||
// 登录 清除缓存
|
||||
_cache.Remove(userLoginReturnModel.BasicInfo.Id.ToString());
|
||||
return ResponseOutput.Ok(userLoginReturnModel);
|
||||
|
||||
}
|
||||
|
||||
@@ -652,5 +696,35 @@ namespace IRaCIS.Application.Services
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//private bool loginIsLocked(string userName)
|
||||
//{
|
||||
|
||||
// //if (failCount == null)
|
||||
// //{
|
||||
// // failCount = 0;
|
||||
// //}
|
||||
// //else
|
||||
// //{
|
||||
// // failCount++;
|
||||
// //}
|
||||
|
||||
// //// 更新缓存中的登录失败次数
|
||||
// //_cache.Set(cacheKey, failCount, TimeSpan.FromMinutes(lockoutMinutes));
|
||||
|
||||
// //if (failCount >= maxFailures)
|
||||
// //{
|
||||
// // // 如果登录失败次数达到了 3 次,则锁定用户
|
||||
// // _cache.Set(cacheKey + ":locked", true, TimeSpan.FromMinutes(lockoutMinutes));
|
||||
// //}
|
||||
|
||||
|
||||
|
||||
|
||||
// //return isLocked;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user