收紧店务端验证码登录准入

This commit is contained in:
2026-07-06 17:35:12 +08:00
parent 3c041e0895
commit 7d7d23a3d2
8 changed files with 124 additions and 6 deletions
@@ -410,6 +410,11 @@ public class UserController {
return Result.success(userService.getLoginShopSelectionByPhone(phone));
}
@GetMapping("/check/manager-login-shops/phone/{phone}")
public Result<LoginShopSelectionVO> getManagerLoginShopsByPhone(@PathVariable String phone) {
return Result.success(userService.getManagerLoginShopSelectionByPhone(phone));
}
@GetMapping("/check/phone/{phone}")
/**
* Run business method `checkPhoneAvailability`.
@@ -148,6 +148,14 @@ public interface UserService extends IService<UserDO> {
*/
LoginShopSelectionVO getLoginShopSelectionByPhone(String phone);
/**
* 查询店务端手机号验证码登录可选店铺。
*
* @param phone 手机号
* @return 可登录店铺选择结果
*/
LoginShopSelectionVO getManagerLoginShopSelectionByPhone(String phone);
/**
* Load data by the supplied parameter.
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
@@ -956,6 +956,33 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
return buildLoginShopSelection(List.of(), false, "当前账号没有可登录的店铺,请联系门店处理");
}
@Override
public LoginShopSelectionVO getManagerLoginShopSelectionByPhone(String phone) {
String normalizedPhone = phone == null ? "" : phone.trim();
if (!StringUtils.hasText(normalizedPhone)) {
return buildLoginShopSelection(List.of(), false, "请输入手机号后再选择店铺");
}
UserDO userDO = userMapper.selectOne(
Wrappers.lambdaQuery(UserDO.class)
.eq(UserDO::getPhone, normalizedPhone)
.eq(UserDO::getIsDelete, 0)
.last("limit 1")
);
if (userDO == null || !isManagerLoginUser(userDO)) {
return buildLoginShopSelection(List.of(), false, "仅店长或美甲师可登录店务端");
}
if (userDO.getStatus() != null && !Integer.valueOf(1).equals(userDO.getStatus())) {
return buildLoginShopSelection(List.of(), false, "该账号已被禁用");
}
List<ShopSimpleVO> shops = listEnabledShopOptionsForUser(userDO.getId());
if (!shops.isEmpty()) {
return buildLoginShopSelection(shops, false, buildLoginShopMessage(shops));
}
return buildLoginShopSelection(List.of(), false, "当前账号没有可登录的店铺,请联系平台管理员");
}
@Override
/**
* Load data by the supplied parameter.
@@ -1086,6 +1113,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
);
if (userDO == null) {
if (isManagerWebClient(phoneLoginRequestDTO.getClientType())) {
throw new RuntimeException("仅店长或美甲师可登录店务端");
}
if (phoneLoginRequestDTO.getShopId() == null || phoneLoginRequestDTO.getShopId() == 0) {
/**
* Run business method `RuntimeException`.
@@ -1103,10 +1133,15 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
* @return result consumed by the caller or returned to the frontend
*/
assertUserAvailable(userDO);
if (isManagerWebClient(phoneLoginRequestDTO.getClientType()) && !isManagerLoginUser(userDO)) {
throw new RuntimeException("仅店长或美甲师可登录店务端");
}
clearLoginFailureCount(userDO.getAccount());
}
Long resolvedShopId = resolveUserLoginShopId(userDO, phoneLoginRequestDTO.getShopId());
Long resolvedShopId = isManagerWebClient(phoneLoginRequestDTO.getClientType())
? resolveAdminLoginShopId(userDO, phoneLoginRequestDTO.getShopId())
: resolveUserLoginShopId(userDO, phoneLoginRequestDTO.getShopId());
return buildLoginResponse(userDO, resolvedShopId, ENCODED_UNSET_PASSWORD.equals(userDO.getPassword()), Boolean.TRUE.equals(phoneLoginRequestDTO.getRememberMe()));
}
@@ -1184,6 +1219,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
*/
private static final String ENCODED_UNSET_PASSWORD = "$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW"; // 加密后的特殊标识
private static final String MANAGER_WEB_CLIENT_TYPE = "MANAGER_WEB";
/**
* Run the registration flow.
@@ -1423,6 +1459,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
return shopId != null && shopId > 0 ? shopId : null;
}
private boolean isManagerWebClient(String clientType) {
return MANAGER_WEB_CLIENT_TYPE.equalsIgnoreCase(clientType == null ? "" : clientType.trim());
}
private boolean isManagerLoginUser(UserDO userDO) {
if (userDO == null) {
return false;
}
Integer userType = userDO.getType();
return Integer.valueOf(2).equals(userType) || Integer.valueOf(3).equals(userType);
}
@Override
/**
* Run the registration flow.