1. add user_market_info
This commit is contained in:
2026-02-05 18:30:40 +08:00
parent 2a73036bc1
commit 23e0017055
5 changed files with 43 additions and 27 deletions

View File

@@ -47,6 +47,7 @@ import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.*;
import org.springblade.modules.auth.provider.UserType;
import org.springblade.modules.auth.utils.CodeUtil;
import org.springblade.modules.market.service.IMarketInfoService;
import org.springblade.modules.resource.utils.AliyunDynpsService;
import org.springblade.modules.system.pojo.entity.User;
import org.springblade.modules.system.service.IUserService;
@@ -69,11 +70,13 @@ public class AppRegisterTokenGranter extends PasswordTokenGranter {
private final IUserService service;
private final AliyunDynpsService dynpsService;
private final IMarketInfoService marketInfoService;
public AppRegisterTokenGranter(OAuth2ClientService clientService, OAuth2UserService userService, PasswordHandler passwordHandler, IUserService service, AliyunDynpsService dynpsService) {
public AppRegisterTokenGranter(OAuth2ClientService clientService, OAuth2UserService userService, PasswordHandler passwordHandler, IUserService service, AliyunDynpsService dynpsService, IMarketInfoService marketInfoService) {
super(clientService, userService, passwordHandler);
this.service = service;
this.dynpsService = dynpsService;
this.marketInfoService = marketInfoService;
}
@Override
@@ -114,34 +117,27 @@ public class AppRegisterTokenGranter extends PasswordTokenGranter {
if (StringUtil.isBlank(smsCode)) {
throw new UserInvalidException("无效验证码");
}
Boolean verified;
try {
verified = dynpsService.verifySms(request.getPhone(), smsCode);
} catch (Exception e) {
throw new UserInvalidException(e.getMessage());
}
if (verified) {
if (StringUtil.isNotBlank(invitationCode) && !StringUtil.equals(invitationCode, "0")) {
if (!CodeUtil.isValidBase36Nullable(invitationCode)) {
throw new UserInvalidException("无效邀请码");
}
long invitorId = Long.parseLong(invitationCode, 36);
User invitor = service.getById(invitorId);
if (invitor != null) {
throw new UserInvalidException("无效邀请码");
}
//todo: 邀请人
User invitor = null;
if (StringUtil.isNotBlank(invitationCode) && !StringUtil.equals(invitationCode, "0")) {
String invitorCode;
try {
invitorCode = String.valueOf(Long.parseLong(new StringBuilder(invitationCode).reverse().toString(), 36));
} catch (Exception e) {
throw new UserInvalidException("无效邀请码");
}
} else {
throw new UserInvalidException("验证码验证失败");
invitor = service.getByPhone(invitorCode);
Assert.notNull(invitor, "无效邀请码");
}
Assert.isTrue(dynpsService.verifySms(request.getPhone(), smsCode), "验证码验证失败");
// 执行用户注册
if (service.registerAppUser(user)) {
request.setUsername(user.getAccount());
// 构建oauth2所需用户信息
return super.user(request);
if (marketInfoService.initInfo(user, invitor)) {
request.setUsername(user.getAccount());
// 构建oauth2所需用户信息
return super.user(request);
}
}
throw new UserInvalidException(ExceptionCode.INVALID_USER.getMessage());
}