commit
8bd57139df
|
|
@ -30,10 +30,16 @@ public static class Utilities
|
|||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static (string, string) SplitAsTuple(this string str, string sep)
|
||||
public static (string, string, string) SplitAsTuple(this string str, string sep)
|
||||
{
|
||||
var splits = str.Split(sep);
|
||||
return (splits[0], splits[1]);
|
||||
|
||||
if (splits.Length == 2 || string.IsNullOrWhiteSpace(splits[2]))
|
||||
{
|
||||
return (splits[0], splits[1], "CN");
|
||||
}
|
||||
|
||||
return (splits[0], splits[1], splits[2]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ public class UserService : IUserService
|
|||
public async Task<Token?> GetAffiliateToken(string authorization)
|
||||
{
|
||||
var base64 = Encoding.UTF8.GetString(Convert.FromBase64String(authorization));
|
||||
var (id, password) = base64.SplitAsTuple(":");
|
||||
var (id, password, regionCode) = base64.SplitAsTuple(":");
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var record = db.GetAffiliateUserByPhone(id);
|
||||
var isCanLogin = record != null && !record.IsDisabled && record.Type == UserType.Affiliate;
|
||||
|
|
@ -170,7 +170,7 @@ public class UserService : IUserService
|
|||
public async Task<Token?> GetAdminToken(string authorization)
|
||||
{
|
||||
var base64 = Encoding.UTF8.GetString(Convert.FromBase64String(authorization));
|
||||
var (id, password) = base64.SplitAsTuple(":");
|
||||
var (id, password, regionCode) = base64.SplitAsTuple(":");
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var record = db.GetUserByPhone(id, type: UserType.Internal);
|
||||
var isCanLogin = record != null && !record.IsDisabled
|
||||
|
|
@ -210,13 +210,13 @@ public class UserService : IUserService
|
|||
public async Task<Token?> GetToken(string authorization)
|
||||
{
|
||||
var base64 = Encoding.UTF8.GetString(Convert.FromBase64String(authorization));
|
||||
var (id, password) = base64.SplitAsTuple(":");
|
||||
var (id, password, regionCode) = base64.SplitAsTuple(":");
|
||||
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var record = id.Contains("@") ? db.GetUserByEmail(id) : db.GetUserByUserName(id);
|
||||
if (record == null)
|
||||
{
|
||||
record = db.GetUserByPhone(id);
|
||||
record = db.GetUserByPhone(id, regionCode: regionCode);
|
||||
}
|
||||
|
||||
if (record != null && record.Type == UserType.Affiliate)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,14 @@ public partial class MongoRepository
|
|||
return null;
|
||||
}
|
||||
|
||||
phoneSecond = phone.StartsWith("+86") ? phone.Replace("+86", "") : $"+86{phone}";
|
||||
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))
|
||||
|
|
|
|||
Loading…
Reference in a new issue