增加用户注册带自定义属性与注册完成后实现自定义逻辑
This commit is contained in:
parent
dba117ef0f
commit
537c764dda
@ -9,7 +9,9 @@ import ink.wgink.interfaces.sms.ISmsBaseService;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import ink.wgink.pojo.result.SuccessResult;
|
||||
import ink.wgink.register.base.pojo.vos.RegisterDefaultVO;
|
||||
import ink.wgink.register.base.pojo.vos.RegisterDefaultWithExpandInfoVO;
|
||||
import ink.wgink.register.base.pojo.vos.RegisterPhoneVO;
|
||||
import ink.wgink.register.base.pojo.vos.RegisterPhoneWithExpandInfoVO;
|
||||
import ink.wgink.register.base.service.IRegisterService;
|
||||
import ink.wgink.util.RegexUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
@ -50,15 +52,7 @@ public class RegisterAppController extends DefaultBaseController {
|
||||
@PostMapping("default")
|
||||
@CheckRequestBodyAnnotation
|
||||
public synchronized SuccessResult defaultRegister(@RequestBody RegisterDefaultVO registerDefaultVO) throws Exception {
|
||||
if (!RegexUtil.isUsername(registerDefaultVO.getUsername())) {
|
||||
throw new ParamsException("用户名只能包含字母、数字、-_!@#%.");
|
||||
}
|
||||
if (!StringUtils.equals(registerDefaultVO.getPassword(), registerDefaultVO.getPasswordSame())) {
|
||||
throw new ParamsException("两次密码不一致");
|
||||
}
|
||||
if (!RegexUtil.isPasswordMiddle(registerDefaultVO.getPassword())) {
|
||||
throw new ParamsException("密码强度不够, 密码6到16位,包含数字、字母、特殊字符,其中的任意两种");
|
||||
}
|
||||
checkDefaultRegisterParams(registerDefaultVO);
|
||||
Map<String, Object> params = requestParams();
|
||||
registerService.registerDefault(registerDefaultVO, params);
|
||||
return new SuccessResult();
|
||||
@ -69,6 +63,64 @@ public class RegisterAppController extends DefaultBaseController {
|
||||
@PostMapping("phone")
|
||||
@CheckRequestBodyAnnotation
|
||||
public synchronized SuccessResult phone(@RequestBody RegisterPhoneVO registerPhoneVO) throws Exception {
|
||||
checkPhoneRegisterParams(registerPhoneVO);
|
||||
Map<String, Object> params = requestParams();
|
||||
registerService.registerPhone(registerPhoneVO, params);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "默认注册(有拓展信息)", notes = "默认注册(有拓展信息),用户名密码注册接口")
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("default-with-expand-info")
|
||||
@CheckRequestBodyAnnotation
|
||||
public synchronized SuccessResult defaultRegisterWithExpandInfo(@RequestBody RegisterDefaultWithExpandInfoVO registerDefaultWithExpandInfoVO) throws Exception {
|
||||
checkDefaultRegisterParams(registerDefaultWithExpandInfoVO);
|
||||
if (registerDefaultWithExpandInfoVO.getExpandInfo() == null || registerDefaultWithExpandInfoVO.getExpandInfo().isEmpty()) {
|
||||
throw new ParamsException("拓展信息不能为空");
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
registerService.registerDefaultWithExpandInfo(registerDefaultWithExpandInfoVO, params);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "手机注册(有拓展信息)", notes = "手机注册(有拓展信息),手机 + 短信验证码接口")
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("phone-with-expand-info")
|
||||
@CheckRequestBodyAnnotation
|
||||
public synchronized SuccessResult phoneWithExpandInfo(@RequestBody RegisterPhoneWithExpandInfoVO registerPhoneWithExpandInfoVO) throws Exception {
|
||||
checkPhoneRegisterParams(registerPhoneWithExpandInfoVO);
|
||||
if (registerPhoneWithExpandInfoVO.getExpandInfo() == null || registerPhoneWithExpandInfoVO.getExpandInfo().isEmpty()) {
|
||||
throw new ParamsException("拓展信息不能为空");
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
registerService.registerPhoneWithExpandInfo(registerPhoneWithExpandInfoVO, params);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证默认注册参数
|
||||
*
|
||||
* @param registerDefaultVO
|
||||
*/
|
||||
private void checkDefaultRegisterParams(RegisterDefaultVO registerDefaultVO) {
|
||||
if (!RegexUtil.isUsername(registerDefaultVO.getUsername())) {
|
||||
throw new ParamsException("用户名只能包含字母、数字、-_!@#%.");
|
||||
}
|
||||
if (!StringUtils.equals(registerDefaultVO.getPassword(), registerDefaultVO.getPasswordSame())) {
|
||||
throw new ParamsException("两次密码不一致");
|
||||
}
|
||||
if (!RegexUtil.isPasswordMiddle(registerDefaultVO.getPassword())) {
|
||||
throw new ParamsException("密码强度不够, 密码6到16位,包含数字、字母、特殊字符,其中的任意两种");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证手机注册参数
|
||||
*
|
||||
* @param registerPhoneVO
|
||||
*/
|
||||
private void checkPhoneRegisterParams(RegisterPhoneVO registerPhoneVO) {
|
||||
if (smsBaseService == null) {
|
||||
throw new DependencyException("短信依赖未引入");
|
||||
}
|
||||
@ -79,9 +131,6 @@ public class RegisterAppController extends DefaultBaseController {
|
||||
if (!StringUtils.equals(verifyCode, registerPhoneVO.getVerifyCode())) {
|
||||
throw new ParamsException("验证码错误");
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
registerService.registerPhone(registerPhoneVO, params);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package ink.wgink.register.base.pojo.vos;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: RegisterVO
|
||||
* @Description: 注册
|
||||
* @Author: WangGeng
|
||||
* @Date: 2020/6/2 10:56 下午
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@ApiModel
|
||||
public class RegisterDefaultWithExpandInfoVO extends RegisterDefaultVO {
|
||||
|
||||
private Map<String, Object> expandInfo;
|
||||
|
||||
public Map<String, Object> getExpandInfo() {
|
||||
return expandInfo;
|
||||
}
|
||||
|
||||
public void setExpandInfo(Map<String, Object> expandInfo) {
|
||||
this.expandInfo = expandInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"expandInfo\":")
|
||||
.append(expandInfo);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package ink.wgink.register.base.pojo.vos;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: RegisterPhoneVO
|
||||
* @Description: 手机注册
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/5/1 11:47 上午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@ApiModel
|
||||
public class RegisterPhoneWithExpandInfoVO extends RegisterPhoneVO {
|
||||
|
||||
private Map<String, Object> expandInfo;
|
||||
|
||||
public Map<String, Object> getExpandInfo() {
|
||||
return expandInfo;
|
||||
}
|
||||
|
||||
public void setExpandInfo(Map<String, Object> expandInfo) {
|
||||
this.expandInfo = expandInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"expandInfo\":")
|
||||
.append(expandInfo);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package ink.wgink.register.base.service;
|
||||
|
||||
import ink.wgink.register.base.pojo.vos.RegisterDefaultVO;
|
||||
import ink.wgink.register.base.pojo.vos.RegisterDefaultWithExpandInfoVO;
|
||||
import ink.wgink.register.base.pojo.vos.RegisterPhoneVO;
|
||||
import ink.wgink.register.base.pojo.vos.RegisterPhoneWithExpandInfoVO;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ -20,18 +22,35 @@ public interface IRegisterService {
|
||||
/**
|
||||
* 默认,用户名密码注册
|
||||
*
|
||||
* @param registerDefaultVO
|
||||
* @param params
|
||||
* @param registerDefaultVO 请求主体
|
||||
* @param queryParams query参数
|
||||
* @throws Exception
|
||||
*/
|
||||
void registerDefault(RegisterDefaultVO registerDefaultVO, Map<String, Object> params) throws Exception;
|
||||
void registerDefault(RegisterDefaultVO registerDefaultVO, Map<String, Object> queryParams) throws Exception;
|
||||
|
||||
/**
|
||||
* 手机注册
|
||||
*
|
||||
* @param registerPhoneVO
|
||||
* @param params
|
||||
* @param registerPhoneVO 请求主体
|
||||
* @param queryParams query参数
|
||||
* @throws Exception
|
||||
*/
|
||||
void registerPhone(RegisterPhoneVO registerPhoneVO, Map<String, Object> params) throws Exception;
|
||||
void registerPhone(RegisterPhoneVO registerPhoneVO, Map<String, Object> queryParams) throws Exception;
|
||||
|
||||
/**
|
||||
* 默认,用户名密码注册(有拓展信息)
|
||||
*
|
||||
* @param registerDefaultWithExpandInfoVO 请求主体
|
||||
* @param queryParams query参数
|
||||
*/
|
||||
void registerDefaultWithExpandInfo(RegisterDefaultWithExpandInfoVO registerDefaultWithExpandInfoVO, Map<String, Object> queryParams) throws Exception;
|
||||
|
||||
/**
|
||||
* 手机注册(有拓展信息)
|
||||
*
|
||||
* @param registerPhoneWithExpandInfoVO 请求主体
|
||||
* @param queryParams query参数
|
||||
*/
|
||||
void registerPhoneWithExpandInfo(RegisterPhoneWithExpandInfoVO registerPhoneWithExpandInfoVO, Map<String, Object> queryParams) throws Exception;
|
||||
|
||||
}
|
||||
|
@ -1,14 +1,20 @@
|
||||
package ink.wgink.register.base.service.impl;
|
||||
|
||||
import ink.wgink.common.base.DefaultBaseService;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.interfaces.expand.register.IRegisterHandlerService;
|
||||
import ink.wgink.interfaces.expand.register.IRegisterWithExpandInfoHandlerService;
|
||||
import ink.wgink.interfaces.manager.ISystemConfigManager;
|
||||
import ink.wgink.register.base.pojo.vos.RegisterDefaultVO;
|
||||
import ink.wgink.register.base.pojo.vos.RegisterDefaultWithExpandInfoVO;
|
||||
import ink.wgink.register.base.pojo.vos.RegisterPhoneVO;
|
||||
import ink.wgink.register.base.pojo.vos.RegisterPhoneWithExpandInfoVO;
|
||||
import ink.wgink.register.base.service.IRegisterService;
|
||||
import ink.wgink.service.user.enums.UserStateEnum;
|
||||
import ink.wgink.service.user.enums.UserTypeEnum;
|
||||
import ink.wgink.service.user.pojo.vos.UserVO;
|
||||
import ink.wgink.service.user.service.IUserService;
|
||||
import ink.wgink.util.ReflectUtil;
|
||||
import ink.wgink.util.UUIDUtil;
|
||||
import ink.wgink.util.string.WStringUtil;
|
||||
import org.slf4j.Logger;
|
||||
@ -16,6 +22,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -33,33 +40,87 @@ public class RegisterServiceImpl extends DefaultBaseService implements IRegister
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RegisterServiceImpl.class);
|
||||
@Autowired(required = false)
|
||||
private IRegisterHandlerService registerHandler;
|
||||
private IRegisterHandlerService registerHandlerService;
|
||||
@Autowired(required = false)
|
||||
private IRegisterWithExpandInfoHandlerService registerWithExpandInfoHandlerService;
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
private ISystemConfigManager systemConfigManager;
|
||||
|
||||
@Override
|
||||
public void registerDefault(RegisterDefaultVO registerDefaultVO, Map<String, Object> params) throws Exception {
|
||||
register(registerDefaultVO.getUsername(), registerDefaultVO.getPassword(), params);
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
try {
|
||||
systemConfigManager = ReflectUtil.getSingleInstance("ink.wgink.login.base.manager.ConfigManager", ISystemConfigManager.class);
|
||||
} catch (ReflectUtil.ReflectException e) {
|
||||
e.printStackTrace();
|
||||
LOG.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPhone(RegisterPhoneVO registerPhoneVO, Map<String, Object> params) throws Exception {
|
||||
public void registerDefault(RegisterDefaultVO registerDefaultVO, Map<String, Object> queryParams) throws Exception {
|
||||
register(registerDefaultVO.getUsername(), registerDefaultVO.getPassword(), queryParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPhone(RegisterPhoneVO registerPhoneVO, Map<String, Object> queryParams) throws Exception {
|
||||
// 生成8位随机密码
|
||||
register(registerPhoneVO.getPhone(), WStringUtil.randomSubStr(UUIDUtil.get32UUID(), 8), params);
|
||||
register(registerPhoneVO.getPhone(), WStringUtil.randomSubStr(UUIDUtil.get32UUID(), 8), queryParams);
|
||||
}
|
||||
|
||||
private void register(String username, String password, Map<String, Object> params) throws Exception {
|
||||
@Override
|
||||
public void registerDefaultWithExpandInfo(RegisterDefaultWithExpandInfoVO registerDefaultWithExpandInfoVO, Map<String, Object> queryParams) throws Exception {
|
||||
registerWithExpandInfo(registerDefaultWithExpandInfoVO.getUsername(), registerDefaultWithExpandInfoVO.getPassword(), registerDefaultWithExpandInfoVO.getExpandInfo(), queryParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPhoneWithExpandInfo(RegisterPhoneWithExpandInfoVO registerPhoneWithExpandInfoVO, Map<String, Object> queryParams) throws Exception {
|
||||
registerWithExpandInfo(registerPhoneWithExpandInfoVO.getPhone(), WStringUtil.randomSubStr(UUIDUtil.get32UUID(), 8), registerPhoneWithExpandInfoVO.getExpandInfo(), queryParams);
|
||||
}
|
||||
|
||||
private void register(String username, String password, Map<String, Object> queryParams) throws Exception {
|
||||
String isExamine = systemConfigManager.getSystemConfigParamsValue(ISystemConstant.REGISTER_USER_EXAMINE);
|
||||
|
||||
UserVO userVO = new UserVO();
|
||||
userVO.setUserUsername(username);
|
||||
userVO.setUserPassword(password);
|
||||
userVO.setUserName(username);
|
||||
userVO.setUserState(UserStateEnum.NORMAL.getValue());
|
||||
if (isRegisterUserExamine()) {
|
||||
userVO.setUserState(UserStateEnum.UN_EXAMINE.getValue());
|
||||
} else {
|
||||
userVO.setUserState(UserStateEnum.NORMAL.getValue());
|
||||
}
|
||||
userVO.setUserType(UserTypeEnum.NORMAL.getValue());
|
||||
String userId = userService.saveAndReturnId(userVO, true);
|
||||
if (registerHandler != null) {
|
||||
registerHandler.handler(userId, params);
|
||||
if (registerHandlerService != null) {
|
||||
registerHandlerService.handler(userId, queryParams);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerWithExpandInfo(String username, String password, Map<String, Object> expandInfo, Map<String, Object> queryParams) throws Exception {
|
||||
UserVO userVO = new UserVO();
|
||||
userVO.setUserUsername(username);
|
||||
userVO.setUserPassword(password);
|
||||
userVO.setUserName(username);
|
||||
if (isRegisterUserExamine()) {
|
||||
userVO.setUserState(UserStateEnum.UN_EXAMINE.getValue());
|
||||
} else {
|
||||
userVO.setUserState(UserStateEnum.NORMAL.getValue());
|
||||
}
|
||||
userVO.setUserType(UserTypeEnum.NORMAL.getValue());
|
||||
String userId = userService.saveAndReturnId(userVO, true);
|
||||
if (registerWithExpandInfoHandlerService != null) {
|
||||
registerWithExpandInfoHandlerService.handler(userId, expandInfo, queryParams);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否需要审核
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Boolean isRegisterUserExamine() {
|
||||
return Boolean.parseBoolean(systemConfigManager.getSystemConfigParamsValue(ISystemConstant.REGISTER_USER_EXAMINE));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user