Merge pull request #48 from Qtoss-AI/hdongDev

hdong: Fix phone exist check issues.
This commit is contained in:
Haiping 2024-11-25 07:34:35 -06:00 committed by GitHub
commit 19662668af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 11 additions and 7 deletions

View file

@ -5,6 +5,7 @@ using BotSharp.Abstraction.Roles.Models;
using BotSharp.Abstraction.Shared;
using BotSharp.Abstraction.Tasks.Models;
using BotSharp.Abstraction.Translation.Models;
using BotSharp.Abstraction.Users.Enums;
using BotSharp.Abstraction.Users.Models;
using BotSharp.Abstraction.VectorStorage.Models;
@ -26,7 +27,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
#region User
User? GetUserByEmail(string email) => throw new NotImplementedException();
User? GetUserByPhone(string phone, string type = "client", string regionCode = "CN") => throw new NotImplementedException();
User? GetUserByPhone(string phone, string type = UserType.Client, string regionCode = "CN") => throw new NotImplementedException();
User? GetAffiliateUserByPhone(string phone) => throw new NotImplementedException();
User? GetUserById(string id) => throw new NotImplementedException();
List<User> GetUserByIds(List<string> ids) => throw new NotImplementedException();

View file

@ -23,6 +23,7 @@ public class User
public bool Verified { get; set; }
public string RegionCode { get; set; } = "CN";
public string? AffiliateId { get; set; }
public string? AffiliateCode { get; set; }
public string? EmployeeId { get; set; }
public bool IsDisabled { get; set; }
public IEnumerable<string> Permissions { get; set; } = [];

View file

@ -11,7 +11,7 @@ public partial class FileRepository
return Users.FirstOrDefault(x => x.Email == email.ToLower());
}
public User? GetUserByPhone(string phone, string? type = "client", string regionCode = "CN")
public User? GetUserByPhone(string phone, string? type = UserType.Client, string regionCode = "CN")
{
var query = Users.Where(x => x.Phone == phone);

View file

@ -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<IBotSharpRepository>();
var record = db.GetUserByPhone(id, type: "internal");
var record = db.GetUserByPhone(id, type: UserType.Internal);
var isCanLogin = record != null && !record.IsDisabled
&& record.Type == UserType.Internal && new List<string>
{
@ -548,7 +548,7 @@ public class UserService : IUserService
}
var db = _services.GetRequiredService<IBotSharpRepository>();
var UserByphone = db.GetUserByPhone(phone, regionCode);
var UserByphone = db.GetUserByPhone(phone, regionCode: regionCode);
if (UserByphone != null && UserByphone.Verified)
{
return true;

View file

@ -13,6 +13,7 @@ public class UserCreationModel
public string Type { get; set; } = UserType.Client;
public string Role { get; set; } = UserRole.User;
public string RegionCode { get; set; } = "CN";
public string? AffiliateCode { get; set; }
public User ToUser()
{
return new User
@ -25,7 +26,8 @@ public class UserCreationModel
Password = Password,
Role = Role,
Type = Type,
RegionCode = RegionCode
RegionCode = RegionCode,
AffiliateCode = AffiliateCode
};
}
}

View file

@ -13,7 +13,7 @@ public partial class MongoRepository
return user != null ? user.ToUser() : null;
}
public User? GetUserByPhone(string phone, string type = "client", string regionCode = "CN")
public User? GetUserByPhone(string phone, string type = UserType.Client, string regionCode = "CN")
{
string phoneSecond = string.Empty;
// if phone number length is less than 4, return null
@ -24,7 +24,7 @@ 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)
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;