限制链接登陆一次

This commit is contained in:
2022-05-30 09:43:01 +08:00
parent ae1137d2af
commit 458ca443fd
4 changed files with 39 additions and 4 deletions
@@ -278,6 +278,8 @@ namespace IRaCIS.Application.Services
var token = _tokenService.GetToken(IRaCISClaims.Create(_mapper.Map<UserBasicInfo>(sysUserInfo)));
await _userRepository.BatchUpdateNoTrackingAsync(t => t.Id == sysUserInfo.Id, u => new User() { EmailToken = token });
routeUrl = routeUrl + "?UserId=" + sysUserInfo.Id + "&Email=" + sysUserInfo.EMail + "&UserName=" + sysUserInfo.UserName + "&UserType=" + sysUserInfo.UserTypeRole.UserTypeShortName + "&access_token=" + token;
using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile))
@@ -369,6 +371,11 @@ namespace IRaCIS.Application.Services
var token = _tokenService.GetToken(IRaCISClaims.Create(_mapper.Map<UserBasicInfo>(sysUserInfo)));
if (sysUserInfo.IsFirstAdd)
{
await _userRepository.BatchUpdateNoTrackingAsync(t => t.Id == sysUserInfo.Id, u => new User() { EmailToken = token });
}
var pathToFile = _hostEnvironment.WebRootPath
+ Path.DirectorySeparatorChar.ToString()
@@ -421,6 +428,10 @@ namespace IRaCIS.Application.Services
var token = _tokenService.GetToken(IRaCISClaims.Create(_mapper.Map<UserBasicInfo>(sysUserInfo)));
if (sysUserInfo.IsFirstAdd)
{
await _userRepository.BatchUpdateNoTrackingAsync(t => t.Id == sysUserInfo.Id, u => new User() { EmailToken = token });
}
var pathToFile = _hostEnvironment.WebRootPath
+ Path.DirectorySeparatorChar.ToString()
@@ -199,17 +199,30 @@ namespace IRaCIS.Application.Services
return ResponseOutput.Ok();
}
/// <summary>
/// Result 为true 的时候 允许提交设置
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IResponseOutput> VerifyCanInitSetUserNameAndPwd(Guid userId)
{
return ResponseOutput.Ok(await _userRepository.AnyAsync(t => t.Id == userId && t.EmailToken == _userInfo.UserToken));
}
[HttpGet]
public async Task<IResponseOutput> InitSetUserNameAndPwd(Guid userId, string newUserName, string newPWd)
{
await VerifyUserPwdAsync(userId, newPWd);
if (!await _userRepository.AnyAsync(t => t.Id == userId && t.EmailToken==_userInfo.UserToken))
{
return ResponseOutput.NotOk("您的初始化链接已过期");
}
await VerifyUserPwdAsync(userId, newPWd);
await VerifyUserNameAsync(userId, newUserName);
await _userRepository.UpdatePartialFromQueryAsync(userId, u => new User()
@@ -220,7 +233,9 @@ namespace IRaCIS.Application.Services
IsFirstAdd = false,
}, true);
EmailToken = String.Empty
}, true) ;
return ResponseOutput.Ok();
}