Skip to content

Commit

Permalink
Feature(auth sdk): add SendMsgCodeForVerificationAsync、VerifyMsgCodeA…
Browse files Browse the repository at this point in the history
…sync、SendMsgCodeForUpdatePhoneNumberAsync (#218)

* refactor:refactor code

* feat(auth sdk):add SendMsgCodeForVerificationAsync、VerifyMsgCodeAsync、
SendMsgCodeForUpdatePhoneNumberAsync

* refactor:refactor code
  • Loading branch information
wuweilaiya authored Aug 23, 2022
1 parent ee11ccd commit ef6575d
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;

public class SendMobileVerificationCodeModel
public class SendMsgCodeForUpdatePhoneNumberModel
{
public Guid UserId { get; set; }

public string PhoneNumber { get; set; }

public SendMobileVerificationCodeModel(string phoneNumber)
public SendMsgCodeForUpdatePhoneNumberModel(Guid userId, string phoneNumber)
{
UserId = userId;
PhoneNumber = phoneNumber;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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 SendMsgCodeForVerificationModel
{
public Guid UserId { get; set; }

public SendMsgCodeForVerificationModel(Guid userId)
{
UserId = userId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class SubjectModel
{
public Guid SubjectId { get; set; }

public string Name { get; set; }
public string? Name { get; set; }

public string? DisplayName { get; set; }

Expand All @@ -21,12 +21,12 @@ public class SubjectModel

public SubjectModel()
{
Name = "";
DisplayName = "";
}

public SubjectModel(
Guid subjectId,
string name,
string? name,
string? displayName,
string? avatar,
string? phoneNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;

public class UpdateStaffBasicInfoModel
{
public Guid Id { get; set; }
public Guid UserId { get; set; }

public string DisplayName { get; set; } = "";

public string Avatar { get; set; } = "";
public string? PhoneNumber { get; set; }

public string PhoneNumber { get; set; } = "";

public string Email { get; set; } = "";
public string? Email { get; set; }

public GenderTypes Gender { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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 VerifyMsgCodeModel
{
public Guid UserId { get; set; }

public string Code { get; set; }

public VerifyMsgCodeModel(Guid userId, string code)
{
UserId = userId;
Code = code;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ public interface IUserService

Task UpdateStaffAvatarAsync(UpdateStaffAvatarModel staff);

Task SendMobileVerificationCodeAsync(SendMobileVerificationCodeModel code);
Task SendMsgCodeForVerificationAsync(SendMsgCodeForVerificationModel model);

Task UpdateUserPhoneNumberAsync(UpdateUserPhoneNumberModel user);
Task<bool> VerifyMsgCodeAsync(VerifyMsgCodeModel model);

Task SendMsgCodeForUpdatePhoneNumberAsync(SendMsgCodeForUpdatePhoneNumberModel model);

Task UpdatePhoneNumberAsync(UpdateUserPhoneNumberModel user);

Task UpdateBasicInfoAsync(UpdateUserBasicInfoModel user);

Expand All @@ -60,5 +64,7 @@ public interface IUserService
Task<T?> GetUserSystemDataAsync<T>(string systemId);

Task<bool> DisableUserAsync(DisableUserModel user);

Task<List<UserSimpleModel>> GetListByAccountAsync(IEnumerable<string> accounts);
}

Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,6 @@ public async Task UpdateStaffAvatarAsync(UpdateStaffAvatarModel staff)
await _caller.PutAsync(requestUri, staff);
}

public async Task SendMobileVerificationCodeAsync(SendMobileVerificationCodeModel code)
{
var requestUri = $"api/user/sendMobileVerificationCode";
await _caller.PostAsync(requestUri, code);
}

public async Task UpdateUserPhoneNumberAsync(UpdateUserPhoneNumberModel user)
{
var requestUri = $"api/user/updateUserPhoneNumber";
await _caller.PutAsync(requestUri, user);
}

public async Task UpdateBasicInfoAsync(UpdateUserBasicInfoModel user)
{
if (user.Id == Guid.Empty)
Expand All @@ -174,6 +162,10 @@ public async Task UpdateBasicInfoAsync(UpdateUserBasicInfoModel user)

public async Task UpdateStaffBasicInfoAsync(UpdateStaffBasicInfoModel staff)
{
if (staff.UserId == Guid.Empty)
{
staff.UserId = _userContext.GetUserId<Guid>();
}
var requestUri = $"api/staff/updateBasicInfo";
await _caller.PutAsync(requestUri, staff);
}
Expand Down Expand Up @@ -212,5 +204,45 @@ public async Task<List<UserSimpleModel>> GetListByAccountAsync(IEnumerable<strin
var requestUri = $"api/user/getListByAccount";
return await _caller.GetAsync<object, List<UserSimpleModel>>(requestUri, new { accounts = string.Join(',', accounts) }) ?? new();
}

public async Task SendMsgCodeForVerificationAsync(SendMsgCodeForVerificationModel model)
{
if (model.UserId == Guid.Empty)
{
model.UserId = _userContext.GetUserId<Guid>();
}
var requestUri = $"api/user/sendMsgCodeForVerification";
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 SendMsgCodeForUpdatePhoneNumberAsync(SendMsgCodeForUpdatePhoneNumberModel model)
{
if (model.UserId == Guid.Empty)
{
model.UserId = _userContext.GetUserId<Guid>();
}
var requestUri = $"api/user/sendMsgCodeForUpdatePhoneNumber";
await _caller.PostAsync(requestUri, model);
}

public async Task UpdatePhoneNumberAsync(UpdateUserPhoneNumberModel user)
{
if (user.Id == Guid.Empty)
{
user.Id = _userContext.GetUserId<Guid>();
}
var requestUri = $"api/user/updateUserPhoneNumber";
await _caller.PutAsync(requestUri, user);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,41 @@ public async Task TestUpdateStaffAvatarAsync()
}

[TestMethod]
public async Task TestSendMobileVerificationCodeAsync()
public async Task TestSendMsgCodeForVerificationAsync()
{
var code = new SendMobileVerificationCodeModel("15168440403");
var requestUri = $"api/user/sendMobileVerificationCode";
var code = new SendMsgCodeForVerificationModel(default);
var requestUri = $"api/user/sendMsgCodeForVerification";
var caller = new Mock<ICaller>();
caller.Setup(provider => provider.PostAsync(requestUri, code, true, default)).Verifiable();
var userContext = new Mock<IUserContext>();
var userService = new UserService(caller.Object, userContext.Object);
await userService.SendMobileVerificationCodeAsync(code);
await userService.SendMsgCodeForVerificationAsync(code);
caller.Verify(provider => provider.PostAsync(requestUri, code, true, default), Times.Once);
}

[TestMethod]
public async Task TestVerifyMsgCodeAsync()
{
var code = new VerifyMsgCodeModel(default, "283417");
var requestUri = $"api/user/verifyMsgCode";
var caller = new Mock<ICaller>();
caller.Setup(provider => provider.PostAsync<bool>(requestUri, code, default)).Verifiable();
var userContext = new Mock<IUserContext>();
var userService = new UserService(caller.Object, userContext.Object);
await userService.VerifyMsgCodeAsync(code);
caller.Verify(provider => provider.PostAsync<bool>(requestUri, code, default), Times.Once);
}

[TestMethod]
public async Task TestSendMsgCodeForUpdatePhoneNumberAsync()
{
var code = new SendMsgCodeForUpdatePhoneNumberModel(default, "283417");
var requestUri = $"api/user/sendMsgCodeForUpdatePhoneNumber";
var caller = new Mock<ICaller>();
caller.Setup(provider => provider.PostAsync(requestUri, code, true, default)).Verifiable();
var userContext = new Mock<IUserContext>();
var userService = new UserService(caller.Object, userContext.Object);
await userService.SendMsgCodeForUpdatePhoneNumberAsync(code);
caller.Verify(provider => provider.PostAsync(requestUri, code, true, default), Times.Once);
}

Expand All @@ -350,7 +376,7 @@ public async Task TestUpdateUserPhoneNumberAsync()
caller.Setup(provider => provider.PutAsync(requestUri, user, true, default)).Verifiable();
var userContext = new Mock<IUserContext>();
var userService = new UserService(caller.Object, userContext.Object);
await userService.UpdateUserPhoneNumberAsync(user);
await userService.UpdatePhoneNumberAsync(user);
caller.Verify(provider => provider.PutAsync(requestUri, user, true, default), Times.Once);
}

Expand Down Expand Up @@ -391,7 +417,7 @@ public async Task TestUpdateStaffBasicInfoAsync()
{
var staff = new UpdateStaffBasicInfoModel
{
Id = Guid.NewGuid(),
UserId = Guid.NewGuid(),
DisplayName = "test",
Gender = GenderTypes.Male,
PhoneNumber = "15168440403"
Expand Down

0 comments on commit ef6575d

Please sign in to comment.