diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/SendEmailTypes.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/SendEmailTypes.cs new file mode 100644 index 000000000..64c56f67a --- /dev/null +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/SendEmailTypes.cs @@ -0,0 +1,12 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Enum; + +public enum SendEmailTypes +{ + Undefined, + Verifiy, + Register, + ForgotPassword +} diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/StaffTypes.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/StaffTypes.cs index 5662a2328..7207b7a5f 100644 --- a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/StaffTypes.cs +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/StaffTypes.cs @@ -5,6 +5,6 @@ namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Enum; public enum StaffTypes { - InternalStaff = 1, - ExternalStaff + Internal = 1, + External } diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/ThirdPartyIdpTypes.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/ThirdPartyIdpTypes.cs index 474ad99c9..43b87ad78 100644 --- a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/ThirdPartyIdpTypes.cs +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/ThirdPartyIdpTypes.cs @@ -8,5 +8,5 @@ public enum ThirdPartyIdpTypes Customize = 1, WeChat = 2, GitHub = 3, - Ldap = 4, + Ldap = 4, } diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/UserRegisterTypes.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/UserRegisterTypes.cs new file mode 100644 index 000000000..80122e923 --- /dev/null +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/UserRegisterTypes.cs @@ -0,0 +1,12 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Enum; + +public enum UserRegisterTypes +{ + Undefined, + Account, + PhoneNumber, + Email +} diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/RegisterModel.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/RegisterModel.cs new file mode 100644 index 000000000..b9136f14f --- /dev/null +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/RegisterModel.cs @@ -0,0 +1,23 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model; + +public class RegisterModel +{ + public UserRegisterTypes UserRegisterType { get; set; } + + public string Email { get; set; } + + public string Password { get; set; } + + public string PhoneNumber { get; set; } + + public string Code { get; set; } + + public string Account { get; set; } + + public string Avatar { get; set; } + + public string DisplayName { get; set; } +} diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SendEmailModel.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SendEmailModel.cs new file mode 100644 index 000000000..c9a276586 --- /dev/null +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SendEmailModel.cs @@ -0,0 +1,21 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model; + +public class SendEmailModel +{ + public string Email { get; set; } = ""; + + public SendEmailTypes SendEmailType { get; set; } = SendEmailTypes.Undefined; + + public SendEmailModel() + { + } + + public SendEmailModel(string email, SendEmailTypes sendEmailType) + { + Email = email; + SendEmailType = sendEmailType; + } +} diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/IUserService.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/IUserService.cs index 3ddfa7270..bf08d31c2 100644 --- a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/IUserService.cs +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/IUserService.cs @@ -74,5 +74,9 @@ public interface IUserService Task RemoveUserRolesAsync(RemoveUserRolesModel user); Task SetCurrentTeamAsync(Guid teamId); + + Task SendEmailAsync(SendEmailModel model); + + Task RegisterAsync(RegisterModel model); } diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/UserService.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/UserService.cs index 4a399976d..7ee1cb577 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/UserService.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/UserService.cs @@ -207,26 +207,6 @@ public async Task> GetListByAccountAsync(IEnumerable>(requestUri, new { accounts = string.Join(',', accounts) }) ?? new(); } - public async Task SendMsgCodeAsync(SendMsgCodeModel model) - { - if (model.UserId == Guid.Empty) - { - model.UserId = _userContext.GetUserId(); - } - var requestUri = $"api/user/sendMsgCode"; - await _caller.PostAsync(requestUri, model); - } - - public async Task VerifyMsgCodeAsync(VerifyMsgCodeModel model) - { - if (model.UserId == Guid.Empty) - { - model.UserId = _userContext.GetUserId(); - } - var requestUri = $"api/user/verifyMsgCode"; - return await _caller.PostAsync(requestUri, model); - } - public async Task UpdatePhoneNumberAsync(UpdateUserPhoneNumberModel user) { if (user.Id == Guid.Empty) @@ -289,5 +269,37 @@ public async Task SetCurrentTeamAsync(Guid teamId) TeamId = teamId }); } + + public async Task SendMsgCodeAsync(SendMsgCodeModel model) + { + if (model.UserId == Guid.Empty) + { + model.UserId = _userContext.GetUserId(); + } + var requestUri = $"api/universal/send_sms"; + await _caller.PostAsync(requestUri, model); + } + + public async Task VerifyMsgCodeAsync(VerifyMsgCodeModel model) + { + if (model.UserId == Guid.Empty) + { + model.UserId = _userContext.GetUserId(); + } + var requestUri = $"api/user/verifyMsgCode"; + return await _caller.PostAsync(requestUri, model); + } + + public async Task SendEmailAsync(SendEmailModel model) + { + var requestUri = $"api/universal/send_email"; + await _caller.PostAsync(requestUri, model); + } + + public async Task RegisterAsync(RegisterModel model) + { + var requestUri = $"api/user/register"; + await _caller.PostAsync(requestUri, model); + } } diff --git a/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Auth.Tests/UserServiceTest.cs b/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Auth.Tests/UserServiceTest.cs index 173a8bd1b..e907b254c 100644 --- a/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Auth.Tests/UserServiceTest.cs +++ b/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Auth.Tests/UserServiceTest.cs @@ -345,7 +345,7 @@ public async Task TestUpdateStaffAvatarAsync() public async Task SendMsgCodeAsync() { var code = new SendMsgCodeModel(); - var requestUri = $"api/user/sendMsgCode"; + var requestUri = $"api/universal/send_sms"; var caller = new Mock(); caller.Setup(provider => provider.PostAsync(requestUri, code, true, default)).Verifiable(); var userContext = new Mock(); @@ -597,6 +597,31 @@ public async Task TestSetCurrentTeamAsyncAsync() caller.Verify(provider => provider.PutAsync(requestUri, It.IsAny(), true, default), Times.Once); } + [TestMethod] + public async Task TestSendEmailAsync() + { + var model = new SendEmailModel(); + var requestUri = $"api/universal/send_email"; + var caller = new Mock(); + caller.Setup(provider => provider.PostAsync(requestUri, model, true, default)).Verifiable(); + var userContext = new Mock(); + var userService = new UserService(caller.Object, userContext.Object); + await userService.SendEmailAsync(model); + caller.Verify(provider => provider.PostAsync(requestUri, model, true, default), Times.Once); + } + + [TestMethod] + public async Task TestRegisterAsync() + { + var model = new RegisterModel(); + var requestUri = $"api/user/register"; + var caller = new Mock(); + caller.Setup(provider => provider.PostAsync(requestUri, model, true, default)).Verifiable(); + var userContext = new Mock(); + var userService = new UserService(caller.Object, userContext.Object); + await userService.RegisterAsync(model); + caller.Verify(provider => provider.PostAsync(requestUri, model, true, default), Times.Once); + } } class SystemData