diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs b/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs index 8f314ffa..4071790c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs @@ -10,4 +10,6 @@ public interface IUserService Task ActiveUser(UserActivationModel model); Task GetToken(string authorization); Task GetMyProfile(); + Task VerifyUserUnique(string userName); + Task VerifyEmailUnique(string email); } \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs b/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs index 92e3eacb..512d27c4 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs @@ -13,17 +13,14 @@ public class Pagination public int Size { - get + get { - if (_size <= 0) return 20; - if (_size > 100) return 100; - return _size; - } - set + } + set { _size = value; - } + } } /// diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index ae5220b9..19242e39 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -263,4 +263,30 @@ public class UserService : IUserService }; return token; } + + public async Task VerifyUserUnique(string userName) + { + if (string.IsNullOrEmpty(userName)) + return false; + + var db = _services.GetRequiredService(); + var user = db.GetUserByUserName(userName); + if (user == null) + return true; + + return false; + } + + public async Task VerifyEmailUnique(string email) + { + if (string.IsNullOrEmpty(email)) + return false; + + var db = _services.GetRequiredService(); + var emailName = db.GetUserByEmail(email); + if (emailName == null) + return true; + + return false; + } } diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs index 317d1fc9..e413724b 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs @@ -94,4 +94,16 @@ public class UserController : ControllerBase } return UserViewModel.FromUser(user); } + + [HttpGet("/user/name/existing")] + public async Task VerifyUserUnique([FromQuery] string userName) + { + return await _userService.VerifyUserUnique(userName); + } + + [HttpGet("/user/email/existing")] + public async Task VerifyEmailUnique([FromQuery] string email) + { + return await _userService.VerifyEmailUnique(email); + } }