From a261605bde1035702067431114c4cd6f4cdc614c Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Mon, 30 May 2022 11:28:01 +0800 Subject: [PATCH] =?UTF-8?q?=E9=93=BE=E6=8E=A5=E7=82=B9=E5=87=BB=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E5=90=8E=E7=AB=AF=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ExtraController.cs | 23 ++++++++++++---- .../IRaCIS.Core.Application.xml | 9 ------- .../Service/Common/MailService.cs | 23 ++++++++++++---- .../Service/Inspection/InspectionService.cs | 1 - .../Service/Management/DTO/UserModel.cs | 2 +- .../Service/Management/UserService.cs | 27 +++++++++---------- .../SiteSurvey/TrialSiteSurveyService.cs | 1 - 7 files changed, 49 insertions(+), 37 deletions(-) diff --git a/IRaCIS.Core.API/Controllers/ExtraController.cs b/IRaCIS.Core.API/Controllers/ExtraController.cs index e6412f877..ec41c5392 100644 --- a/IRaCIS.Core.API/Controllers/ExtraController.cs +++ b/IRaCIS.Core.API/Controllers/ExtraController.cs @@ -19,6 +19,10 @@ using Microsoft.AspNetCore.Http; using IRaCIS.Core.Application.Interfaces; using System.Threading.Tasks; 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 { @@ -188,17 +192,26 @@ namespace IRaCIS.Api.Controllers - //外部用户 邮件链接调用 以及跳转逻辑 - [HttpGet("trialExternalUser/ExternalUserJoinTrial")] + [HttpGet("User/UserRedirect")] [AllowAnonymous] - public async Task ExternalUserJoinTrial([FromServices] ITrialExternalUserService _trialExternalUserService, Guid trialId, Guid trialExternalUserId, string url) + public async Task UserRedirect([FromServices] IRepository _userRepository, string url) { - await _trialExternalUserService.UserConfirmJoinTrial(trialId, trialExternalUserId); - 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); } diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index e14ac2980..c30551941 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -390,7 +390,6 @@ 传入参数记录ID - @@ -971,7 +970,6 @@ 发送验证码 - @@ -2354,13 +2352,6 @@ 发送验证码 修改邮箱(已经登陆修改) New - - - Result 为true 的时候 允许提交设置 - - - - 重置密码为 默认密码 diff --git a/IRaCIS.Core.Application/Service/Common/MailService.cs b/IRaCIS.Core.Application/Service/Common/MailService.cs index 2d4fbbbaf..1eb3f4437 100644 --- a/IRaCIS.Core.Application/Service/Common/MailService.cs +++ b/IRaCIS.Core.Application/Service/Common/MailService.cs @@ -18,7 +18,7 @@ namespace IRaCIS.Application.Services Task AnolymousSendEmailForResetAccount(string emailAddress, int verificationCode); - Task AddUserSendEmailAsync(Guid userId, string routeUrl); + Task AddUserSendEmailAsync(Guid userId, string baseUrl, string routeUrl); 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(); @@ -281,6 +282,10 @@ namespace IRaCIS.Application.Services 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; + + 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)) { @@ -291,7 +296,7 @@ namespace IRaCIS.Application.Services sysUserInfo.FullName, sysUserInfo.UserName, 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 domain = baseUrl.Substring(0, baseUrl.IndexOf("/login")); + + var redirectUrl = $"{domain}/api/User/UserRedirect?url={ System.Web.HttpUtility.UrlEncode(routeUrl) }"; + builder.HtmlBody = string.Format(templateInfo, sysUserInfo.FullName, trialInfo.ExperimentName, @@ -396,7 +405,7 @@ namespace IRaCIS.Application.Services trialInfo.TrialCode, sysUserInfo.UserName, sysUserInfo.UserTypeRole.UserTypeShortName, - sysUserInfo.IsFirstAdd ? routeUrl : baseUrl + sysUserInfo.IsFirstAdd ? redirectUrl : baseUrl ); } @@ -443,8 +452,12 @@ namespace IRaCIS.Application.Services { 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 redirectUrl = $"{domain}/api/User/UserRedirect?url={ System.Web.HttpUtility.UrlEncode(routeUrl) }"; + builder.HtmlBody = string.Format(templateInfo, sysUserInfo.FullName, trialInfo.ExperimentName, @@ -452,7 +465,7 @@ namespace IRaCIS.Application.Services trialInfo.TrialCode, sysUserInfo.UserName, sysUserInfo.UserTypeRole.UserTypeShortName, - sysUserInfo.IsFirstAdd ? routeUrl : baseUrl + sysUserInfo.IsFirstAdd ? redirectUrl : baseUrl ); } diff --git a/IRaCIS.Core.Application/Service/Inspection/InspectionService.cs b/IRaCIS.Core.Application/Service/Inspection/InspectionService.cs index 94c7c8eaa..a897daf77 100644 --- a/IRaCIS.Core.Application/Service/Inspection/InspectionService.cs +++ b/IRaCIS.Core.Application/Service/Inspection/InspectionService.cs @@ -158,7 +158,6 @@ namespace IRaCIS.Core.Application.Service.Inspection /// 传入参数记录ID /// /// - /// /// public async Task RecordSing(SignDTO SignInfo) { diff --git a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs index bb1740ad2..54b1c0a20 100644 --- a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs +++ b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs @@ -159,7 +159,7 @@ namespace IRaCIS.Application.Contracts public class UserCommand : UserInfo { - + public string BaseUrl { get; set; } = string.Empty; public string RouteUrl { get; set; } = string.Empty; //public string FirstName { get; set; } diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index 8f0695d6b..9af2c2f2a 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -199,26 +199,23 @@ namespace IRaCIS.Application.Services return ResponseOutput.Ok(); } - /// - /// Result 为true 的时候 认为链接没有失效 - /// - /// - /// - [HttpGet] - public async Task VerifyCanInitSetUserNameAndPwd(Guid userId) - { - return ResponseOutput.Ok(await _userRepository.AnyAsync(t => t.Id == userId && t.EmailToken == _userInfo.UserToken && t.IsFirstAdd)); - } + ///// + ///// Result 为true 的时候 认为链接没有失效 + ///// + ///// + ///// + //[HttpGet] + //public async Task VerifyCanInitSetUserNameAndPwd(Guid userId) + //{ + // return ResponseOutput.Ok(await _userRepository.AnyAsync(t => t.Id == userId && t.EmailToken == _userInfo.UserToken && t.IsFirstAdd)); + //} [HttpGet] public async Task 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); @@ -489,7 +486,7 @@ namespace IRaCIS.Application.Services 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 }); diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs index 7cf2fa569..42e64c81a 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs @@ -52,7 +52,6 @@ namespace IRaCIS.Core.Application.Contracts /// 发送验证码 /// /// - /// /// [AllowAnonymous] public async Task SendVerifyCode(SiteSurveySendVerifyCode userInfo)