From fc4ef6b939a0d654813d0f41780f3a459b6db6c3 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Mon, 24 Feb 2025 13:24:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E8=BF=87=E6=9C=9F+=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E4=B8=8D=E5=85=81=E8=AE=B8=E5=BF=98=E8=AE=B0=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ExtraController.cs | 13 ++++++++++++- .../Service/Management/UserService.cs | 19 +++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/IRaCIS.Core.API/Controllers/ExtraController.cs b/IRaCIS.Core.API/Controllers/ExtraController.cs index f737fa776..79b7ad5d0 100644 --- a/IRaCIS.Core.API/Controllers/ExtraController.cs +++ b/IRaCIS.Core.API/Controllers/ExtraController.cs @@ -25,6 +25,7 @@ using RestSharp; using RestSharp.Authenticators; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Net; using System.Net.Http; @@ -200,10 +201,20 @@ namespace IRaCIS.Api.Controllers var errorUrl = domainStrList[0] + "//" + domainStrList[2] + "/error"; + if (lang == "zh") + { + CultureInfo.CurrentCulture = new CultureInfo(StaticData.CultureInfo.zh_CN); + CultureInfo.CurrentUICulture = new CultureInfo(StaticData.CultureInfo.zh_CN); + } + else + { + CultureInfo.CurrentCulture = new CultureInfo(StaticData.CultureInfo.en_US); + CultureInfo.CurrentUICulture = new CultureInfo(StaticData.CultureInfo.en_US); + } if (!await _useRepository.AnyAsync(t => t.Id == Guid.Parse(userId) && t.EmailToken == token && t.IsFirstAdd)) { - decodeUrl = errorUrl + $"?lang={lang}&ErrorMessage={System.Web.HttpUtility.UrlEncode(lang == "zh" ? "您的初始化链接已过期" : "Error!The initialization link has expired.")} "; + decodeUrl = errorUrl + $"?lang={lang}&ErrorMessage={System.Web.HttpUtility.UrlEncode(I18n.T("UserRedirect_InitializationLinkExpire"))} "; } return Redirect(decodeUrl); diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index 6bf2ce9ea..701bd3a85 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -334,14 +334,21 @@ namespace IRaCIS.Core.Application.Service } ////查找改邮箱或者手机的用户 - var exist = await _identityUserRepository.AnyAsync(t => t.EMail == email && t.Status == UserStateEnum.Enable); + var existUser = await _identityUserRepository.Where(t => t.EMail == email && t.Status == UserStateEnum.Enable).FirstOrDefaultAsync(); - if (!exist) + if (existUser==null) { //---邮箱错误。 return ResponseOutput.NotOk(_localizer["User_EmailError"]); } + else + { + if (existUser.IsFirstAdd && existUser.UserName.IsNullOrEmpty()) + { + return ResponseOutput.NotOk(_localizer["User_Notinitialized"]); + } + } //验证码 6位 @@ -937,7 +944,7 @@ namespace IRaCIS.Core.Application.Service var userLoginReturnModel = new IRCLoginReturnDTO(); - var loginUser = await _identityUserRepository.Where(u => u.UserName.Equals(userName) && u.Password == password).ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync(); + var loginUser = await _identityUserRepository.Where(u => (u.UserName.Equals(userName) || u.EMail.Equals(userName)) && u.Password == password).ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync(); var existUserLoginInfo = await _identityUserRepository.Where(u => u.UserName == userName).Select(t => new { t.LastLoginIP, t.LastChangePassWordTime, t.Id }).FirstOrDefaultAsync(); @@ -1013,13 +1020,13 @@ namespace IRaCIS.Core.Application.Service await _identityUserRepository.BatchUpdateNoTrackingAsync(x => x.Id == loginUser.IdentityUserId, x => new IdentityUser() { LastLoginTime = DateTime.Now, - LastLoginIP=_userInfo.IP, + LastLoginIP = _userInfo.IP, }); if (loginUser.Status == 0) { - await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = loginUser.IdentityUserId, ActionUserName = userName, OptType = UserOptType.LoginLockedAccount, IsLoginUncommonly = isLoginUncommonly }, true); + await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = loginUser.IdentityUserId, ActionUserName = loginUser.UserName, OptType = UserOptType.LoginLockedAccount, IsLoginUncommonly = isLoginUncommonly }, true); //---该用户已经被禁用。 return ResponseOutput.NotOk(_localizer["User_Disabled"], new IRCLoginReturnDTO()); @@ -1029,7 +1036,7 @@ namespace IRaCIS.Core.Application.Service await _fusionCache.SetAsync(cacheKey, 0, TimeSpan.FromMinutes(lockoutMinutes)); - await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = loginUser.IdentityUserId, OptType = UserOptType.Login, IsLoginUncommonly = isLoginUncommonly }, true); + await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = loginUser.IdentityUserId, ActionUserName=loginUser.UserName, OptType = UserOptType.Login, IsLoginUncommonly = isLoginUncommonly }, true); userLoginReturnModel.BasicInfo = loginUser;