hdong: roll back type user and remain new logic.
This commit is contained in:
parent
9ea04ecd78
commit
136f7eab67
|
|
@ -27,7 +27,8 @@ public interface IBotSharpRepository : IHaveServiceProvider
|
|||
|
||||
#region User
|
||||
User? GetUserByEmail(string email) => throw new NotImplementedException();
|
||||
User? GetUserByPhone(string phone, string source = "internal", string regionCode = "CN") => throw new NotImplementedException();
|
||||
User? GetUserByPhone(string phone, string type = UserType.Client, string regionCode = "CN") => throw new NotImplementedException();
|
||||
User? GetUserByPhoneV2(string phone, string source = UserType.Internal, 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();
|
||||
|
|
|
|||
|
|
@ -11,7 +11,24 @@ public partial class FileRepository
|
|||
return Users.FirstOrDefault(x => x.Email == email.ToLower());
|
||||
}
|
||||
|
||||
public User? GetUserByPhone(string phone, string? source = UserType.Internal, string regionCode = "CN")
|
||||
public User? GetUserByPhone(string phone, string? type = UserType.Client, string regionCode = "CN")
|
||||
{
|
||||
var query = Users.Where(x => x.Phone == phone);
|
||||
|
||||
if (!string.IsNullOrEmpty(type))
|
||||
{
|
||||
query = query.Where(x => x.Type == type);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(regionCode))
|
||||
{
|
||||
query = query.Where(x => x.RegionCode == regionCode);
|
||||
}
|
||||
|
||||
return query.FirstOrDefault();
|
||||
}
|
||||
|
||||
public User? GetUserByPhoneV2(string phone, string? source = UserType.Internal, string regionCode = "CN")
|
||||
{
|
||||
var query = Users.Where(x => x.Phone == phone);
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,11 @@ public class UserService : IUserService
|
|||
|
||||
if (record == null && !string.IsNullOrWhiteSpace(user.Phone))
|
||||
{
|
||||
//if (user.Type != "internal")
|
||||
//{
|
||||
// record = db.GetUserByPhoneV2(user.Phone, regionCode: (string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode));
|
||||
//}
|
||||
|
||||
record = db.GetUserByPhone(user.Phone, regionCode: (string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode));
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +183,7 @@ public class UserService : IUserService
|
|||
var base64 = Encoding.UTF8.GetString(Convert.FromBase64String(authorization));
|
||||
var (id, password, regionCode) = base64.SplitAsTuple(":");
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var record = db.GetUserByPhone(id, source: UserType.Internal);
|
||||
var record = db.GetUserByPhone(id, type: UserType.Internal);
|
||||
var isCanLogin = record != null && !record.IsDisabled
|
||||
&& record.Type == UserType.Internal && new List<string>
|
||||
{
|
||||
|
|
@ -477,11 +482,17 @@ public class UserService : IUserService
|
|||
var id = model.UserName;
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var record = id.Contains("@") ? db.GetUserByEmail(id) : db.GetUserByUserName(id);
|
||||
|
||||
if (record == null)
|
||||
{
|
||||
record = db.GetUserByPhone(id, regionCode: (string.IsNullOrWhiteSpace(model.RegionCode) ? "CN" : model.RegionCode));
|
||||
}
|
||||
|
||||
//if (record == null)
|
||||
//{
|
||||
// record = db.GetUserByPhoneV2(id, regionCode: (string.IsNullOrWhiteSpace(model.RegionCode) ? "CN" : model.RegionCode));
|
||||
//}
|
||||
|
||||
if (record == null)
|
||||
{
|
||||
return default;
|
||||
|
|
@ -621,21 +632,12 @@ public class UserService : IUserService
|
|||
public async Task<User> ResetVerificationCode(User user)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
User record = null;
|
||||
if (!string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.Phone))
|
||||
if (!string.IsNullOrWhiteSpace(user.Email) && !string.IsNullOrWhiteSpace(user.Phone))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(user.Phone))
|
||||
{
|
||||
record = db.GetUserByPhone(user.Phone, regionCode: user.RegionCode);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(user.Email))
|
||||
{
|
||||
record = db.GetUserByEmail(user.Email);
|
||||
}
|
||||
User? record = GetLoginUserByUniqueFilter(user, db);
|
||||
|
||||
if (record == null)
|
||||
{
|
||||
|
|
@ -650,6 +652,36 @@ public class UserService : IUserService
|
|||
return record;
|
||||
}
|
||||
|
||||
private static User? GetLoginUserByUniqueFilter(User user, IBotSharpRepository db)
|
||||
{
|
||||
User? record = null;
|
||||
if (!string.IsNullOrWhiteSpace(user.Id))
|
||||
{
|
||||
record = db.GetUserById(user.Id);
|
||||
}
|
||||
|
||||
if (record == null && !string.IsNullOrWhiteSpace(user.Phone))
|
||||
{
|
||||
record = db.GetUserByPhone(user.Phone, regionCode: string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode);
|
||||
//if (record == null)
|
||||
//{
|
||||
// record = db.GetUserByPhoneV2(user.Phone, regionCode: string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode);
|
||||
//}
|
||||
}
|
||||
|
||||
if (record == null && !string.IsNullOrWhiteSpace(user.Email))
|
||||
{
|
||||
record = db.GetUserByEmail(user.Email);
|
||||
}
|
||||
|
||||
if (record == null && !string.IsNullOrWhiteSpace(user.UserName))
|
||||
{
|
||||
record = db.GetUserByUserName(user.UserName);
|
||||
}
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
public async Task<bool> SendVerificationCodeLogin()
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
|
|
@ -689,17 +721,7 @@ public class UserService : IUserService
|
|||
}
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
|
||||
User? record = null;
|
||||
|
||||
if (!string.IsNullOrEmpty(user.Email))
|
||||
{
|
||||
record = db.GetUserByEmail(user.Email);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(user.Phone))
|
||||
{
|
||||
record = db.GetUserByPhone(user.Phone, regionCode: (string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode));
|
||||
}
|
||||
User? record = GetLoginUserByUniqueFilter(user, db);
|
||||
|
||||
if (record == null)
|
||||
{
|
||||
|
|
@ -724,20 +746,7 @@ public class UserService : IUserService
|
|||
}
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
|
||||
User? record = null;
|
||||
|
||||
if (!string.IsNullOrEmpty(user.Id))
|
||||
{
|
||||
record = db.GetUserById(user.Id);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(user.Phone))
|
||||
{
|
||||
record = db.GetUserByPhone(user.Phone, regionCode: (string.IsNullOrWhiteSpace(user.RegionCode) ? "CN" : user.RegionCode));
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(user.Email))
|
||||
{
|
||||
record = db.GetUserByEmail(user.Email);
|
||||
}
|
||||
User? record = GetLoginUserByUniqueFilter(user, db);
|
||||
|
||||
if (record == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,31 @@ public partial class MongoRepository
|
|||
return user != null ? user.ToUser() : null;
|
||||
}
|
||||
|
||||
public User? GetUserByPhone(string phone, string source = UserType.Internal, 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
|
||||
if (string.IsNullOrWhiteSpace(phone) || phone?.Length < 4)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (regionCode == "CN")
|
||||
{
|
||||
phoneSecond = (phone ?? "").StartsWith("+86") ? (phone ?? "").Replace("+86", "") : ($"+86{phone ?? ""}");
|
||||
}
|
||||
else
|
||||
{
|
||||
phoneSecond = (phone ?? "").Substring(regionCode == "US" ? 2 : 3);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public User? GetUserByPhoneV2(string phone, string source = UserType.Internal, string regionCode = "CN")
|
||||
{
|
||||
string phoneSecond = string.Empty;
|
||||
// if phone number length is less than 4, return null
|
||||
|
|
|
|||
Loading…
Reference in a new issue