hdong: merge code.
This commit is contained in:
parent
b9d7ff1023
commit
00b244227b
|
|
@ -18,8 +18,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
|
||||||
|
|
||||||
#region User
|
#region User
|
||||||
User? GetUserByEmail(string email) => throw new NotImplementedException();
|
User? GetUserByEmail(string email) => throw new NotImplementedException();
|
||||||
User? GetUserByPhone(string phone, string regionCode = "CN") => throw new NotImplementedException();
|
User? GetUserByPhone(string phone, string role = null, string regionCode = "CN") => throw new NotImplementedException();
|
||||||
User? GetAdminUserByPhone(string phone, string regionCode = "CN") => throw new NotImplementedException();
|
|
||||||
User? GetAffiliateUserByPhone(string phone) => throw new NotImplementedException();
|
User? GetAffiliateUserByPhone(string phone) => throw new NotImplementedException();
|
||||||
User? GetUserById(string id) => throw new NotImplementedException();
|
User? GetUserById(string id) => throw new NotImplementedException();
|
||||||
List<User> GetUserByIds(List<string> ids) => throw new NotImplementedException();
|
List<User> GetUserByIds(List<string> ids) => throw new NotImplementedException();
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ public class UserService : IUserService
|
||||||
var base64 = Encoding.UTF8.GetString(Convert.FromBase64String(authorization));
|
var base64 = Encoding.UTF8.GetString(Convert.FromBase64String(authorization));
|
||||||
var (id, password) = base64.SplitAsTuple(":");
|
var (id, password) = base64.SplitAsTuple(":");
|
||||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||||
var record = db.GetAdminUserByPhone(id);
|
var record = db.GetUserByPhone(id,"admin");
|
||||||
var isCanLogin = record != null && !record.IsDisabled
|
var isCanLogin = record != null && !record.IsDisabled
|
||||||
&& record.Type == UserType.Internal && new List<string>
|
&& record.Type == UserType.Internal && new List<string>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ public partial class MongoRepository
|
||||||
return user != null ? user.ToUser() : null;
|
return user != null ? user.ToUser() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User? GetUserByPhone(string phone, string regionCode = "CN")
|
public User? GetUserByPhone(string phone, string role = null, string regionCode = "CN")
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(phone))
|
if (string.IsNullOrWhiteSpace(phone))
|
||||||
{
|
{
|
||||||
|
|
@ -23,21 +23,8 @@ public partial class MongoRepository
|
||||||
string phoneSecond = phone.StartsWith("+86") ? phone.Replace("+86", "") : $"+86{phone}";
|
string 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
|
var user = _dc.Users.AsQueryable().FirstOrDefault(x => (x.Phone == phone || x.Phone == phoneSecond) && x.Type != UserType.Affiliate
|
||||||
&& (x.RegionCode == regionCode || string.IsNullOrWhiteSpace(x.RegionCode)));
|
&& (x.RegionCode == regionCode || string.IsNullOrWhiteSpace(x.RegionCode))
|
||||||
return user != null ? user.ToUser() : null;
|
&& (role == "admin" ? x.Role == "admin" || x.Role == "root" : true));
|
||||||
}
|
|
||||||
|
|
||||||
public User? GetAdminUserByPhone(string phone, string regionCode = "CN")
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(phone))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
string 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)) && (x.Role == "admin" || x.Role == "root"));
|
|
||||||
return user != null ? user.ToUser() : null;
|
return user != null ? user.ToUser() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue