feat:
1. add user_market_info
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springblade.modules.market.pojo.entity.MarketInfoEntity;
|
||||
import org.springblade.modules.market.pojo.vo.MarketInfoVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.core.mp.base.BaseService;
|
||||
import org.springblade.modules.system.pojo.entity.User;
|
||||
|
||||
/**
|
||||
* 用户拓展信息表 服务类
|
||||
@@ -46,4 +47,5 @@ public interface IMarketInfoService extends BaseService<MarketInfoEntity> {
|
||||
*/
|
||||
IPage<MarketInfoVO> selectMarketInfoPage(IPage<MarketInfoVO> page, MarketInfoVO marketInfo);
|
||||
|
||||
boolean initInfo(User user, User invitor);
|
||||
}
|
||||
|
||||
@@ -29,10 +29,13 @@ import org.springblade.modules.market.pojo.entity.MarketInfoEntity;
|
||||
import org.springblade.modules.market.pojo.vo.MarketInfoVO;
|
||||
import org.springblade.modules.market.mapper.MarketInfoMapper;
|
||||
import org.springblade.modules.market.service.IMarketInfoService;
|
||||
import org.springblade.modules.system.pojo.entity.User;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 用户拓展信息表 服务实现类
|
||||
*
|
||||
@@ -47,4 +50,12 @@ public class MarketInfoServiceImpl extends BaseServiceImpl<MarketInfoMapper, Mar
|
||||
return page.setRecords(baseMapper.selectMarketInfoPage(page, marketInfo));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initInfo(User user, User invitor) {
|
||||
MarketInfoEntity info = new MarketInfoEntity();
|
||||
info.setId(user.getId());
|
||||
Optional.ofNullable(invitor).map(User::getId).ifPresent(info::setPid);
|
||||
return save(info);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ public interface IUserService extends BaseService<User> {
|
||||
*/
|
||||
boolean registerUser(User user);
|
||||
|
||||
boolean registerAppUser(User user,User invitor);
|
||||
boolean registerAppUser(User user);
|
||||
/**
|
||||
* 配置用户平台
|
||||
*
|
||||
@@ -306,4 +306,5 @@ public interface IUserService extends BaseService<User> {
|
||||
|
||||
String inviteCode();
|
||||
|
||||
User getByPhone(String phoneNumber);
|
||||
}
|
||||
|
||||
@@ -451,7 +451,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean registerAppUser(User user, User invitor) {
|
||||
public boolean registerAppUser(User user) {
|
||||
Tenant tenant = SysCache.getTenant(user.getTenantId());
|
||||
if (tenant == null || tenant.getId() == null) {
|
||||
throw new OAuth2Exception("租户信息错误!");
|
||||
@@ -611,6 +611,12 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
|
||||
|
||||
@Override
|
||||
public String inviteCode() {
|
||||
return Long.toString(Long.parseLong(AuthUtil.getUserAccount()), 36).toUpperCase();
|
||||
String upperCaseCode = Long.toString(Long.parseLong(AuthUtil.getUserAccount()), 36).toUpperCase();
|
||||
return new StringBuilder(upperCaseCode).reverse().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getByPhone(String phoneNumber) {
|
||||
return getOne(Wrappers.<User>lambdaQuery().eq(User::getAccount, phoneNumber).eq(User::getIsDeleted, 0).eq(User::getStatus, 1));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user