diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs index f3859a3a6..33be79c18 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs @@ -26,7 +26,7 @@ public interface IBotSharpRepository : IHaveServiceProvider #region User User? GetUserByEmail(string email) => throw new NotImplementedException(); - User? GetUserByPhone(string phone, string role = null, string regionCode = "CN") => throw new NotImplementedException(); + User? GetUserByPhone(string phone, string type = "client", string regionCode = "CN") => throw new NotImplementedException(); User? GetAffiliateUserByPhone(string phone) => throw new NotImplementedException(); User? GetUserById(string id) => throw new NotImplementedException(); List GetUserByIds(List ids) => throw new NotImplementedException(); diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs index 68e76cd83..962bc9412 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs @@ -11,13 +11,13 @@ public partial class FileRepository return Users.FirstOrDefault(x => x.Email == email.ToLower()); } - public User? GetUserByPhone(string phone, string? role = null, string regionCode = "CN") + public User? GetUserByPhone(string phone, string? type = "client", string regionCode = "CN") { var query = Users.Where(x => x.Phone == phone); - if (!string.IsNullOrEmpty(role)) + if (!string.IsNullOrEmpty(type)) { - query = query.Where(x => x.Role == role); + query = query.Where(x => x.Type == type); } if (!string.IsNullOrEmpty(regionCode)) diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index 9e74d961b..45f22937c 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -172,7 +172,7 @@ public async Task UpdatePassword(string password, string verificationCode) 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, type: "internal"); 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 e999e0348..d72247aab 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 type = "client", string regionCode = "CN") { string phoneSecond = string.Empty; // if phone number length is less than 4, return null @@ -24,9 +24,9 @@ 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)); + var user = _dc.Users.AsQueryable().FirstOrDefault(x => (x.Phone == phone || x.Phone == phoneSecond) + && (x.RegionCode == regionCode || string.IsNullOrWhiteSpace(x.RegionCode)) + && (x.Type == type)); return user != null ? user.ToUser() : null; } @@ -245,7 +245,7 @@ public PagedItems GetUsers(UserFilter filter) user.AgentActions = agentActions; return user; } - + var agentIds = userAgents.Select(x => x.AgentId)?.Distinct().ToList(); if (!agentIds.IsNullOrEmpty()) {