From de3cba3e59adc4edd3772ecac04dda919a567547 Mon Sep 17 00:00:00 2001 From: AnonymousDotNet <18776095145@163.com> Date: Fri, 6 Sep 2024 18:15:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=8B=E6=9C=BA=E5=8F=B7?= =?UTF-8?q?=E5=92=8C=E9=82=AE=E7=AE=B1=E5=BF=98=E8=AE=B0=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=92=8C=E5=8F=91=E9=80=81=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81=E6=8E=A5=E5=8F=A3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/IBotSharpRepository.cs | 1 + .../FileRepository/FileRepository.User.cs | 5 +++ .../Users/Services/UserService.cs | 35 +++++++++++++++++-- .../Controllers/UserController.cs | 2 +- .../Repository/MongoRepository.User.cs | 6 ++++ 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs index 0af44080..92891652 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs @@ -19,6 +19,7 @@ public interface IBotSharpRepository #region User User? GetUserByEmail(string email) => throw new NotImplementedException(); + User? GetUserByPhone(string phone) => throw new NotImplementedException(); User? GetUserById(string id) => throw new NotImplementedException(); User? GetUserByUserName(string userName) => throw new NotImplementedException(); void CreateUser(User user) => throw new NotImplementedException(); diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs index 32a5127b..447bb82c 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs @@ -11,6 +11,11 @@ public partial class FileRepository return Users.FirstOrDefault(x => x.Email == email.ToLower()); } + public User? GetUserByPhone(string phone) + { + return Users.FirstOrDefault(x => x.Phone == phone); + } + public User? GetUserById(string id = null) { return Users.FirstOrDefault(x => x.Id == id || (x.ExternalId != null && x.ExternalId == id)); diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index 0e7f14ee..8160028e 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -325,8 +325,24 @@ public class UserService : IUserService public async Task SendVerificationCodeResetPassword(User user) { + if (!string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.Phone)) + { + return false; + } + var db = _services.GetRequiredService(); - var record = db.GetUserByEmail(user.Email); + + User? record = null; + + if (!string.IsNullOrEmpty(user.Email)) + { + record = db.GetUserByEmail(user.Email); + } + + if (!string.IsNullOrEmpty(user.Phone)) + { + record = db.GetUserByPhone(user.Phone); + } if (record == null) { return false; @@ -349,8 +365,23 @@ public class UserService : IUserService public async Task ResetUserPassword(User user) { + if (!string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.Phone)) + { + return false; + } var db = _services.GetRequiredService(); - var record = db.GetUserByEmail(user.Email); + + User? record = null; + + if (!string.IsNullOrEmpty(user.Email)) + { + record = db.GetUserByEmail(user.Email); + } + + if (!string.IsNullOrEmpty(user.Phone)) + { + record = db.GetUserByPhone(user.Phone); + } if (record == null) { diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs index a7d4c449..b4558557 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs @@ -110,7 +110,7 @@ public class UserController : ControllerBase } [AllowAnonymous] [HttpPost("/user/verifycode")] - public async Task SendVerificationCodeResetPassword([FromQuery] UserCreationModel user) + public async Task SendVerificationCodeResetPassword([FromBody] UserCreationModel user) { return await _userService.SendVerificationCodeResetPassword(user.ToUser()); } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs index 17c9d0cd..4f8da156 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs @@ -10,6 +10,12 @@ public partial class MongoRepository return user != null ? user.ToUser() : null; } + public User? GetUserByPhone(string phone) + { + var user = _dc.Users.AsQueryable().FirstOrDefault(x => x.Phone == phone); + return user != null ? user.ToUser() : null; + } + public User? GetUserById(string id) { var user = _dc.Users.AsQueryable()