Skip to content

Commit

Permalink
Feat/send email (#248)
Browse files Browse the repository at this point in the history
* feat:register login

* feat:add register

Co-authored-by: Mayue <[email protected]>
  • Loading branch information
MayueCif and Mayue authored Sep 19, 2022
1 parent 73b9326 commit 69229cd
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Enum;

public enum StaffTypes
{
InternalStaff = 1,
ExternalStaff
Internal = 1,
External
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public enum ThirdPartyIdpTypes
Customize = 1,
WeChat = 2,
GitHub = 3,
Ldap = 4,
Ldap = 4,
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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; }
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,9 @@ public interface IUserService
Task RemoveUserRolesAsync(RemoveUserRolesModel user);

Task SetCurrentTeamAsync(Guid teamId);

Task SendEmailAsync(SendEmailModel model);

Task RegisterAsync(RegisterModel model);
}

Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,6 @@ public async Task<List<UserSimpleModel>> GetListByAccountAsync(IEnumerable<strin
return await _caller.GetAsync<object, List<UserSimpleModel>>(requestUri, new { accounts = string.Join(',', accounts) }) ?? new();
}

public async Task SendMsgCodeAsync(SendMsgCodeModel model)
{
if (model.UserId == Guid.Empty)
{
model.UserId = _userContext.GetUserId<Guid>();
}
var requestUri = $"api/user/sendMsgCode";
await _caller.PostAsync(requestUri, model);
}

public async Task<bool> VerifyMsgCodeAsync(VerifyMsgCodeModel model)
{
if (model.UserId == Guid.Empty)
{
model.UserId = _userContext.GetUserId<Guid>();
}
var requestUri = $"api/user/verifyMsgCode";
return await _caller.PostAsync<bool>(requestUri, model);
}

public async Task<bool> UpdatePhoneNumberAsync(UpdateUserPhoneNumberModel user)
{
if (user.Id == Guid.Empty)
Expand Down Expand Up @@ -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<Guid>();
}
var requestUri = $"api/universal/send_sms";
await _caller.PostAsync(requestUri, model);
}

public async Task<bool> VerifyMsgCodeAsync(VerifyMsgCodeModel model)
{
if (model.UserId == Guid.Empty)
{
model.UserId = _userContext.GetUserId<Guid>();
}
var requestUri = $"api/user/verifyMsgCode";
return await _caller.PostAsync<bool>(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);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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<ICaller>();
caller.Setup(provider => provider.PostAsync(requestUri, code, true, default)).Verifiable();
var userContext = new Mock<IUserContext>();
Expand Down Expand Up @@ -597,6 +597,31 @@ public async Task TestSetCurrentTeamAsyncAsync()
caller.Verify(provider => provider.PutAsync(requestUri, It.IsAny<object>(), true, default), Times.Once);
}

[TestMethod]
public async Task TestSendEmailAsync()
{
var model = new SendEmailModel();
var requestUri = $"api/universal/send_email";
var caller = new Mock<ICaller>();
caller.Setup(provider => provider.PostAsync(requestUri, model, true, default)).Verifiable();
var userContext = new Mock<IUserContext>();
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<ICaller>();
caller.Setup(provider => provider.PostAsync(requestUri, model, true, default)).Verifiable();
var userContext = new Mock<IUserContext>();
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
Expand Down

0 comments on commit 69229cd

Please sign in to comment.