Merge pull request #48 from Qtoss-AI/hdongDev
hdong: Fix phone exist check issues.
This commit is contained in:
commit
19662668af
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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; } = [];
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue