链接点击一次后端跳转

Uat_Study
hang 2022-05-30 11:28:01 +08:00
parent 144f53e809
commit a261605bde
7 changed files with 49 additions and 37 deletions

View File

@ -19,6 +19,10 @@ using Microsoft.AspNetCore.Http;
using IRaCIS.Core.Application.Interfaces; using IRaCIS.Core.Application.Interfaces;
using System.Threading.Tasks; using System.Threading.Tasks;
using IRaCIS.Application.Services; using IRaCIS.Application.Services;
using IRaCIS.Core.Infra.EFCore;
using IRaCIS.Core.Domain.Models;
using IRaCIS.Core.Infrastructure;
using System.Linq;
namespace IRaCIS.Api.Controllers namespace IRaCIS.Api.Controllers
{ {
@ -188,17 +192,26 @@ namespace IRaCIS.Api.Controllers
//外部用户 邮件链接调用 以及跳转逻辑
[HttpGet("trialExternalUser/ExternalUserJoinTrial")] [HttpGet("User/UserRedirect")]
[AllowAnonymous] [AllowAnonymous]
public async Task<IActionResult> ExternalUserJoinTrial([FromServices] ITrialExternalUserService _trialExternalUserService, Guid trialId, Guid trialExternalUserId, string url) public async Task<IActionResult> UserRedirect([FromServices] IRepository<User> _userRepository, string url)
{ {
await _trialExternalUserService.UserConfirmJoinTrial(trialId, trialExternalUserId);
var decodeUrl = System.Web.HttpUtility.UrlDecode(url); var decodeUrl = System.Web.HttpUtility.UrlDecode(url);
var userId = decodeUrl.Substring(decodeUrl.IndexOf("UserId=") + "UserId=".Length , 36) ;
var token = decodeUrl.Substring(decodeUrl.IndexOf("access_token=") + "access_token=".Length);
var domainStrList = decodeUrl.Split("/").ToList().Take(3).ToList();
var errorUrl = domainStrList[0]+"//"+ domainStrList[2]+ "/error";
if (!await _userRepository.AnyAsync(t => t.Id == Guid.Parse(userId) && t.EmailToken == token && t.IsFirstAdd))
{
decodeUrl = errorUrl+ "?ErrorMessage=您的初始化链接已过期";
}
return Redirect(decodeUrl); return Redirect(decodeUrl);
} }

View File

@ -390,7 +390,6 @@
传入参数记录ID 传入参数记录ID
</summary> </summary>
<param name="SignInfo"></param> <param name="SignInfo"></param>
<param name="response"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:IRaCIS.Core.Application.Service.Inspection.InspectionService.CompletedSign(System.Guid,IRaCIS.Core.Infrastructure.Extention.IResponseOutput)"> <member name="M:IRaCIS.Core.Application.Service.Inspection.InspectionService.CompletedSign(System.Guid,IRaCIS.Core.Infrastructure.Extention.IResponseOutput)">
@ -971,7 +970,6 @@
发送验证码 发送验证码
</summary> </summary>
<param name="userInfo"></param> <param name="userInfo"></param>
<param name="_mailVerificationService"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:IRaCIS.Core.Application.Contracts.TrialSiteSurveyService.VerifySendCode(IRaCIS.Core.Application.Contracts.LoginDto,IRaCIS.Core.Application.Auth.ITokenService)"> <member name="M:IRaCIS.Core.Application.Contracts.TrialSiteSurveyService.VerifySendCode(IRaCIS.Core.Application.Contracts.LoginDto,IRaCIS.Core.Application.Auth.ITokenService)">
@ -2354,13 +2352,6 @@
<member name="M:IRaCIS.Application.Services.UserService.SendVerificationCode(System.String)"> <member name="M:IRaCIS.Application.Services.UserService.SendVerificationCode(System.String)">
<summary>发送验证码 修改邮箱(已经登陆修改) New </summary> <summary>发送验证码 修改邮箱(已经登陆修改) New </summary>
</member> </member>
<member name="M:IRaCIS.Application.Services.UserService.VerifyCanInitSetUserNameAndPwd(System.Guid)">
<summary>
Result 为true 的时候 允许提交设置
</summary>
<param name="userId"></param>
<returns></returns>
</member>
<member name="M:IRaCIS.Application.Services.UserService.ResetPassword(System.Guid)"> <member name="M:IRaCIS.Application.Services.UserService.ResetPassword(System.Guid)">
<summary> <summary>
重置密码为 默认密码 重置密码为 默认密码

View File

@ -18,7 +18,7 @@ namespace IRaCIS.Application.Services
Task AnolymousSendEmailForResetAccount(string emailAddress, int verificationCode); Task AnolymousSendEmailForResetAccount(string emailAddress, int verificationCode);
Task AddUserSendEmailAsync(Guid userId, string routeUrl); Task AddUserSendEmailAsync(Guid userId, string baseUrl, string routeUrl);
Task AdminResetPwdSendEmailAsync(Guid userId); Task AdminResetPwdSendEmailAsync(Guid userId);
@ -253,8 +253,9 @@ namespace IRaCIS.Application.Services
//添加用户发送邮件 //添加用户发送邮件
public async Task AddUserSendEmailAsync(Guid userId, string routeUrl) public async Task AddUserSendEmailAsync(Guid userId, string baseUrl, string routeUrl)
{ {
var sysUserInfo = (await _userRepository.Where(t => t.Id == userId).Include(t => t.UserTypeRole).FirstOrDefaultAsync()).IfNullThrowException(); var sysUserInfo = (await _userRepository.Where(t => t.Id == userId).Include(t => t.UserTypeRole).FirstOrDefaultAsync()).IfNullThrowException();
@ -282,6 +283,10 @@ namespace IRaCIS.Application.Services
routeUrl = routeUrl + "?UserId=" + sysUserInfo.Id + "&Email=" + sysUserInfo.EMail + "&UserName=" + sysUserInfo.UserName + "&UserType=" + sysUserInfo.UserTypeRole.UserTypeShortName + "&access_token=" + token; routeUrl = routeUrl + "?UserId=" + sysUserInfo.Id + "&Email=" + sysUserInfo.EMail + "&UserName=" + sysUserInfo.UserName + "&UserType=" + sysUserInfo.UserTypeRole.UserTypeShortName + "&access_token=" + token;
var domain=baseUrl.Substring(0,baseUrl.IndexOf("/login"));
var redirectUrl = $"{domain}/api/User/UserRedirect?url={ System.Web.HttpUtility.UrlEncode(routeUrl) }";
using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile)) using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile))
{ {
var templateInfo = SourceReader.ReadToEnd(); var templateInfo = SourceReader.ReadToEnd();
@ -291,7 +296,7 @@ namespace IRaCIS.Application.Services
sysUserInfo.FullName, sysUserInfo.FullName,
sysUserInfo.UserName, sysUserInfo.UserName,
sysUserInfo.UserTypeRole.UserTypeShortName, sysUserInfo.UserTypeRole.UserTypeShortName,
routeUrl redirectUrl
); );
} }
@ -389,6 +394,10 @@ namespace IRaCIS.Application.Services
var routeUrl = rootUrl + "?UserId=" + sysUserInfo.Id + "&Email=" + sysUserInfo.EMail + "&UserName=" + sysUserInfo.UserName + "&UserType=" + sysUserInfo.UserTypeRole.UserTypeShortName + "&access_token=" + token; var routeUrl = rootUrl + "?UserId=" + sysUserInfo.Id + "&Email=" + sysUserInfo.EMail + "&UserName=" + sysUserInfo.UserName + "&UserType=" + sysUserInfo.UserTypeRole.UserTypeShortName + "&access_token=" + token;
var domain = baseUrl.Substring(0, baseUrl.IndexOf("/login"));
var redirectUrl = $"{domain}/api/User/UserRedirect?url={ System.Web.HttpUtility.UrlEncode(routeUrl) }";
builder.HtmlBody = string.Format(templateInfo, builder.HtmlBody = string.Format(templateInfo,
sysUserInfo.FullName, sysUserInfo.FullName,
trialInfo.ExperimentName, trialInfo.ExperimentName,
@ -396,7 +405,7 @@ namespace IRaCIS.Application.Services
trialInfo.TrialCode, trialInfo.TrialCode,
sysUserInfo.UserName, sysUserInfo.UserName,
sysUserInfo.UserTypeRole.UserTypeShortName, sysUserInfo.UserTypeRole.UserTypeShortName,
sysUserInfo.IsFirstAdd ? routeUrl : baseUrl sysUserInfo.IsFirstAdd ? redirectUrl : baseUrl
); );
} }
@ -443,8 +452,12 @@ namespace IRaCIS.Application.Services
{ {
var templateInfo = SourceReader.ReadToEnd(); var templateInfo = SourceReader.ReadToEnd();
var domain = baseUrl.Substring(0, baseUrl.IndexOf("/login"));
var routeUrl = rootUrl + "?UserId=" + sysUserInfo.Id + "&Email=" + sysUserInfo.EMail + "&UserName=" + sysUserInfo.UserName + "&UserType=" + sysUserInfo.UserTypeRole.UserTypeShortName + "&access_token=" + token; var routeUrl = rootUrl + "?UserId=" + sysUserInfo.Id + "&Email=" + sysUserInfo.EMail + "&UserName=" + sysUserInfo.UserName + "&UserType=" + sysUserInfo.UserTypeRole.UserTypeShortName + "&access_token=" + token;
var redirectUrl = $"{domain}/api/User/UserRedirect?url={ System.Web.HttpUtility.UrlEncode(routeUrl) }";
builder.HtmlBody = string.Format(templateInfo, builder.HtmlBody = string.Format(templateInfo,
sysUserInfo.FullName, sysUserInfo.FullName,
trialInfo.ExperimentName, trialInfo.ExperimentName,
@ -452,7 +465,7 @@ namespace IRaCIS.Application.Services
trialInfo.TrialCode, trialInfo.TrialCode,
sysUserInfo.UserName, sysUserInfo.UserName,
sysUserInfo.UserTypeRole.UserTypeShortName, sysUserInfo.UserTypeRole.UserTypeShortName,
sysUserInfo.IsFirstAdd ? routeUrl : baseUrl sysUserInfo.IsFirstAdd ? redirectUrl : baseUrl
); );
} }

