新增用户名密码注册

This commit is contained in:
wanggeng888 2021-05-01 12:04:40 +08:00
parent 78949c170a
commit be0c6fdb69
6 changed files with 252 additions and 14 deletions

View File

@ -1,14 +0,0 @@
package ink.wgink.register.base.controller.api;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: RegisterController
* @Description: 注册
* @Author: wanggeng
* @Date: 2021/4/29 6:12 下午
* @Version: 1.0
*/
public class RegisterController {
}

View File

@ -0,0 +1,67 @@
package ink.wgink.register.base.controller.app.api;
import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.exceptions.ParamsException;
import ink.wgink.interfaces.consts.ISystemConstant;
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.RegisterPhoneVO;
import ink.wgink.register.base.service.IRegisterService;
import ink.wgink.util.RegexUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: RegisterController
* @Description: 注册
* @Author: wanggeng
* @Date: 2021/4/29 6:12 下午
* @Version: 1.0
*/
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "注册")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/register")
public class RegisterController {
@Autowired
private IRegisterService registerService;
@ApiOperation(value = "默认注册", notes = "默认注册,用户名密码注册接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("default")
@CheckRequestBodyAnnotation
public synchronized SuccessResult defaultRegister(@RequestBody 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位包含数字、字母、特殊字符其中的任意两种");
}
registerService.defaultRegister(registerDefaultVO);
return new SuccessResult();
}
@ApiOperation(value = "手机注册", notes = "手机注册,手机 + 短信验证码接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("phone")
@CheckRequestBodyAnnotation
public synchronized SuccessResult phone(@RequestBody RegisterPhoneVO registerPhoneVO) {
return new SuccessResult();
}
}

View File

@ -0,0 +1,66 @@
package ink.wgink.register.base.pojo.vos;
import ink.wgink.annotation.CheckEmptyAnnotation;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* 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 RegisterDefaultVO {
@ApiModelProperty(name = "username", value = "用户名")
@CheckEmptyAnnotation(name = "用户名", verifyType = "username")
private String username;
@ApiModelProperty(name = "password", value = "密码")
@CheckEmptyAnnotation(name = "密码")
private String password;
@ApiModelProperty(name = "passwordSame", value = "相同密码")
@CheckEmptyAnnotation(name = "passwordSame")
private String passwordSame;
public String getUsername() {
return username == null ? "" : username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password == null ? "" : password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPasswordSame() {
return passwordSame == null ? "" : passwordSame;
}
public void setPasswordSame(String passwordSame) {
this.passwordSame = passwordSame;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("{");
sb.append("\"username\":\"")
.append(username).append('\"');
sb.append(",\"password\":\"")
.append(password).append('\"');
sb.append(",\"passwordSame\":\"")
.append(passwordSame).append('\"');
sb.append('}');
return sb.toString();
}
}

View File

@ -0,0 +1,53 @@
package ink.wgink.register.base.pojo.vos;
import ink.wgink.annotation.CheckEmptyAnnotation;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* 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 RegisterPhoneVO {
@ApiModelProperty(name = "phone", value = "手机号")
@CheckEmptyAnnotation(name = "手机号", verifyType = "phone")
private String phone;
@ApiModelProperty(name = "verifyCode", value = "验证码")
@CheckEmptyAnnotation(name = "验证码")
private String verifyCode;
public String getPhone() {
return phone == null ? "" : phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getVerifyCode() {
return verifyCode == null ? "" : verifyCode;
}
public void setVerifyCode(String verifyCode) {
this.verifyCode = verifyCode;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("{");
sb.append("\"phone\":\"")
.append(phone).append('\"');
sb.append(",\"verifyCode\":\"")
.append(verifyCode).append('\"');
sb.append('}');
return sb.toString();
}
}

View File

@ -0,0 +1,23 @@
package ink.wgink.register.base.service;
import ink.wgink.register.base.pojo.vos.RegisterDefaultVO;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: IRegisterService
* @Description: 注册
* @Author: wanggeng
* @Date: 2021/5/1 10:33 上午
* @Version: 1.0
*/
public interface IRegisterService {
/**
* 默认用户名密码注册
*
* @param registerDefaultVO
*/
void defaultRegister(RegisterDefaultVO registerDefaultVO);
}

View File

@ -0,0 +1,43 @@
package ink.wgink.register.base.service.impl;
import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.register.base.pojo.vos.RegisterDefaultVO;
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 org.springframework.beans.factory.annotation.Autowired;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: RegisterServiceImpl
* @Description: 注册
* @Author: wanggeng
* @Date: 2021/5/1 10:33 上午
* @Version: 1.0
*/
public class RegisterServiceImpl extends DefaultBaseService implements IRegisterService {
@Autowired
private IUserService userService;
@Override
public void defaultRegister(RegisterDefaultVO registerDefaultVO) {
register(registerDefaultVO.getUsername(), registerDefaultVO.getPassword());
}
private void register(String username, String password) {
UserVO userVO = new UserVO();
userVO.setUserUsername(username);
userVO.setUserPassword(password);
userVO.setUserName(username);
userVO.setUserState(UserStateEnum.NORMAL.getValue());
userVO.setUserType(UserTypeEnum.NORMAL.getValue());
userService.register(userVO);
}
}