Merge branch 'test' of http://git.buggoglobal.com/java-project/baiyue-firstleg into dev
This commit is contained in:
@@ -22,7 +22,7 @@ public interface IamOnboardingClient {
|
||||
@PathVariable("authUserId") Long authUserId);
|
||||
|
||||
record OnboardingRequest(Long authUserId, String displayName, String companyName,
|
||||
String legalPerson, String legalPhone, String contactEmail,
|
||||
String legalPerson, String administratorPhone, String contactEmail,
|
||||
String countryCode, String address) { }
|
||||
|
||||
record OnboardingResponse(Long tenantId, Long membershipId, String tenantStatus,
|
||||
|
||||
@@ -77,7 +77,7 @@ public class AuthController {
|
||||
@SecurityRequirements
|
||||
@PostMapping("/register")
|
||||
@Operation(summary = "Merchant registration / 客户注册",
|
||||
description = "Create a login account and an enterprise profile awaiting the required business license and legal-person ID; other qualification files are optional.")
|
||||
description = "Create a login account and enterprise profile. The supplied phone initializes both the first administrator login phone and company contact phone; they are maintained independently after creation. Only the business license and unified social credit code are required for review; legal-person ID is optional.")
|
||||
public ApiResponse<MerchantRegisterResponse> register(@Valid @RequestBody MerchantRegisterRequest request) {
|
||||
return ApiResponse.success(registrationService.register(request));
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public final class AccountManagementDtos {
|
||||
@NotBlank @Pattern(regexp = "^1[3-9]\\d{9}$") String phone,
|
||||
@NotBlank String currentPassword) { }
|
||||
public record UpdateAccountPhoneRequest(
|
||||
@NotBlank @Pattern(regexp = "^1[3-9]\\d{9}$") String phone) { }
|
||||
@Pattern(regexp = "^1[3-9]\\d{9}$") String phone) { }
|
||||
public record UpdateAccountProfileRequest(@NotBlank @Size(max = 64) String displayName) { }
|
||||
public record UpdateAccountStatusRequest(@NotBlank String status) { }
|
||||
public record RevokeAccountSessionsRequest(
|
||||
|
||||
@@ -13,7 +13,8 @@ public record MerchantRegisterRequest(
|
||||
@NotBlank @Size(max = 64) String displayName,
|
||||
@NotBlank @Size(max = 128) String companyName,
|
||||
@NotBlank @Size(max = 64) String legalPerson,
|
||||
@NotBlank @Pattern(regexp = "^1[3-9]\\d{9}$") String legalPhone,
|
||||
@Schema(description = "首个企业管理员的登录手机号;注册时同时初始化企业联系电话,创建后两者独立维护")
|
||||
@NotBlank @Pattern(regexp = "^1[3-9]\\d{9}$") String phone,
|
||||
@Email @Size(max = 128) String contactEmail,
|
||||
@Size(min = 2, max = 2) String countryCode,
|
||||
@Size(max = 255) String address
|
||||
|
||||
@@ -151,9 +151,9 @@ public class AccountManagementService {
|
||||
description = "同步受管账号手机号", captureAfter = false)
|
||||
public void updatePhone(Long accountId, UpdateAccountPhoneRequest request) {
|
||||
AuthAccount account = required(accountId);
|
||||
String phone = request.phone().trim();
|
||||
String phone = request.phone() == null ? null : request.phone().trim();
|
||||
if (Objects.equals(account.getPhone(), phone)) return;
|
||||
if (repository.existsByPhoneForOtherAccount(phone, accountId)) {
|
||||
if (phone != null && repository.existsByPhoneForOtherAccount(phone, accountId)) {
|
||||
throw new BizException(ResultCode.CONFLICT, "手机号已存在");
|
||||
}
|
||||
account.setPhone(phone);
|
||||
|
||||
@@ -38,7 +38,7 @@ public class MerchantRegistrationService {
|
||||
if (accountRepository.existsByUsername(request.username())) {
|
||||
throw new BizException(ResultCode.CONFLICT, "用户名已存在");
|
||||
}
|
||||
if (accountRepository.existsByPhone(request.legalPhone())) {
|
||||
if (accountRepository.existsByPhone(request.phone())) {
|
||||
throw new BizException(ResultCode.CONFLICT, "手机号已存在");
|
||||
}
|
||||
long accountId = IdWorker.getId();
|
||||
@@ -49,7 +49,7 @@ public class MerchantRegistrationService {
|
||||
try {
|
||||
var response = onboardingClient.register(internalToken,
|
||||
new IamOnboardingClient.OnboardingRequest(accountId, request.displayName(),
|
||||
request.companyName(), request.legalPerson(), request.legalPhone(),
|
||||
request.companyName(), request.legalPerson(), request.phone(),
|
||||
request.contactEmail(), request.countryCode(), request.address()));
|
||||
if (response == null) {
|
||||
throw new BizException(ResultCode.SERVICE_UNAVAILABLE, "IAM registration failed");
|
||||
@@ -84,7 +84,7 @@ public class MerchantRegistrationService {
|
||||
AuthAccount account = new AuthAccount();
|
||||
account.setId(accountId);
|
||||
account.setUsername(request.username());
|
||||
account.setPhone(request.legalPhone());
|
||||
account.setPhone(request.phone());
|
||||
account.setPasswordHash(passwordHash);
|
||||
account.setDisplayName(request.displayName());
|
||||
account.setAccountStatus("ACTIVE");
|
||||
|
||||
@@ -7,11 +7,21 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class LoginIdentifierContractTest {
|
||||
|
||||
@Test
|
||||
void registrationExposesAnAccountPhoneInsteadOfALegalPersonPhoneAlias() {
|
||||
var componentNames = Arrays.stream(MerchantRegisterRequest.class.getRecordComponents())
|
||||
.map(component -> component.getName())
|
||||
.toList();
|
||||
|
||||
assertThat(componentNames).contains("phone").doesNotContain("legalPhone");
|
||||
}
|
||||
|
||||
@Test
|
||||
void mainlandMobileRuleRejectsPlaceholderNumbersAcrossJavaAndSql() throws Exception {
|
||||
try (var factory = Validation.buildDefaultValidatorFactory()) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.baiyue.auth.dto.AccountManagementDtos.ChangePasswordRequest;
|
||||
import com.baiyue.auth.dto.AccountManagementDtos.ForcedPasswordChangeRequest;
|
||||
import com.baiyue.auth.dto.AccountManagementDtos.CreateAccountRequest;
|
||||
import com.baiyue.auth.dto.AccountManagementDtos.UpdateAccountProfileRequest;
|
||||
import com.baiyue.auth.dto.AccountManagementDtos.UpdateAccountPhoneRequest;
|
||||
import com.baiyue.auth.dto.AccountManagementDtos.UpdateAccountStatusRequest;
|
||||
import com.baiyue.auth.dto.AccountManagementDtos.UpdateAccountScopeRequest;
|
||||
import com.baiyue.auth.dto.AccountManagementDtos.ChangeLoginIdentifiersRequest;
|
||||
@@ -173,6 +174,17 @@ class AccountManagementServiceTest {
|
||||
verify(sessions).revokeAll(10L);
|
||||
}
|
||||
|
||||
@Test void managedPhoneChangeOrRemovalRevokesOnlyThatAccountsSessions() {
|
||||
account.setPhone("13800138000");
|
||||
|
||||
service.updatePhone(10L, new UpdateAccountPhoneRequest(null));
|
||||
|
||||
assertEquals(null, account.getPhone());
|
||||
assertEquals(3, account.getTokenVersion());
|
||||
verify(repository).save(account);
|
||||
verify(sessions).revokeAll(10L);
|
||||
}
|
||||
|
||||
@Test void duplicatePhoneDoesNotChangeLoginIdentifiers() {
|
||||
account.setUsername("old.user");
|
||||
account.setPhone("13800138000");
|
||||
|
||||
@@ -54,6 +54,8 @@ class MerchantRegistrationServiceTest {
|
||||
assertEquals(30001L, storedAccount.getValue().getDefaultMembershipId());
|
||||
assertEquals("MERCHANT", storedAccount.getValue().getDefaultAppCode());
|
||||
assertEquals("ACTIVE", storedAccount.getValue().getAccountStatus());
|
||||
assertEquals("13800138000", storedAccount.getValue().getPhone());
|
||||
assertEquals("13800138000", onboardingRequest.getValue().administratorPhone());
|
||||
assertEquals("encoded-password", storedAccount.getValue().getPasswordHash());
|
||||
assertEquals("LOGIN_AND_COMPLETE_QUALIFICATIONS", result.nextStep());
|
||||
assertEquals("PENDING", result.dimensionInitializationStatus());
|
||||
|
||||
Reference in New Issue
Block a user