From 93a4bd95a95c0b55a7cc00fe16e34c20a3e14fe9 Mon Sep 17 00:00:00 2001 From: YouWeiDH Date: Thu, 21 Nov 2024 17:38:16 +0800 Subject: [PATCH] hdong: split some phone number from client and admin. --- .../BotSharp.Core/Users/Services/UserService.cs | 2 +- .../Repository/MongoRepository.User.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index 9e74d961..02fccb40 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -172,7 +172,7 @@ public class UserService : IUserService var base64 = Encoding.UTF8.GetString(Convert.FromBase64String(authorization)); var (id, password) = base64.SplitAsTuple(":"); var db = _services.GetRequiredService(); - var record = db.GetUserByPhone(id,"admin"); + var record = db.GetUserByPhone(id, role: "admin"); var isCanLogin = record != null && !record.IsDisabled && record.Type == UserType.Internal && new List { diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs index e999e034..d71157c3 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs @@ -13,7 +13,7 @@ public partial class MongoRepository return user != null ? user.ToUser() : null; } - public User? GetUserByPhone(string phone, string role = null, string regionCode = "CN") + public User? GetUserByPhone(string phone, string role = "client", string regionCode = "CN") { string phoneSecond = string.Empty; // if phone number length is less than 4, return null @@ -25,8 +25,8 @@ public partial class MongoRepository phoneSecond = phone.StartsWith("+86") ? phone.Replace("+86", "") : $"+86{phone}"; var user = _dc.Users.AsQueryable().FirstOrDefault(x => (x.Phone == phone || x.Phone == phoneSecond) && x.Type != UserType.Affiliate - && (x.RegionCode == regionCode || string.IsNullOrWhiteSpace(x.RegionCode)) - && (role == "admin" ? x.Role == "admin" || x.Role == "root" : true)); + && (x.RegionCode == regionCode || string.IsNullOrWhiteSpace(x.RegionCode)) + && (role == "client" ? x.Role == "client" || x.Role == "user" : role == "admin" ? x.Role == "admin" || x.Role == "root" : true)); return user != null ? user.ToUser() : null; } @@ -245,7 +245,7 @@ public partial class MongoRepository user.AgentActions = agentActions; return user; } - + var agentIds = userAgents.Select(x => x.AgentId)?.Distinct().ToList(); if (!agentIds.IsNullOrEmpty()) {