HIR 增加下拉框切换账户

Test_HIR_Net8
hang 2025-03-27 16:30:43 +08:00
parent 5ec3fc3d13
commit 95fe14fece
5 changed files with 134 additions and 4 deletions

View File

@ -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<IResponseOutput<LoginReturnDTO>> LoginSelectUserType(Guid userId, Guid userTypeId,
[FromServices] IUserService _userService,
[FromServices] IFusionCache _fusionCache,
[FromServices] ITokenService _tokenService,
[FromServices] IReadingImageTaskService readingImageTaskService,
[FromServices] IOptionsMonitor<ServiceVerifyConfigOption> _verifyConfig,
[FromServices] IOptionsMonitor<SystemEmailSendConfig> _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;
}

View File

@ -31,6 +31,26 @@ namespace IRaCIS.Application.Contracts
public SystemEmailSendConfigView CompanyInfo { get; set; }
public bool IsMutiAccount => AccountList?.Count > 1;
public List<UserAccountInfo> 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

View File

@ -9,6 +9,8 @@ namespace IRaCIS.Core.Application.Service
Task<IResponseOutput> DeleteUser(Guid userId);
Task<UserDetailDTO> GetUser(Guid id);
Task<PageOutput<UserListDTO>> GetUserList(UserListQueryDTO param);
Task<IResponseOutput<LoginReturnDTO>> LoginSelectUserType(Guid userId, Guid userTypeId);
Task<IResponseOutput<LoginReturnDTO>> Login(string userName, string password);
Task<IResponseOutput> VerifyMFACodeAsync(Guid userId, string Code);

View File

@ -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
}
/// <summary>
/// (未登陆) 设置新密码
@ -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<UserListDTO>(_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<IResponseOutput<LoginReturnDTO>> HospitalUserLogin(string token)
//{
// //同济医院token 地址http://192.168.40.88:8080
// //本地测试地址接口
// //RestClientAPI.PostAsync<>
//}
[NonDynamicMethod]
public async Task<IResponseOutput<LoginReturnDTO>> 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);
}
/// <summary>
/// 用户登陆
/// </summary>
@ -728,6 +753,9 @@ namespace IRaCIS.Core.Application.Service
});
userLoginReturnModel.AccountList = _userRepository.Where(t => t.EMail == userLoginReturnModel.BasicInfo.EMail && t.UserTypeEnum != UserTypeEnum.SuperAdmin)
.ProjectTo<UserAccountInfo>(_mapper.ConfigurationProvider).ToList();
return ResponseOutput.Ok(userLoginReturnModel);
}

View File

@ -136,6 +136,11 @@ namespace IRaCIS.Core.Application.Service
;
CreateMap<UserFeedBackAddOrEdit, UserFeedBack>().ReverseMap();
CreateMap<User, UserAccountInfo>()
.ForMember(d => d.UserTypeShortName, c => c.MapFrom(t => t.UserTypeRole.UserTypeShortName));
}
}