diff --git a/IRaCIS.Core.API/Controllers/ExtraController.cs b/IRaCIS.Core.API/Controllers/ExtraController.cs index 6bbb4f479..91b89b224 100644 --- a/IRaCIS.Core.API/Controllers/ExtraController.cs +++ b/IRaCIS.Core.API/Controllers/ExtraController.cs @@ -24,6 +24,7 @@ using RestSharp; using RestSharp.Authenticators; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Net; using System.Net.Http; @@ -101,6 +102,80 @@ namespace IRaCIS.Api.Controllers + [HttpGet, Route("user/loginSelectUserType")] + public async Task> LoginSelectUserType(Guid userId, Guid userTypeId, + [FromServices] IUserService _userService, + [FromServices] IFusionCache _fusionCache, + [FromServices] ITokenService _tokenService, + [FromServices] IReadingImageTaskService readingImageTaskService, + [FromServices] IOptionsMonitor _verifyConfig, + [FromServices] IOptionsMonitor _emailConfig, + + [FromServices] IMailVerificationService _mailVerificationService) + { + var emailConfig = _emailConfig.CurrentValue; + var companyInfo = new SystemEmailSendConfigView() { CompanyName = emailConfig.CompanyName, CompanyNameCN = emailConfig.CompanyNameCN, CompanyShortName = emailConfig.CompanyShortName, CompanyShortNameCN = emailConfig.CompanyShortNameCN }; + + var returnModel = await _userService.LoginSelectUserType(userId, userTypeId); + + if (returnModel.IsSuccess) + { + if (_verifyConfig.CurrentValue.OpenLoginMFA) + { + //MFA 发送邮件 + + returnModel.Data.IsMFA = true; + + var email = returnModel.Data.BasicInfo.EMail; + + var hiddenEmail = IRCEmailPasswordHelper.MaskEmail(email); + + returnModel.Data.BasicInfo.EMail = hiddenEmail; + + //修改密码 + if (returnModel.Data.BasicInfo.IsFirstAdd || returnModel.Data.BasicInfo.LoginState == 1) + { + returnModel.Data.JWTStr = _tokenService.GetToken(IRaCISClaims.Create(returnModel.Data.BasicInfo)); + } + else + { + //正常登录才发送邮件 + await _userService.SendMFAEmail(userId); + + } + + } + else + { + returnModel.Data.JWTStr = _tokenService.GetToken(IRaCISClaims.Create(returnModel.Data.BasicInfo)); + + // 创建一个 CookieOptions 对象,用于设置 Cookie 的属性 + var option = new CookieOptions + { + Expires = DateTime.Now.AddMonths(1), // 设置过期时间为 30 分钟之后 + HttpOnly = false, // 确保 cookie 只能通过 HTTP 访问 + SameSite = Microsoft.AspNetCore.Http.SameSiteMode.None, // 设置 SameSite 属性 + Secure = false // 确保 cookie 只能通过 HTTPS 访问 + }; + + HttpContext.Response.Cookies.Append("access_token", returnModel.Data.JWTStr, option); + + + + // 验证阅片休息时间 + await readingImageTaskService.ResetReadingRestTime(returnModel.Data.BasicInfo.Id); + + await _fusionCache.SetAsync(CacheKeys.UserToken(userId), returnModel.Data.JWTStr, TimeSpan.FromDays(7)); + + await _fusionCache.SetAsync(CacheKeys.UserAutoLoginOut(userId), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromMinutes(_verifyConfig.CurrentValue.AutoLoginOutMinutes)); + } + } + + returnModel.Data.CompanyInfo = companyInfo; + + return returnModel; + } + diff --git a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs index 770e09914..5801402e4 100644 --- a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs +++ b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs @@ -31,6 +31,26 @@ namespace IRaCIS.Application.Contracts public SystemEmailSendConfigView CompanyInfo { get; set; } + public bool IsMutiAccount => AccountList?.Count > 1; + public List AccountList { get; set; } + + } + public class UserAccountInfo + { + public Guid Id { get; set; } + public string UserName { get; set; } = string.Empty; + public string FullName { get; set; } = string.Empty; + + public string Phone { get; set; } = string.Empty; + public string EMail { get; set; } = string.Empty; + + public Guid UserTypeId { get; set; } + + public UserTypeEnum UserTypeEnum { get; set; } + + public string UserTypeShortName { get; set; } + + public int Status { get; set; } } public class UserBasicInfo diff --git a/IRaCIS.Core.Application/Service/Management/Interface/IUserService.cs b/IRaCIS.Core.Application/Service/Management/Interface/IUserService.cs index dd3778899..7cf9372cc 100644 --- a/IRaCIS.Core.Application/Service/Management/Interface/IUserService.cs +++ b/IRaCIS.Core.Application/Service/Management/Interface/IUserService.cs @@ -9,6 +9,8 @@ namespace IRaCIS.Core.Application.Service Task DeleteUser(Guid userId); Task GetUser(Guid id); Task> GetUserList(UserListQueryDTO param); + + Task> LoginSelectUserType(Guid userId, Guid userTypeId); Task> Login(string userName, string password); Task VerifyMFACodeAsync(Guid userId, string Code); diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index ef6451214..d5e7354b0 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -2,6 +2,7 @@ using IRaCIS.Application.Contracts; using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Application.Helper; +using IRaCIS.Core.Application.Helper.OtherTool; using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infrastructure; @@ -339,7 +340,7 @@ namespace IRaCIS.Core.Application.Service } - + /// /// (未登陆) 设置新密码 @@ -393,7 +394,7 @@ namespace IRaCIS.Core.Application.Service .WhereIf(inQuery.UserState != null, t => t.Status == inQuery.UserState) .WhereIf(inQuery.IsTestUser != null, t => t.IsTestUser == inQuery.IsTestUser) .WhereIf(inQuery.IsZhiZhun != null, t => t.IsZhiZhun == inQuery.IsZhiZhun) - .WhereIf(_userInfo.UserTypeEnumInt ==(int)UserTypeEnum.OA, t => t.UserTypeEnum != UserTypeEnum.Admin) + .WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.OA, t => t.UserTypeEnum != UserTypeEnum.Admin) .ProjectTo(_mapper.ConfigurationProvider); return await userQueryable.ToPagedListAsync(inQuery); @@ -485,7 +486,7 @@ namespace IRaCIS.Core.Application.Service if (user == null) return Null404NotFound(user); - if (user.Status!=model.Status) + if (user.Status != model.Status) { await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = _userInfo.Id, OptUserId = model.Id, OptType = model.Status == UserStateEnum.Enable ? UserOptType.AccountEnable : UserOptType.AccountLocked }, true); @@ -501,7 +502,7 @@ namespace IRaCIS.Core.Application.Service await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = _userInfo.Id, OptUserId = model.Id, OptType = UserOptType.UpdateUser }); - + var success = await _userRepository.SaveChangesAsync(); @@ -622,6 +623,30 @@ namespace IRaCIS.Core.Application.Service return ResponseOutput.Ok(); } + + + //public async Task> HospitalUserLogin(string token) + //{ + // //同济医院token 地址:http://192.168.40.88:8080 + + // //本地测试地址接口 + + // //RestClientAPI.PostAsync<> + + //} + + + + + [NonDynamicMethod] + public async Task> LoginSelectUserType(Guid userId, Guid userTypeId) + { + var userNamePwd = await _userRepository.Where(t => t.Id == userId && t.UserTypeId == userTypeId).Select(t => new { t.UserName, t.Password }).FirstNotNullAsync(); + + return await Login(userNamePwd.UserName, userNamePwd.Password); + } + + /// /// 用户登陆 /// @@ -728,6 +753,9 @@ namespace IRaCIS.Core.Application.Service }); + userLoginReturnModel.AccountList = _userRepository.Where(t => t.EMail == userLoginReturnModel.BasicInfo.EMail && t.UserTypeEnum != UserTypeEnum.SuperAdmin) + .ProjectTo(_mapper.ConfigurationProvider).ToList(); + return ResponseOutput.Ok(userLoginReturnModel); } diff --git a/IRaCIS.Core.Application/Service/Management/_MapConfig.cs b/IRaCIS.Core.Application/Service/Management/_MapConfig.cs index bd6289e3f..a4adf5475 100644 --- a/IRaCIS.Core.Application/Service/Management/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Management/_MapConfig.cs @@ -136,6 +136,11 @@ namespace IRaCIS.Core.Application.Service ; CreateMap().ReverseMap(); + + CreateMap() + .ForMember(d => d.UserTypeShortName, c => c.MapFrom(t => t.UserTypeRole.UserTypeShortName)); + + } }