@@ -23,6 +23,8 @@ public class AuthManager extends AbstractLoginManager { | |||
public AuthResponse serviceHandle(AuthRequest request) throws ServiceHandleException { | |||
String openId = request.getLoginSource() == SourceType.WEB || request.getLoginSource() == SourceType.SERVICE_HALL ? request.getOpenId() : findOpenIdByToken(request.getAccessToken()); | |||
AccountInfo accountInfo = accountInfoRepo.findByIdNumAndIdType(request.getIdNum(), request.getIdType()); | |||
if (accountInfo != null) throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("该用户已存在实名账号"); | |||
AccountInfo byOpenId = accountInfoRepo.findByOpenId(openId); | |||
if (byOpenId == null) throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("该用户不存在"); | |||
byOpenId.setIdType(request.getIdType()); |
@@ -1,7 +1,6 @@ | |||
package cn.com.taiji.ias.manager.portal; | |||
import cn.com.taiji.common.manager.net.http.ServiceHandleException; | |||
import cn.com.taiji.core.entity.dict.basic.UserType; | |||
import cn.com.taiji.core.entity.user.AccountInfo; | |||
import cn.com.taiji.core.manager.cache.RedisKeyGenerator; | |||
import cn.com.taiji.core.manager.tools.SystemFinals; | |||
@@ -15,6 +14,8 @@ import org.springframework.stereotype.Service; | |||
import java.time.LocalDateTime; | |||
import java.util.UUID; | |||
import static cn.com.taiji.core.manager.tools.SystemFinals.appId; | |||
/** | |||
* 账号注册 | |||
* 小程序是ETC用户账号注册,APP和WEB是业务人员账号注册 | |||
@@ -25,7 +26,6 @@ public class RegisterManager extends AbstractLoginManager { | |||
private AccountInfoRepo accountInfoRepo; | |||
public RegisterResponse serviceHandle(RegisterRequest request) throws ServiceHandleException { | |||
String smsCode = redisManager.get(RedisKeyGenerator.getSmsCodeKey(request.getMobile(), request.getLoginSource().name(), 1)); | |||
if (!hasText(smsCode)) | |||
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("短信验证码已过期,请重新发送"); | |||
@@ -34,15 +34,20 @@ public class RegisterManager extends AbstractLoginManager { | |||
AccountInfo accountInfo = accountInfoRepo.findByAccount(request.getMobile()); | |||
if (accountInfo != null) | |||
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("该账号名:\"" + request.getMobile() + "\",已经被注册过了!"); | |||
accountInfo = handle(request); | |||
if (hasText(request.getIdNum()) && request.getIdType() != null) { | |||
accountInfo = accountInfoRepo.findByIdNumAndIdType(request.getIdNum(), request.getIdType()); | |||
if (accountInfo != null) | |||
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("该用户已存在实名账号"); | |||
} | |||
accountInfo = from(request); | |||
accountInfoRepo.persist(accountInfo); | |||
redisManager.delete(RedisKeyGenerator.getSmsCodeKey(request.getMobile(), request.getLoginSource().name(), 1)); | |||
return new RegisterResponse(); | |||
} | |||
private AccountInfo handle(RegisterRequest request) { | |||
private AccountInfo from(RegisterRequest request) { | |||
AccountInfo accountInfo = new AccountInfo(); | |||
accountInfo.setAppId(SystemFinals.appId); | |||
accountInfo.setAppId(appId); | |||
accountInfo.setLoginPass(request.getLoginPass()); | |||
accountInfo.setMobile(request.getMobile()); | |||
accountInfo.setAccount(request.getMobile()); | |||
@@ -51,6 +56,18 @@ public class RegisterManager extends AbstractLoginManager { | |||
accountInfo.setNeedChangePasswordNow("0"); // 该用户主动修改密码后,设置其登录后不用提示去自行修改密码 | |||
String openId = UUID.randomUUID().toString().replaceAll("-", ""); | |||
accountInfo.setOpenId(openId); | |||
accountInfo.setIdType(request.getIdType()); | |||
accountInfo.setIdNum(request.getIdNum()); | |||
accountInfo.setUserName(request.getUserName()); | |||
accountInfo.setGender(request.getGender()); | |||
accountInfo.setUserIdImgUrl(request.getUserIdImgUrl()); | |||
accountInfo.setUserIdImgBase64(request.getUserIdImgBase64()); | |||
accountInfo.setUserIdBackImgUrl(request.getUserIdBackImgUrl()); | |||
accountInfo.setUserIdBackImgBase64(request.getUserIdBackImgBase64()); | |||
accountInfo.setStartDate(request.getStartDate()); | |||
accountInfo.setExpireDate(request.getExpireDate()); | |||
accountInfo.setAddress(request.getAddress()); | |||
accountInfo.setUpdateTime(LocalDateTime.now()); | |||
return accountInfo; | |||
} | |||
} |
@@ -0,0 +1,81 @@ | |||
package cn.com.taiji.ias.manager.portal; | |||
import cn.com.taiji.common.manager.net.http.ServiceHandleException; | |||
import cn.com.taiji.core.entity.dict.basic.SourceType; | |||
import cn.com.taiji.core.entity.user.AccountInfo; | |||
import cn.com.taiji.core.manager.cache.RedisKeyGenerator; | |||
import cn.com.taiji.core.model.comm.protocol.ias.portal.RegisterNoCodeRequest; | |||
import cn.com.taiji.core.model.comm.protocol.ias.portal.RegisterNoCodeResponse; | |||
import cn.com.taiji.core.model.comm.protocol.valid.GlyServiceError; | |||
import cn.com.taiji.core.repo.jpa.user.AccountInfoRepo; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.security.SecureRandom; | |||
import java.time.LocalDateTime; | |||
import java.util.UUID; | |||
import static cn.com.taiji.core.manager.tools.SystemFinals.appId; | |||
/** | |||
* 账号注册 | |||
* 仅渠道人员注册 | |||
*/ | |||
@Service | |||
public class RegisterNoCodeManager extends AbstractLoginManager { | |||
@Autowired | |||
private AccountInfoRepo accountInfoRepo; | |||
public RegisterNoCodeResponse serviceHandle(RegisterNoCodeRequest request) throws ServiceHandleException { | |||
if (request.getLoginSource() != SourceType.CHANNEL || request.getLoginSource() != SourceType.SERVICE_HALL) | |||
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("没有注册用户权限"); | |||
AccountInfo accountInfo = accountInfoRepo.findByAccount(request.getMobile()); | |||
if (accountInfo != null) | |||
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("该账号名:\"" + request.getMobile() + "\",已经被注册过了!"); | |||
if (hasText(request.getIdNum()) && request.getIdType() != null) { | |||
accountInfo = accountInfoRepo.findByIdNumAndIdType(request.getIdNum(), request.getIdType()); | |||
if (accountInfo != null) | |||
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("该用户已存在实名账号"); | |||
} | |||
accountInfo = from(request); | |||
accountInfoRepo.persist(accountInfo); | |||
return new RegisterNoCodeResponse(); | |||
} | |||
private AccountInfo from(RegisterNoCodeRequest request) { | |||
AccountInfo accountInfo = new AccountInfo(); | |||
accountInfo.setAppId(appId); | |||
accountInfo.setLoginPass(hasText(request.getLoginPass()) ? request.getLoginPass() : createPassword(10)); | |||
accountInfo.setMobile(request.getMobile()); | |||
accountInfo.setAccount(request.getMobile()); | |||
accountInfo.setNickName(request.getNickName()); | |||
accountInfo.setCreateTime(LocalDateTime.now()); | |||
accountInfo.setNeedChangePasswordNow("0"); // 该用户主动修改密码后,设置其登录后不用提示去自行修改密码 | |||
String openId = UUID.randomUUID().toString().replaceAll("-", ""); | |||
accountInfo.setOpenId(openId); | |||
accountInfo.setIdType(request.getIdType()); | |||
accountInfo.setIdNum(request.getIdNum()); | |||
accountInfo.setUserName(request.getUserName()); | |||
accountInfo.setGender(request.getGender()); | |||
accountInfo.setUserIdImgUrl(request.getUserIdImgUrl()); | |||
accountInfo.setUserIdImgBase64(request.getUserIdImgBase64()); | |||
accountInfo.setUserIdBackImgUrl(request.getUserIdBackImgUrl()); | |||
accountInfo.setUserIdBackImgBase64(request.getUserIdBackImgBase64()); | |||
accountInfo.setStartDate(request.getStartDate()); | |||
accountInfo.setExpireDate(request.getExpireDate()); | |||
accountInfo.setAddress(request.getAddress()); | |||
accountInfo.setUpdateTime(LocalDateTime.now()); | |||
return accountInfo; | |||
} | |||
private String createPassword(int length) { | |||
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()"; | |||
StringBuilder password = new StringBuilder(length); | |||
SecureRandom random = new SecureRandom(); | |||
for (int i = 0; i < length; i++) { | |||
int index = random.nextInt(characters.length()); | |||
password.append(characters.charAt(index)); | |||
} | |||
return password.toString(); | |||
} | |||
} |