Merge pull request #25 from AnonymousDotNet/lida_dev

fix: 修复创建用户时判空BUG。
This commit is contained in:
Haiping 2024-10-12 08:56:20 -05:00 committed by GitHub
commit a3387fb1f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -33,7 +33,7 @@ public class UserService : IUserService
public async Task<User> CreateUser(User user)
{
string hasRegisterId = null;
if (string.IsNullOrEmpty(user.UserName))
if (string.IsNullOrWhiteSpace(user.UserName))
{
// generate unique name
var name = Nanoid.Generate("0123456789botsharp", 10);
@ -48,29 +48,24 @@ public class UserService : IUserService
User? record = null;
if (user.Phone != null)
if (!string.IsNullOrWhiteSpace(user.Phone))
{
record = db.GetUserByPhone(user.Phone);
}
if (record == null && user.Email != null)
if (record == null && !string.IsNullOrWhiteSpace(user.Email))
{
record = db.GetUserByEmail(user.Email);
}
if (record == null && user.UserName != null)
{
record = db.GetUserByUserName(user.UserName);
}
if (record != null)
{
hasRegisterId = record.Id;
}
if (string.IsNullOrEmpty(user.Id))
if (string.IsNullOrWhiteSpace(user.Id))
{
if (hasRegisterId != null)
if (!string.IsNullOrWhiteSpace(hasRegisterId))
{
user.Id = hasRegisterId;
}