Skip to content

Lida dev #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Infrastructure/BotSharp.Core/Infrastructures/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ public static string HashTextSha256(string text)
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public async Task<bool> UpdatePassword(string password, string verificationCode)
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;
Expand All @@ -170,7 +170,7 @@ public async Task<bool> UpdatePassword(string password, string verificationCode)
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
Expand Down Expand Up @@ -210,13 +210,13 @@ public async Task<bool> UpdatePassword(string password, string verificationCode)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down