优化小程序手机号与微信授权登录
This commit is contained in:
+4
-17
@@ -155,25 +155,12 @@ public class WechatMiniAuthServiceImpl implements WechatMiniAuthService {
|
||||
|
||||
UserDO phoneUser = findActiveUserByPhone(phone);
|
||||
if (phoneUser != null) {
|
||||
/**
|
||||
* Run business method `assertUserAvailable`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param phoneUser parameter `phoneUser` supplied by the caller
|
||||
* @return result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
assertUserAvailable(phoneUser);
|
||||
if (userShopBindingSupport.listActiveShopIdsByUserId(phoneUser.getId()).isEmpty()) {
|
||||
return WechatMiniLoginResultVO.registrationRequired(userService.phoneLoginByVerifiedPhone(phone));
|
||||
}
|
||||
return loginOrSelectShop(phoneUser, normalizeShopId(requestDTO.getPreferredShopId()), sessionInfo, false);
|
||||
}
|
||||
|
||||
List<ShopSimpleVO> shops = userShopBindingSupport.listAllActiveShopOptions();
|
||||
if (shops.isEmpty()) {
|
||||
return WechatMiniLoginResultVO.needManualLogin("当前暂无可登录门店,请稍后再试。");
|
||||
}
|
||||
return buildSelectShopResult(
|
||||
"首次使用微信手机号一键登录,请先选择本次登录门店。",
|
||||
shops,
|
||||
new TicketPayload(null, phone, sessionInfo.openId(), sessionInfo.unionId(), true)
|
||||
);
|
||||
return WechatMiniLoginResultVO.registrationRequired(userService.phoneLoginByVerifiedPhone(phone));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+22
@@ -65,6 +65,14 @@ public class WechatMiniLoginResultVO {
|
||||
*/
|
||||
private Boolean needSetPassword;
|
||||
|
||||
private Boolean registrationRequired;
|
||||
private String registrationTicket;
|
||||
private String phone;
|
||||
private String registrationReason;
|
||||
private String registrationStatus;
|
||||
private String registrationRejectReason;
|
||||
private Long registrationApplicationId;
|
||||
|
||||
/**
|
||||
* Purpose: success supports WechatMiniLoginResultVO.java by holding or executing the success business role.
|
||||
* Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state.
|
||||
@@ -81,6 +89,20 @@ public class WechatMiniLoginResultVO {
|
||||
return resultVO;
|
||||
}
|
||||
|
||||
public static WechatMiniLoginResultVO registrationRequired(LoginResponseVO loginResponse) {
|
||||
WechatMiniLoginResultVO resultVO = new WechatMiniLoginResultVO();
|
||||
resultVO.setStatus(STATUS_NEED_MANUAL_LOGIN);
|
||||
resultVO.setMessage("手机号尚未绑定店铺,请先完成身份注册");
|
||||
resultVO.setRegistrationRequired(true);
|
||||
resultVO.setRegistrationTicket(loginResponse.getRegistrationTicket());
|
||||
resultVO.setPhone(loginResponse.getPhone());
|
||||
resultVO.setRegistrationReason(loginResponse.getRegistrationReason());
|
||||
resultVO.setRegistrationStatus(loginResponse.getRegistrationStatus());
|
||||
resultVO.setRegistrationRejectReason(loginResponse.getRegistrationRejectReason());
|
||||
resultVO.setRegistrationApplicationId(loginResponse.getRegistrationApplicationId());
|
||||
return resultVO;
|
||||
}
|
||||
|
||||
public static WechatMiniLoginResultVO selectShop(
|
||||
String message,
|
||||
String ticket,
|
||||
|
||||
+8
-3
@@ -91,8 +91,13 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
||||
} else {
|
||||
require(existing == null, "该手机号已注册,请直接登录或查看审核状态");
|
||||
}
|
||||
require(StringUtils.hasText(request.getPassword()), "密码不能为空");
|
||||
require(request.getPassword().equals(request.getConfirmPassword()), "两次密码不一致");
|
||||
boolean passwordProvided = StringUtils.hasText(request.getPassword()) || StringUtils.hasText(request.getConfirmPassword());
|
||||
if (ticket == null) {
|
||||
require(passwordProvided, "密码不能为空");
|
||||
}
|
||||
if (passwordProvided) {
|
||||
require(request.getPassword().equals(request.getConfirmPassword()), "两次密码不一致");
|
||||
}
|
||||
|
||||
ShopDO shop = null;
|
||||
if (WorkbenchRegistrationRole.MANAGER.equals(roleType)) {
|
||||
@@ -115,7 +120,7 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
||||
user.setShopId(shop.getId());
|
||||
user.setNickname((WorkbenchRegistrationRole.MANAGER.equals(roleType) ? shop.getShopName() + "店长" : "Salon店员"));
|
||||
user.setAccount(phone);
|
||||
user.setPassword(passwordEncoder.encode(request.getPassword()));
|
||||
user.setPassword(passwordProvided ? passwordEncoder.encode(request.getPassword()) : "$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW");
|
||||
user.setPhone(phone);
|
||||
user.setContactPhone(phone);
|
||||
user.setPhoneVerified(1);
|
||||
|
||||
+2
@@ -106,6 +106,8 @@ public interface UserService extends IService<UserDO> {
|
||||
*/
|
||||
LoginResponseVO phoneLogin(PhoneLoginRequestDTO phoneLoginRequestDTO);
|
||||
|
||||
LoginResponseVO phoneLoginByVerifiedPhone(String phone);
|
||||
|
||||
/**
|
||||
* Run the login flow.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
|
||||
+16
-5
@@ -1074,23 +1074,34 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
throw new RuntimeException("验证码错误或已过期");
|
||||
}
|
||||
|
||||
return phoneLoginByVerifiedPhone(phoneLoginRequestDTO.getPhone(), phoneLoginRequestDTO.getShopId(), Boolean.TRUE.equals(phoneLoginRequestDTO.getRememberMe()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginResponseVO phoneLoginByVerifiedPhone(String phone) {
|
||||
return phoneLoginByVerifiedPhone(phone, null, false);
|
||||
}
|
||||
|
||||
private LoginResponseVO phoneLoginByVerifiedPhone(String phone, Long shopId, boolean rememberMe) {
|
||||
String normalizedPhone = validateUserPhone(phone, null, true);
|
||||
|
||||
UserDO userDO = userMapper.selectOne(
|
||||
Wrappers.lambdaQuery(UserDO.class)
|
||||
.eq(UserDO::getPhone, phoneLoginRequestDTO.getPhone())
|
||||
.eq(UserDO::getPhone, normalizedPhone)
|
||||
.eq(UserDO::getIsDelete, 0)
|
||||
);
|
||||
|
||||
if (userDO == null) {
|
||||
return buildRegistrationRequiredResponse(phoneLoginRequestDTO.getPhone(), null, "PHONE_NOT_REGISTERED");
|
||||
return buildRegistrationRequiredResponse(normalizedPhone, null, "PHONE_NOT_REGISTERED");
|
||||
}
|
||||
if (userShopBindingSupport.listActiveShopIdsByUserId(userDO.getId()).isEmpty()) {
|
||||
return buildRegistrationRequiredResponse(phoneLoginRequestDTO.getPhone(), userDO, "NO_SHOP_BINDING");
|
||||
return buildRegistrationRequiredResponse(normalizedPhone, userDO, "NO_SHOP_BINDING");
|
||||
}
|
||||
assertUserAvailable(userDO);
|
||||
clearLoginFailureCount(userDO.getAccount());
|
||||
|
||||
Long resolvedShopId = resolveUserLoginShopId(userDO, phoneLoginRequestDTO.getShopId());
|
||||
return buildLoginResponse(userDO, resolvedShopId, ENCODED_UNSET_PASSWORD.equals(userDO.getPassword()), Boolean.TRUE.equals(phoneLoginRequestDTO.getRememberMe()));
|
||||
Long resolvedShopId = resolveUserLoginShopId(userDO, shopId);
|
||||
return buildLoginResponse(userDO, resolvedShopId, ENCODED_UNSET_PASSWORD.equals(userDO.getPassword()), rememberMe);
|
||||
}
|
||||
|
||||
private LoginResponseVO buildRegistrationRequiredResponse(String phone, UserDO userDO, String reason) {
|
||||
|
||||
Reference in New Issue
Block a user