新增登录、注册自定义处理接口
This commit is contained in:
parent
a7a479d607
commit
f74a79b325
@ -1,8 +1,11 @@
|
|||||||
package ink.wgink.register.base.controller.app.api;
|
package ink.wgink.register.base.controller.app.api;
|
||||||
|
|
||||||
import ink.wgink.annotation.CheckRequestBodyAnnotation;
|
import ink.wgink.annotation.CheckRequestBodyAnnotation;
|
||||||
|
import ink.wgink.exceptions.DependencyException;
|
||||||
import ink.wgink.exceptions.ParamsException;
|
import ink.wgink.exceptions.ParamsException;
|
||||||
|
import ink.wgink.exceptions.PropertiesException;
|
||||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||||
|
import ink.wgink.interfaces.sms.ISmsBaseService;
|
||||||
import ink.wgink.pojo.result.ErrorResult;
|
import ink.wgink.pojo.result.ErrorResult;
|
||||||
import ink.wgink.pojo.result.SuccessResult;
|
import ink.wgink.pojo.result.SuccessResult;
|
||||||
import ink.wgink.register.base.pojo.vos.RegisterDefaultVO;
|
import ink.wgink.register.base.pojo.vos.RegisterDefaultVO;
|
||||||
@ -35,6 +38,8 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@RequestMapping(ISystemConstant.APP_PREFIX + "/register")
|
@RequestMapping(ISystemConstant.APP_PREFIX + "/register")
|
||||||
public class RegisterController {
|
public class RegisterController {
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private ISmsBaseService smsBaseService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IRegisterService registerService;
|
private IRegisterService registerService;
|
||||||
|
|
||||||
@ -42,7 +47,7 @@ public class RegisterController {
|
|||||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||||
@PostMapping("default")
|
@PostMapping("default")
|
||||||
@CheckRequestBodyAnnotation
|
@CheckRequestBodyAnnotation
|
||||||
public synchronized SuccessResult defaultRegister(@RequestBody RegisterDefaultVO registerDefaultVO) {
|
public synchronized SuccessResult defaultRegister(@RequestBody RegisterDefaultVO registerDefaultVO) throws Exception {
|
||||||
if (!RegexUtil.isUsername(registerDefaultVO.getUsername())) {
|
if (!RegexUtil.isUsername(registerDefaultVO.getUsername())) {
|
||||||
throw new ParamsException("用户名只能包含字母、数字、-_!@#%.");
|
throw new ParamsException("用户名只能包含字母、数字、-_!@#%.");
|
||||||
}
|
}
|
||||||
@ -60,7 +65,18 @@ public class RegisterController {
|
|||||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||||
@PostMapping("phone")
|
@PostMapping("phone")
|
||||||
@CheckRequestBodyAnnotation
|
@CheckRequestBodyAnnotation
|
||||||
public synchronized SuccessResult phone(@RequestBody RegisterPhoneVO registerPhoneVO) {
|
public synchronized SuccessResult phone(@RequestBody RegisterPhoneVO registerPhoneVO) throws Exception {
|
||||||
|
if (smsBaseService == null) {
|
||||||
|
throw new DependencyException("短信依赖未引入");
|
||||||
|
}
|
||||||
|
String verifyCode = smsBaseService.getVerifyCode(registerPhoneVO.getPhone());
|
||||||
|
if (StringUtils.isBlank(verifyCode)) {
|
||||||
|
throw new ParamsException("验证码无效");
|
||||||
|
}
|
||||||
|
if (!StringUtils.equals(verifyCode, registerPhoneVO.getVerifyCode())) {
|
||||||
|
throw new ParamsException("验证码错误");
|
||||||
|
}
|
||||||
|
registerService.phoneRegister(registerPhoneVO);
|
||||||
return new SuccessResult();
|
return new SuccessResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ink.wgink.register.base.service;
|
package ink.wgink.register.base.service;
|
||||||
|
|
||||||
import ink.wgink.register.base.pojo.vos.RegisterDefaultVO;
|
import ink.wgink.register.base.pojo.vos.RegisterDefaultVO;
|
||||||
|
import ink.wgink.register.base.pojo.vos.RegisterPhoneVO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When you feel like quitting. Think about why you started
|
* When you feel like quitting. Think about why you started
|
||||||
@ -18,6 +19,15 @@ public interface IRegisterService {
|
|||||||
* 默认,用户名密码注册
|
* 默认,用户名密码注册
|
||||||
*
|
*
|
||||||
* @param registerDefaultVO
|
* @param registerDefaultVO
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
void defaultRegister(RegisterDefaultVO registerDefaultVO);
|
void defaultRegister(RegisterDefaultVO registerDefaultVO) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机注册
|
||||||
|
*
|
||||||
|
* @param registerPhoneVO
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
void phoneRegister(RegisterPhoneVO registerPhoneVO) throws Exception;
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,21 @@
|
|||||||
package ink.wgink.register.base.service.impl;
|
package ink.wgink.register.base.service.impl;
|
||||||
|
|
||||||
import ink.wgink.common.base.DefaultBaseService;
|
import ink.wgink.common.base.DefaultBaseService;
|
||||||
|
import ink.wgink.exceptions.base.SystemException;
|
||||||
|
import ink.wgink.interfaces.expand.register.IRegisterHandler;
|
||||||
import ink.wgink.register.base.pojo.vos.RegisterDefaultVO;
|
import ink.wgink.register.base.pojo.vos.RegisterDefaultVO;
|
||||||
|
import ink.wgink.register.base.pojo.vos.RegisterPhoneVO;
|
||||||
import ink.wgink.register.base.service.IRegisterService;
|
import ink.wgink.register.base.service.IRegisterService;
|
||||||
import ink.wgink.service.user.enums.UserStateEnum;
|
import ink.wgink.service.user.enums.UserStateEnum;
|
||||||
import ink.wgink.service.user.enums.UserTypeEnum;
|
import ink.wgink.service.user.enums.UserTypeEnum;
|
||||||
import ink.wgink.service.user.pojo.vos.UserVO;
|
import ink.wgink.service.user.pojo.vos.UserVO;
|
||||||
import ink.wgink.service.user.service.IUserService;
|
import ink.wgink.service.user.service.IUserService;
|
||||||
|
import ink.wgink.util.UUIDUtil;
|
||||||
|
import ink.wgink.util.string.WStringUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When you feel like quitting. Think about why you started
|
* When you feel like quitting. Think about why you started
|
||||||
@ -19,24 +27,37 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
* @Date: 2021/5/1 10:33 上午
|
* @Date: 2021/5/1 10:33 上午
|
||||||
* @Version: 1.0
|
* @Version: 1.0
|
||||||
*/
|
*/
|
||||||
|
@Service
|
||||||
public class RegisterServiceImpl extends DefaultBaseService implements IRegisterService {
|
public class RegisterServiceImpl extends DefaultBaseService implements IRegisterService {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(RegisterServiceImpl.class);
|
||||||
|
@Autowired(required = false)
|
||||||
|
private IRegisterHandler registerHandler;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IUserService userService;
|
private IUserService userService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void defaultRegister(RegisterDefaultVO registerDefaultVO) {
|
public void defaultRegister(RegisterDefaultVO registerDefaultVO) throws Exception {
|
||||||
register(registerDefaultVO.getUsername(), registerDefaultVO.getPassword());
|
register(registerDefaultVO.getUsername(), registerDefaultVO.getPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void register(String username, String password) {
|
@Override
|
||||||
|
public void phoneRegister(RegisterPhoneVO registerPhoneVO) throws Exception {
|
||||||
|
// 生成8位随机密码
|
||||||
|
register(registerPhoneVO.getPhone(), WStringUtil.randomSubStr(UUIDUtil.get32UUID(), 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void register(String username, String password) throws Exception {
|
||||||
UserVO userVO = new UserVO();
|
UserVO userVO = new UserVO();
|
||||||
userVO.setUserUsername(username);
|
userVO.setUserUsername(username);
|
||||||
userVO.setUserPassword(password);
|
userVO.setUserPassword(password);
|
||||||
userVO.setUserName(username);
|
userVO.setUserName(username);
|
||||||
userVO.setUserState(UserStateEnum.NORMAL.getValue());
|
userVO.setUserState(UserStateEnum.NORMAL.getValue());
|
||||||
userVO.setUserType(UserTypeEnum.NORMAL.getValue());
|
userVO.setUserType(UserTypeEnum.NORMAL.getValue());
|
||||||
userService.register(userVO);
|
String userId = userService.saveAndReturnId(userVO, true);
|
||||||
|
if (registerHandler == null) {
|
||||||
|
registerHandler.handler(userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user