修改
This commit is contained in:
@@ -194,7 +194,24 @@ namespace IRaCIS.Core.Application.Contracts
|
||||
|
||||
}
|
||||
|
||||
public class VerifyEmialGetDoctorInfoInDto
|
||||
{
|
||||
public string VerificationCode { get; set; }
|
||||
|
||||
public string EmailOrPhone { get; set; }
|
||||
}
|
||||
|
||||
public class VerifyEmialGetDoctorInfoOutDto
|
||||
{
|
||||
public Guid? DoctorId { get; set; }
|
||||
|
||||
public string Token { get; set; }
|
||||
}
|
||||
|
||||
public class SendEmialVerifyCodeInDto
|
||||
{
|
||||
public string Email { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class SiteSurveySendVerifyCode
|
||||
{
|
||||
|
||||
@@ -28,13 +28,14 @@ namespace IRaCIS.Core.Application.Contracts
|
||||
private readonly IRepository<TrialSiteUserSurvey> _trialSiteUserSurveyRepository;
|
||||
private readonly IRepository<User> _userRepository;
|
||||
private readonly IRepository<TrialSite> _trialSiteRepository;
|
||||
|
||||
private readonly IRepository<Doctor> _doctorRepository;
|
||||
private readonly IRepository<TrialUser> _trialUserRepository;
|
||||
private readonly ITokenService _tokenService;
|
||||
private readonly IMailVerificationService _mailVerificationService;
|
||||
|
||||
public TrialSiteSurveyService(IRepository<TrialSiteSurvey> trialSiteSurveyRepository, IRepository<TrialUser> trialUserRepository, IRepository<TrialSiteUserSurvey> trialSiteUserSurveyRepository,
|
||||
IRepository<User> userRepository, IRepository<TrialSite> trialSiteRepository,
|
||||
IRepository<Doctor> doctorRepository,
|
||||
ITokenService tokenService,
|
||||
IMailVerificationService mailVerificationService)
|
||||
{
|
||||
@@ -43,12 +44,71 @@ namespace IRaCIS.Core.Application.Contracts
|
||||
_userRepository = userRepository;
|
||||
_trialUserRepository = trialUserRepository;
|
||||
_trialSiteRepository = trialSiteRepository;
|
||||
this._doctorRepository = doctorRepository;
|
||||
_tokenService = tokenService;
|
||||
_mailVerificationService = mailVerificationService;
|
||||
}
|
||||
|
||||
private object lockObj { get; set; } = new object();
|
||||
|
||||
/// <summary>
|
||||
/// 发送验证码
|
||||
/// </summary>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
public async Task<IResponseOutput> SendEmialVerifyCode(SendEmialVerifyCodeInDto userInfo)
|
||||
{
|
||||
//检查手机或者邮箱是否有效
|
||||
if (!Regex.IsMatch(userInfo.Email, @"^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$"))
|
||||
{
|
||||
throw new BusinessValidationFailedException("请输入正确的邮箱地址。");
|
||||
}
|
||||
|
||||
//邮箱
|
||||
|
||||
//验证码 6位
|
||||
int verificationCode = new Random().Next(100000, 1000000);
|
||||
await _mailVerificationService.SendEmailVerification(userInfo.Email, verificationCode);
|
||||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证邮箱验证码 获取医生信息Id
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<VerifyEmialGetDoctorInfoOutDto> VerifyEmialGetDoctorInfo(VerifyEmialGetDoctorInfoInDto inDto)
|
||||
{
|
||||
var verificationRecord = await _repository.GetQueryable<VerificationCode>().OrderByDescending(x=>x.ExpirationTime).Where(t => (t.EmailOrPhone == inDto.EmailOrPhone) && t.Code == inDto.VerificationCode && t.CodeType == VerifyType.Email).FirstOrDefaultAsync();
|
||||
VerifyEmialGetDoctorInfoOutDto result = new VerifyEmialGetDoctorInfoOutDto();
|
||||
|
||||
var doctorInfo = await _doctorRepository.Where(x => x.EMail == inDto.EmailOrPhone).FirstOrDefaultAsync();
|
||||
|
||||
result.DoctorId = doctorInfo == null ? null : doctorInfo.Id;
|
||||
//检查数据库是否存在该验证码
|
||||
if (verificationRecord == null)
|
||||
{
|
||||
throw new BusinessValidationFailedException("验证码错误。");
|
||||
}
|
||||
else
|
||||
{
|
||||
//检查验证码是否失效
|
||||
if (verificationRecord.ExpirationTime < DateTime.Now)
|
||||
{
|
||||
throw new BusinessValidationFailedException("验证码已经过期。");
|
||||
}
|
||||
else //验证码正确 并且 没有超时
|
||||
{
|
||||
result.Token= _tokenService.GetToken(IRaCISClaims.Create(new UserBasicInfo()));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送验证码
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user