View File

@ -158,7 +158,6 @@ namespace IRaCIS.Core.Application.Service.Inspection
/// 传入参数记录ID /// 传入参数记录ID
/// </summary> /// </summary>
/// <param name="SignInfo"></param> /// <param name="SignInfo"></param>
/// <param name="response"></param>
/// <returns></returns> /// <returns></returns>
public async Task<Guid> RecordSing(SignDTO SignInfo) public async Task<Guid> RecordSing(SignDTO SignInfo)
{ {

View File

@ -159,7 +159,7 @@ namespace IRaCIS.Application.Contracts
public class UserCommand : UserInfo public class UserCommand : UserInfo
{ {
public string BaseUrl { get; set; } = string.Empty;
public string RouteUrl { get; set; } = string.Empty; public string RouteUrl { get; set; } = string.Empty;
//public string FirstName { get; set; } //public string FirstName { get; set; }

View File

@ -199,26 +199,23 @@ namespace IRaCIS.Application.Services
return ResponseOutput.Ok(); return ResponseOutput.Ok();
} }
/// <summary> ///// <summary>
/// Result 为true 的时候 认为链接没有失效 ///// Result 为true 的时候 认为链接没有失效
/// </summary> ///// </summary>
/// <param name="userId"></param> ///// <param name="userId"></param>
/// <returns></returns> ///// <returns></returns>
[HttpGet] //[HttpGet]
public async Task<IResponseOutput> VerifyCanInitSetUserNameAndPwd(Guid userId) //public async Task<IResponseOutput> VerifyCanInitSetUserNameAndPwd(Guid userId)
{ //{
return ResponseOutput.Ok(await _userRepository.AnyAsync(t => t.Id == userId && t.EmailToken == _userInfo.UserToken && t.IsFirstAdd)); // return ResponseOutput.Ok(await _userRepository.AnyAsync(t => t.Id == userId && t.EmailToken == _userInfo.UserToken && t.IsFirstAdd));
} //}
[HttpGet] [HttpGet]
public async Task<IResponseOutput> InitSetUserNameAndPwd(Guid userId, string newUserName, string newPWd) public async Task<IResponseOutput> InitSetUserNameAndPwd(Guid userId, string newUserName, string newPWd)
{ {
if (!await _userRepository.AnyAsync(t => t.Id == userId && t.EmailToken==_userInfo.UserToken && t.IsFirstAdd))
{
return ResponseOutput.NotOk("您的初始化链接已过期");
}
await VerifyUserPwdAsync(userId, newPWd); await VerifyUserPwdAsync(userId, newPWd);
@ -489,7 +486,7 @@ namespace IRaCIS.Application.Services
var success = await _userRepository.SaveChangesAsync(); var success = await _userRepository.SaveChangesAsync();
await _mailVerificationService.AddUserSendEmailAsync(saveItem.Id, userAddModel.RouteUrl); await _mailVerificationService.AddUserSendEmailAsync(saveItem.Id, userAddModel.BaseUrl, userAddModel.RouteUrl);
return ResponseOutput.Result(success, new UserAddedReturnDTO { Id = saveItem.Id, UserCode = saveItem.UserCode }); return ResponseOutput.Result(success, new UserAddedReturnDTO { Id = saveItem.Id, UserCode = saveItem.UserCode });

View File

@ -52,7 +52,6 @@ namespace IRaCIS.Core.Application.Contracts
/// 发送验证码 /// 发送验证码
/// </summary> /// </summary>
/// <param name="userInfo"></param> /// <param name="userInfo"></param>
/// <param name="_mailVerificationService"></param>
/// <returns></returns> /// <returns></returns>
[AllowAnonymous] [AllowAnonymous]
public async Task<IResponseOutput> SendVerifyCode(SiteSurveySendVerifyCode userInfo) public async Task<IResponseOutput> SendVerifyCode(SiteSurveySendVerifyCode userInfo)