fix: Add regionCode to GetUserByUserName API

This commit is contained in:
AnonymousDotNet 2024-12-14 17:19:40 +08:00
parent d87afc7151
commit f5b2999408
4 changed files with 13 additions and 13 deletions

View file

@ -32,7 +32,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
User? GetUserById(string id) => throw new NotImplementedException();
List<User> GetUserByIds(List<string> ids) => throw new NotImplementedException();
List<User> GetUsersByAffiliateId(string affiliateId) => throw new NotImplementedException();
User? GetUserByUserName(string userName) => throw new NotImplementedException();
User? GetUserByUserName(string userName, string regionCode = "CN") => throw new NotImplementedException();
Dashboard? GetDashboard(string id = null) => throw new NotImplementedException();
void CreateUser(User user) => throw new NotImplementedException();
void UpdateExistUser(string userId, User user) => throw new NotImplementedException();

View file

@ -48,9 +48,9 @@ public partial class FileRepository
return Users.Where(x => x.AffiliateId == affiliateId).ToList();
}
public User? GetUserByUserName(string userName = null)
public User? GetUserByUserName(string userName = null, string regionCode = "CN")
{
return Users.FirstOrDefault(x => x.UserName == userName.ToLower());
return Users.FirstOrDefault(x => x.UserName == userName.ToLower() && x.RegionCode == regionCode.ToLower());
}
public Dashboard? GetDashboard(string id = null)

View file

@ -50,7 +50,7 @@ public class UserService : IUserService
if (!string.IsNullOrWhiteSpace(user.UserName))
{
record = db.GetUserByUserName(user.UserName);
record = db.GetUserByUserName(user.UserName, regionCode: user.RegionCode);
}
if (record != null && record.Verified)
@ -214,7 +214,7 @@ public class UserService : IUserService
var (id, password, regionCode) = base64.SplitAsTuple(":");
var db = _services.GetRequiredService<IBotSharpRepository>();
var record = id.Contains("@") ? db.GetUserByEmail(id) : db.GetUserByUserName(id);
var record = id.Contains("@") ? db.GetUserByEmail(id) : db.GetUserByUserName(id, regionCode: regionCode);
if (record == null)
{
record = db.GetUserByPhone(id, regionCode: regionCode);
@ -384,7 +384,7 @@ public class UserService : IUserService
}
else if (_user.UserName != null)
{
user = db.GetUserByUserName(_user.UserName);
user = db.GetUserByUserName(_user.UserName, _user.RegionCode);
}
else if (_user.Email != null)
{
@ -471,7 +471,7 @@ public class UserService : IUserService
{
var id = model.UserName;
var db = _services.GetRequiredService<IBotSharpRepository>();
var record = id.Contains("@") ? db.GetUserByEmail(id) : db.GetUserByUserName(id);
var record = id.Contains("@") ? db.GetUserByEmail(id) : db.GetUserByUserName(id, regionCode: (string.IsNullOrWhiteSpace(model.RegionCode) ? "CN" : model.RegionCode));
if (record == null)
{
record = db.GetUserByPhone(id, regionCode: (string.IsNullOrWhiteSpace(model.RegionCode) ? "CN" : model.RegionCode));
@ -515,7 +515,7 @@ public class UserService : IUserService
var db = _services.GetRequiredService<IBotSharpRepository>();
var user = db.GetUserByUserName(userName);
var user = db.GetUserByUserName(userName, regionCode: "CN");
if (user != null && user.Verified)
{
return true;

View file

@ -61,9 +61,9 @@ public partial class MongoRepository
return users?.Any() == true ? users.Select(x => x.ToUser()).ToList() : new List<User>();
}
public User? GetUserByUserName(string userName)
public User? GetUserByUserName(string userName, string regionCode = "CN")
{
var user = _dc.Users.AsQueryable().FirstOrDefault(x => x.UserName == userName.ToLower());
var user = _dc.Users.AsQueryable().FirstOrDefault(x => x.UserName == userName.ToLower() && x.RegionCode == regionCode.ToLower());
return user != null ? user.ToUser() : null;
}
@ -331,10 +331,10 @@ public partial class MongoRepository
.FirstOrDefault(x => x.Id == userId || (x.ExternalId != null && x.ExternalId == userId));
if (user == null) return;
var curDash = user.Dashboard ?? new Dashboard();
curDash.ConversationList.Add(new DashboardConversation
{
curDash.ConversationList.Add(new DashboardConversation
{
Id = Guid.NewGuid().ToString(),
ConversationId = conversationId
ConversationId = conversationId
});
var filter = Builders<UserDocument>.Filter.Eq(x => x.Id, userId);