fix: Update CreateUser API

This commit is contained in:
AnonymousDotNet 2024-10-21 19:59:05 +08:00
parent 78f5cd1751
commit 3e1fd96ef8
5 changed files with 15 additions and 7 deletions

View file

@ -21,6 +21,7 @@ public class User
public string Role { get; set; } = UserRole.User;
public string? VerificationCode { get; set; }
public bool Verified { get; set; }
public string? RegionCode { get; set; }
public string? AffiliateId { get; set; }
public bool IsDisabled { get; set; }
public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;

View file

@ -91,7 +91,8 @@ public class UserService : IUserService
record.Email = user.Email?.ToLower();
if (!string.IsNullOrWhiteSpace(user.Phone))
{
record.Phone = "+" + Regex.Match(user.Phone, @"\d+").Value;
//record.Phone = "+" + Regex.Match(user.Phone, @"\d+").Value;
record.Phone = Regex.Match(user.Phone, @"\d+").Value;
}
record.Salt = Guid.NewGuid().ToString("N");
record.Password = Utilities.HashTextMd5($"{user.Password}{record.Salt}");

View file

@ -5,18 +5,18 @@ namespace BotSharp.OpenAPI.ViewModels.Users;
public class UserCreationModel
{
public string? UserName { get; set; }
public string FirstName { get; set; } = string.Empty;
public string FirstName { get; set; } = string.Empty;
public string? LastName { get; set; }
public string? Email { get; set; }
public string? Phone { get; set; }
public string Password { get; set; } = string.Empty;
public string Type { get; set; } = UserType.Client;
public string Role { get; set; } = UserRole.User;
public string? RegionCode { get; set; }
public User ToUser()
{
return new User
{
return new User
{
UserName = UserName,
FirstName = FirstName,
LastName = LastName,
@ -24,7 +24,8 @@ public class UserCreationModel
Phone = Phone,
Password = Password,
Role = Role,
Type = Type
Type = Type,
RegionCode = RegionCode
};
}
}

View file

@ -18,6 +18,7 @@ public class UserDocument : MongoBase
public string Role { get; set; } = null!;
public string? VerificationCode { get; set; }
public bool Verified { get; set; }
public string? RegionCode { get; set; }
public string? AffiliateId { get; set; }
public bool IsDisabled { get; set; }
public DateTime CreatedTime { get; set; }
@ -43,6 +44,7 @@ public class UserDocument : MongoBase
IsDisabled = IsDisabled,
VerificationCode = VerificationCode,
Verified = Verified,
RegionCode = RegionCode,
};
}
}

View file

@ -70,6 +70,7 @@ public partial class MongoRepository
Type = user.Type,
VerificationCode = user.VerificationCode,
Verified = user.Verified,
RegionCode = user.RegionCode,
AffiliateId = user.AffiliateId,
IsDisabled = user.IsDisabled,
CreatedTime = DateTime.UtcNow,
@ -87,7 +88,9 @@ public partial class MongoRepository
.Set(x => x.Phone, user.Phone)
.Set(x => x.Salt, user.Salt)
.Set(x => x.Password, user.Password)
.Set(x => x.VerificationCode, user.VerificationCode);
.Set(x => x.VerificationCode, user.VerificationCode)
.Set(x => x.UpdatedTime, DateTime.UtcNow)
.Set(x => x.RegionCode, user.RegionCode);
_dc.Users.UpdateOne(filter, update);
}