XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension.NetCore.ServerInteractive

[DLL] Server interaction extension, including user identity verification and querying in conjunction with AutoConfig

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFEExtension.NetCore.ServerInteractive

修复用户登录查找方式

26b3805
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

4 个文件 +25 -11
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Helpers/UserHelper.cs +6 -5
@@ -3,7 +3,6 @@ using System.Text.Json;
3 3 using XFEExtension.NetCore.ServerInteractive.Interfaces;
4 4 using XFEExtension.NetCore.ServerInteractive.Models.ServerModels;
5 5 using XFEExtension.NetCore.ServerInteractive.Models.UserModels;
6 using XFEExtension.NetCore.StringExtension.Json;
7 6
8 7 namespace XFEExtension.NetCore.ServerInteractive.Utilities.Helpers;
9 8
@@ -23,19 +22,21 @@ public static class UserHelper
23 22 /// <summary>
24 23 /// 获取用户(通过Session)
25 24 /// </summary>
26 /// <param name="sessionId"></param>
25 /// <param name="session"></param>
27 26 /// <param name="computerInfo"></param>
28 27 /// <param name="ipAddress"></param>
29 28 /// <param name="encryptedUserLoginModels"></param>
30 29 /// <param name="userInfoList"></param>
31 30 /// <param name="user"></param>
32 31 /// <returns></returns>
33 public static UserOperateResult GetUser(string sessionId, string computerInfo, string ipAddress, IEnumerable<EncryptedUserLoginModel> encryptedUserLoginModels, IEnumerable<IUserFaceInfo> userInfoList, out IUserInfo? user)
32 public static UserOperateResult GetUser(string session, string computerInfo, string ipAddress, IEnumerable<EncryptedUserLoginModel> encryptedUserLoginModels, IEnumerable<IUserFaceInfo> userInfoList, out IUserInfo? user)
34 33 {
35 34 user = null;
36 if (encryptedUserLoginModels.FirstOrDefault(user => user.UserLoginModel.ComputerInfo == computerInfo) is not EncryptedUserLoginModel encryptedUserLoginModel)
35 var split = session.Split('|');
36 if (encryptedUserLoginModels.FirstOrDefault(user => user.UserLoginModel.UID == split[0]) is not EncryptedUserLoginModel encryptedUserLoginModel)
37 37 return UserOperateResult.LoginExpired;
38 if (Decrypt<UserLoginModel>(encryptedUserLoginModel.Key, sessionId) is not UserLoginModel targetUserLoginModel || encryptedUserLoginModel.UserLoginModel.UID != targetUserLoginModel.UID)
38 if (encryptedUserLoginModel.UserLoginModel.ComputerInfo != computerInfo) return UserOperateResult.LoginExpired;
39 if (Decrypt<UserLoginModel>(encryptedUserLoginModel.Key, split[1]) is not UserLoginModel targetUserLoginModel || encryptedUserLoginModel.UserLoginModel.UID != targetUserLoginModel.UID)
39 40 return UserOperateResult.UserNotFound;
40 41 if (encryptedUserLoginModel.UserLoginModel.EndDateTime < DateTime.Now || (encryptedUserLoginModel.UserLoginModel.LastIPAddress != ipAddress && !((encryptedUserLoginModel.UserLoginModel.LastIPAddress == "127.0.0.1" || encryptedUserLoginModel.UserLoginModel.LastIPAddress == "::1") && (ipAddress == "127.0.0.1" || ipAddress == "::1"))))
41 42 return UserOperateResult.LoginExpired;
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Server/Services/CoreService/UserLoginService.cs +13 -2
@@ -26,7 +26,18 @@ public class UserLoginService<T> : ServerCoreUserServiceBase where T : IUserFace
26 26 if (computerInfo.IsNullOrWhiteSpace()) r.Error("电脑信息不能为空", HttpStatusCode.BadRequest);
27 27 var user = UserHelper.GetUser(queryableJsonNode["account"], queryableJsonNode["password"], GetUserFunction(), r);
28 28 Console.WriteLine($"{account}({computerInfo})");
29 var userLoginList = GetEncryptedUserLoginModelFunction().Where(userLogin => userLogin.UserLoginModel.ComputerInfo == computerInfo);
29 30 var userLogin = GetEncryptedUserLoginModelFunction().FirstOrDefault(userLogin => userLogin.UserLoginModel.UID == user.ID);
31 //for (int i = 0; i < userLoginList.Count(); i++)
32 //{
33 // var otherLogin = userLoginList.ElementAt(i);
34 // if (otherLogin.UserLoginModel.UID != user.ID)
35 // {
36 // RemoveEncryptedUserLoginModelFunction(otherLogin);
37 // i--;
38 // Console.WriteLine($"[DEBUG]删除用户 {otherLogin.UserLoginModel.UID} 在电脑 {computerInfo} 上的登录状态");
39 // }
40 //}
30 41 if (userLogin is null)
31 42 {
32 43 userLogin = new EncryptedUserLoginModel
@@ -44,7 +55,7 @@ public class UserLoginService<T> : ServerCoreUserServiceBase where T : IUserFace
44 55 Console.WriteLine($"[DEBUG]用户 {user.UserName} 登录成功,登录到期时间 {userLogin.UserLoginModel.EndDateTime}");
45 56 await r.Args.ReplyAndClose(new
46 57 {
47 session = UserHelper.Encrypt(userLogin.Key, userLogin.UserLoginModel),
58 session = $"{user.ID}|{UserHelper.Encrypt(userLogin.Key, userLogin.UserLoginModel)}",
48 59 expireDate = userLogin.UserLoginModel.EndDateTime,
49 60 userInfo = (T)user
50 61 }.ToJson(), HttpStatusCode.OK);
@@ -57,7 +68,7 @@ public class UserLoginService<T> : ServerCoreUserServiceBase where T : IUserFace
57 68 Console.WriteLine($"[DEBUG]用户 {user.UserName} 已登录,登录到期时间:{userLogin.UserLoginModel.EndDateTime}");
58 69 await r.Args.ReplyAndClose(new
59 70 {
60 session = UserHelper.Encrypt(userLogin.Key, userLogin.UserLoginModel),
71 session = $"{user.ID}|{UserHelper.Encrypt(userLogin.Key, userLogin.UserLoginModel)}",
61 72 expireDate = userLogin.UserLoginModel.EndDateTime,
62 73 userInfo = (T)user
63 74 }.ToJson(), HttpStatusCode.OK);
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Server/Services/CoreService/UserReloginService.cs +4 -2
@@ -24,8 +24,10 @@ public class UserReloginService<T> : ServerCoreUserServiceBase where T : IUserFa
24 24 var computerInfo = queryableJsonNode["computerInfo"].ToString();
25 25 if (session.IsNullOrWhiteSpace()) r.Error("Session值不能为空", HttpStatusCode.BadRequest);
26 26 if (computerInfo.IsNullOrWhiteSpace()) r.Error("电脑信息不能为空", HttpStatusCode.BadRequest);
27 if (GetEncryptedUserLoginModelFunction().FirstOrDefault(user => user.UserLoginModel.ComputerInfo == computerInfo) is not EncryptedUserLoginModel encryptedUserLoginModel) throw r.GetError("Session值不正确或已过期", HttpStatusCode.Forbidden);
28 var userLoginModel = UserHelper.Decrypt<UserLoginModel>(encryptedUserLoginModel.Key, session);
27 var split = session.Split('|');
28 if (GetEncryptedUserLoginModelFunction().FirstOrDefault(user => user.UserLoginModel.UID == split[0]) is not EncryptedUserLoginModel encryptedUserLoginModel) throw r.GetError("Session值不正确或已过期", HttpStatusCode.Forbidden);
29 if (encryptedUserLoginModel.UserLoginModel.ComputerInfo != computerInfo) r.Error("电脑信息不匹配", HttpStatusCode.Forbidden);
30 var userLoginModel = UserHelper.Decrypt<UserLoginModel>(encryptedUserLoginModel.Key, split[1]);
29 31 if (userLoginModel.UID.IsNullOrWhiteSpace() || userLoginModel.UID != encryptedUserLoginModel.UserLoginModel.UID)
30 32 r.Error("登录用户ID不匹配", HttpStatusCode.Forbidden);
31 33 var user = UserHelper.GetUser(userLoginModel.UID, GetUserFunction()) ?? throw r.GetError("用户ID未注册", HttpStatusCode.Forbidden);
Modified XFEExtension.NetCore.ServerInteractive/XFEExtension.NetCore.ServerInteractive.csproj +2 -2
@@ -5,7 +5,7 @@
5 5 <ImplicitUsings>enable</ImplicitUsings>
6 6 <Nullable>enable</Nullable>
7 7 <GenerateDocumentationFile>True</GenerateDocumentationFile>
8 <Version>1.0.5</Version>
8 <Version>1.0.6</Version>
9 9 <Title>XFEExtension.NetCore.ServerInteractive</Title>
10 10 <RepositoryUrl>https://github.com/XFEstudio/XFEExtension.NetCore.ServerInteractive</RepositoryUrl>
11 11 <AnalysisLevel>latest</AnalysisLevel>
@@ -21,7 +21,7 @@
21 21 <PackageReleaseNotes>
22 22 ## 调整
23 23
24 修复用户登录模型的Json转换问题
24 修复用户登录查找方式
25 25
26 26 ## 新增
27 27