MFA 登录修改
continuous-integration/drone/push Build is running
Details
continuous-integration/drone/push Build is running
Details
parent
f62e849f80
commit
f034d9ca87
|
@ -735,17 +735,17 @@ namespace IRaCIS.Core.Application.Service
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发送MFA 验证邮件
|
/// 发送MFA 验证邮件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId"></param>
|
/// <param name="identityUserId"></param>
|
||||||
/// <param name="mfaType"></param>
|
/// <param name="mfaType"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public async Task<IResponseOutput> SendMFAEmail(Guid userId, UserMFAType mfaType)
|
public async Task<IResponseOutput> SendMFAEmail(Guid identityUserId, UserMFAType mfaType)
|
||||||
{
|
{
|
||||||
var userInfo = await _identityUserRepository.Where(u => u.Id == userId).Select(t => new { t.FullName, t.EMail }).FirstOrDefaultAsync();
|
var userInfo = await _identityUserRepository.Where(u => u.Id == identityUserId).Select(t => new { t.FullName, t.EMail }).FirstOrDefaultAsync();
|
||||||
|
|
||||||
int verificationCode = new Random().Next(100000, 1000000);
|
int verificationCode = new Random().Next(100000, 1000000);
|
||||||
|
|
||||||
await _mailVerificationService.SenMFAVerifyEmail(userId, userInfo.FullName, userInfo.EMail, verificationCode, (UserMFAType)mfaType);
|
await _mailVerificationService.SenMFAVerifyEmail(identityUserId, userInfo.FullName, userInfo.EMail, verificationCode, (UserMFAType)mfaType);
|
||||||
|
|
||||||
var hiddenEmail = IRCEmailPasswordHelper.MaskEmail(userInfo.EMail);
|
var hiddenEmail = IRCEmailPasswordHelper.MaskEmail(userInfo.EMail);
|
||||||
return ResponseOutput.Ok(hiddenEmail);
|
return ResponseOutput.Ok(hiddenEmail);
|
||||||
|
@ -754,20 +754,19 @@ namespace IRaCIS.Core.Application.Service
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 验证MFA 邮件
|
/// 验证MFA 邮件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId"></param>
|
/// <param name="identityUserId"></param>
|
||||||
/// <param name="Code"></param>
|
/// <param name="Code"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="BusinessValidationFailedException"></exception>
|
/// <exception cref="BusinessValidationFailedException"></exception>
|
||||||
[AllowAnonymous]
|
public async Task<IResponseOutput> VerifyMFACodeAsync(Guid identityUserId, string Code)
|
||||||
public async Task<IResponseOutput> VerifyMFACodeAsync(Guid userId, string Code)
|
|
||||||
{
|
{
|
||||||
var verificationRecord = await _verificationCodeRepository.Where(t => t.UserId == userId && t.Code == Code && t.CodeType == VerifyType.Email).OrderByDescending(x => x.ExpirationTime).FirstOrDefaultAsync();
|
var verificationRecord = await _verificationCodeRepository.Where(t => t.UserId == identityUserId && t.Code == Code && t.CodeType == VerifyType.Email).OrderByDescending(x => x.ExpirationTime).FirstOrDefaultAsync();
|
||||||
VerifyEmialGetDoctorInfoOutDto result = new VerifyEmialGetDoctorInfoOutDto();
|
VerifyEmialGetDoctorInfoOutDto result = new VerifyEmialGetDoctorInfoOutDto();
|
||||||
|
|
||||||
//检查数据库是否存在该验证码
|
//检查数据库是否存在该验证码
|
||||||
if (verificationRecord == null)
|
if (verificationRecord == null)
|
||||||
{
|
{
|
||||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = userId, OptUserId = userId, OptType = UserOptType.MFALoginFail }, true);
|
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionUserName = _userInfo.UserName, TargetIdentityUserId = identityUserId, OptType = UserOptType.MFALoginFail }, true);
|
||||||
//---验证码错误。
|
//---验证码错误。
|
||||||
throw new BusinessValidationFailedException(_localizer["TrialSiteSurvey_WrongVerificationCode"]);
|
throw new BusinessValidationFailedException(_localizer["TrialSiteSurvey_WrongVerificationCode"]);
|
||||||
}
|
}
|
||||||
|
@ -776,7 +775,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
//检查验证码是否失效
|
//检查验证码是否失效
|
||||||
if (verificationRecord.ExpirationTime < DateTime.Now)
|
if (verificationRecord.ExpirationTime < DateTime.Now)
|
||||||
{
|
{
|
||||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = userId, OptUserId = userId, OptType = UserOptType.MFALoginFail }, true);
|
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionUserName = _userInfo.UserName, TargetIdentityUserId = identityUserId, OptType = UserOptType.MFALoginFail }, true);
|
||||||
//---验证码已经过期。
|
//---验证码已经过期。
|
||||||
throw new BusinessValidationFailedException(_localizer["TrialSiteSurvey_ExpiredVerificationCode"]);
|
throw new BusinessValidationFailedException(_localizer["TrialSiteSurvey_ExpiredVerificationCode"]);
|
||||||
|
|
||||||
|
@ -788,7 +787,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
|
|
||||||
//删除验证码历史记录
|
//删除验证码历史记录
|
||||||
await _verificationCodeRepository.BatchDeleteNoTrackingAsync(t => t.Id == verificationRecord.Id);
|
await _verificationCodeRepository.BatchDeleteNoTrackingAsync(t => t.Id == verificationRecord.Id);
|
||||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = userId, OptUserId = userId, OptType = UserOptType.MFALogin }, true);
|
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionUserName = _userInfo.UserName, TargetIdentityUserId = identityUserId, OptType = UserOptType.MFALogin }, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue