commit
06275b86fb
|
|
@ -32,7 +32,7 @@ public interface IBotSharpRepository
|
|||
void UpdateUserVerificationCode(string userId, string verficationCode) => throw new NotImplementedException();
|
||||
void UpdateUserPassword(string userId, string password) => throw new NotImplementedException();
|
||||
void UpdateUserEmail(string userId, string email) => throw new NotImplementedException();
|
||||
void UpdateUserPhone(string userId, string Iphone) => throw new NotImplementedException();
|
||||
void UpdateUserPhone(string userId, string Iphone, string regionCode) => throw new NotImplementedException();
|
||||
void UpdateUserIsDisable(string userId, bool isDisable) => throw new NotImplementedException();
|
||||
void UpdateUsersIsDisable(List<string> userIds, bool isDisable) => throw new NotImplementedException();
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -17,4 +17,5 @@ public interface IUserIdentity
|
|||
string? EmployeeId { get; }
|
||||
string Type { get; }
|
||||
string Role { get; }
|
||||
string? RegionCode { get; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public interface IUserService
|
|||
Task<bool> SendVerificationCodeResetPasswordLogin();
|
||||
Task<bool> ResetUserPassword(User user);
|
||||
Task<bool> ModifyUserEmail(string email);
|
||||
Task<bool> ModifyUserPhone(string phone);
|
||||
Task<bool> ModifyUserPhone(string phone, string regionCode);
|
||||
Task<bool> UpdatePassword(string newPassword, string verificationCode);
|
||||
Task<DateTime> GetUserTokenExpires();
|
||||
Task<bool> UpdateUsersIsDisable(List<string> userIds, bool isDisable);
|
||||
|
|
|
|||
|
|
@ -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; } = "CN";
|
||||
public string? AffiliateId { get; set; }
|
||||
public string? EmployeeId { get; set; }
|
||||
public bool IsDisabled { get; set; }
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class UserIdentity : IUserIdentity
|
|||
get
|
||||
{
|
||||
_contextAccessor.HttpContext.Request.Headers.TryGetValue("User-Language", out var languages);
|
||||
return languages.FirstOrDefault() ?? "en-US";
|
||||
return languages.FirstOrDefault() ?? "en-US";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -81,4 +81,7 @@ public class UserIdentity : IUserIdentity
|
|||
|
||||
[JsonPropertyName("role")]
|
||||
public string? Role => _claims?.FirstOrDefault(x => x.Type == ClaimTypes.Role)?.Value;
|
||||
|
||||
[JsonPropertyName("regionCode")]
|
||||
public string? RegionCode => _claims?.FirstOrDefault(x => x.Type == "regionCode")?.Value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}");
|
||||
|
|
@ -188,7 +189,7 @@ public class UserService : IUserService
|
|||
}
|
||||
|
||||
var (token, jwt) = BuildToken(record);
|
||||
|
||||
|
||||
return await Task.FromResult(token);
|
||||
}
|
||||
|
||||
|
|
@ -266,7 +267,8 @@ public class UserService : IUserService
|
|||
ExternalId = user.ExternalId,
|
||||
Password = user.Password,
|
||||
Type = user.Type,
|
||||
Role = user.Role
|
||||
Role = user.Role,
|
||||
RegionCode = user.RegionCode
|
||||
};
|
||||
await CreateUser(record);
|
||||
}
|
||||
|
|
@ -316,7 +318,8 @@ public class UserService : IUserService
|
|||
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
|
||||
new Claim("phone", user.Phone ?? string.Empty),
|
||||
new Claim("affiliateId", user.AffiliateId ?? string.Empty),
|
||||
new Claim("employeeId", user.EmployeeId ?? string.Empty)
|
||||
new Claim("employeeId", user.EmployeeId ?? string.Empty),
|
||||
new Claim("regionCode", user.RegionCode ?? "CN")
|
||||
};
|
||||
|
||||
var validators = _services.GetServices<IAuthenticationHook>();
|
||||
|
|
@ -617,8 +620,12 @@ public class UserService : IUserService
|
|||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> ModifyUserPhone(string phone)
|
||||
public async Task<bool> ModifyUserPhone(string phone, string regionCode)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(regionCode))
|
||||
{
|
||||
throw new Exception("regionCode is required");
|
||||
}
|
||||
var curUser = await GetMyProfile();
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var record = db.GetUserById(curUser.Id);
|
||||
|
|
@ -630,6 +637,9 @@ public class UserService : IUserService
|
|||
}
|
||||
|
||||
record.Phone = phone;
|
||||
record.RegionCode = regionCode;
|
||||
record.UserName = phone;
|
||||
record.FirstName = phone;
|
||||
|
||||
var hooks = _services.GetServices<IAuthenticationHook>();
|
||||
foreach (var hook in hooks)
|
||||
|
|
@ -637,7 +647,7 @@ public class UserService : IUserService
|
|||
await hook.UserUpdating(record);
|
||||
}
|
||||
|
||||
db.UpdateUserPhone(record.Id, record.Phone);
|
||||
db.UpdateUserPhone(record.Id, record.Phone, regionCode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,9 +153,9 @@ public class UserController : ControllerBase
|
|||
}
|
||||
|
||||
[HttpPost("/user/phone/modify")]
|
||||
public async Task<bool> ModifyUserPhone([FromQuery] string phone)
|
||||
public async Task<bool> ModifyUserPhone([FromQuery] string phone, [FromQuery] string regionCode = "CN")
|
||||
{
|
||||
return await _userService.ModifyUserPhone(phone);
|
||||
return await _userService.ModifyUserPhone(phone, regionCode);
|
||||
}
|
||||
|
||||
[HttpPost("/user/update/isdisable")]
|
||||
|
|
|
|||
|
|
@ -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; } = "CN";
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
using System.Data;
|
||||
|
||||
namespace BotSharp.OpenAPI.ViewModels.Users;
|
||||
|
||||
public class UserResetPasswordModel
|
||||
|
|
@ -8,6 +6,7 @@ public class UserResetPasswordModel
|
|||
public string? Phone { get; set; }
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public string VerificationCode { get; set; }
|
||||
public string RegionCode { get; set; } = "CN";
|
||||
|
||||
public User ToUser()
|
||||
{
|
||||
|
|
@ -16,7 +15,8 @@ public class UserResetPasswordModel
|
|||
Email = Email,
|
||||
Phone = Phone,
|
||||
Password = Password,
|
||||
VerificationCode = VerificationCode
|
||||
VerificationCode = VerificationCode,
|
||||
RegionCode = RegionCode
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class UserViewModel
|
|||
FirstName = user.FirstName,
|
||||
LastName = user.LastName,
|
||||
Email = user.Email,
|
||||
Phone = user.Phone,
|
||||
Phone = user.Phone.Substring(0, 3) == "+86" ? user.Phone.Substring(3) : user.Phone,
|
||||
Type = user.Type,
|
||||
Role = user.Role,
|
||||
Source = user.Source,
|
||||
|
|
|
|||
|
|
@ -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 string? EmployeeId { get; set; }
|
||||
public bool IsDisabled { get; set; }
|
||||
|
|
@ -45,6 +46,7 @@ public class UserDocument : MongoBase
|
|||
IsDisabled = IsDisabled,
|
||||
VerificationCode = VerificationCode,
|
||||
Verified = Verified,
|
||||
RegionCode = RegionCode,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,12 @@ public partial class MongoRepository
|
|||
|
||||
public User? GetUserByPhone(string phone)
|
||||
{
|
||||
var user = _dc.Users.AsQueryable().FirstOrDefault(x => x.Phone == phone && x.Type != UserType.Affiliate);
|
||||
string phoneSecond = string.Empty;
|
||||
if (phone.Substring(0, 3) != "+86")
|
||||
{
|
||||
phoneSecond = $"+86{phone}";
|
||||
}
|
||||
var user = _dc.Users.AsQueryable().FirstOrDefault(x => (x.Phone == phone || x.Phone == phoneSecond) && x.Type != UserType.Affiliate);
|
||||
return user != null ? user.ToUser() : null;
|
||||
}
|
||||
|
||||
|
|
@ -70,6 +75,7 @@ public partial class MongoRepository
|
|||
Type = user.Type,
|
||||
VerificationCode = user.VerificationCode,
|
||||
Verified = user.Verified,
|
||||
RegionCode = user.RegionCode,
|
||||
AffiliateId = user.AffiliateId,
|
||||
EmployeeId = user.EmployeeId,
|
||||
IsDisabled = user.IsDisabled,
|
||||
|
|
@ -88,7 +94,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);
|
||||
}
|
||||
|
||||
|
|
@ -125,11 +133,14 @@ public partial class MongoRepository
|
|||
_dc.Users.UpdateOne(filter, update);
|
||||
}
|
||||
|
||||
public void UpdateUserPhone(string userId, string phone)
|
||||
public void UpdateUserPhone(string userId, string phone, string regionCode)
|
||||
{
|
||||
var filter = Builders<UserDocument>.Filter.Eq(x => x.Id, userId);
|
||||
var update = Builders<UserDocument>.Update.Set(x => x.Phone, phone)
|
||||
.Set(x => x.UpdatedTime, DateTime.UtcNow);
|
||||
.Set(x => x.UpdatedTime, DateTime.UtcNow)
|
||||
.Set(x => x.RegionCode, regionCode)
|
||||
.Set(x => x.UserName, phone)
|
||||
.Set(x => x.FirstName, phone);
|
||||
_dc.Users.UpdateOne(filter, update);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue