diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs index 4ef68d88..003eddf4 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs @@ -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 userIds, bool isDisable) => throw new NotImplementedException(); #endregion diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs b/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs index d5547051..8123b272 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs @@ -19,7 +19,7 @@ public interface IUserService Task SendVerificationCodeResetPasswordLogin(); Task ResetUserPassword(User user); Task ModifyUserEmail(string email); - Task ModifyUserPhone(string phone); + Task ModifyUserPhone(string phone, string regionCode); Task UpdatePassword(string newPassword, string verificationCode); Task GetUserTokenExpires(); Task UpdateUsersIsDisable(List userIds, bool isDisable); diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index 43e2dfb7..a56c57a8 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -189,7 +189,7 @@ public class UserService : IUserService } var (token, jwt) = BuildToken(record); - + return await Task.FromResult(token); } @@ -618,8 +618,12 @@ public class UserService : IUserService return true; } - public async Task ModifyUserPhone(string phone) + public async Task ModifyUserPhone(string phone, string regionCode) { + if (string.IsNullOrWhiteSpace(regionCode)) + { + throw new Exception("regionCode is required"); + } var curUser = await GetMyProfile(); var db = _services.GetRequiredService(); var record = db.GetUserById(curUser.Id); @@ -631,6 +635,7 @@ public class UserService : IUserService } record.Phone = phone; + record.RegionCode = regionCode; var hooks = _services.GetServices(); foreach (var hook in hooks) @@ -638,7 +643,7 @@ public class UserService : IUserService await hook.UserUpdating(record); } - db.UpdateUserPhone(record.Id, record.Phone); + db.UpdateUserPhone(record.Id, record.Phone, regionCode); return true; } diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs index 67c0f4e3..253c19be 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs @@ -153,9 +153,9 @@ public class UserController : ControllerBase } [HttpPost("/user/phone/modify")] - public async Task ModifyUserPhone([FromQuery] string phone) + public async Task ModifyUserPhone([FromQuery] string phone, [FromQuery] string regionCode) { - return await _userService.ModifyUserPhone(phone); + return await _userService.ModifyUserPhone(phone, regionCode); } [HttpPost("/user/update/isdisable")] diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs index cf33312c..7b1f66db 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs @@ -128,11 +128,12 @@ 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.Filter.Eq(x => x.Id, userId); var update = Builders.Update.Set(x => x.Phone, phone) - .Set(x => x.UpdatedTime, DateTime.UtcNow); + .Set(x => x.UpdatedTime, DateTime.UtcNow) + .Set(x => x.RegionCode, regionCode); _dc.Users.UpdateOne(filter, update); }