补丁包
This commit is contained in:
parent
72090aadd1
commit
4df82ecdcc
@ -23,8 +23,7 @@ public class UserRegisterVO {
|
||||
@NotBlank(message = "密码不能为空")
|
||||
private String password;
|
||||
|
||||
@Pattern(regexp = "^(男|女|保密)$", message = "性别只能为男或女")
|
||||
@NotBlank(message = "性别不能为空")
|
||||
@Pattern(regexp = "^(男|女|保密)$", message = "性别只能为男、女或保密")
|
||||
private String sex;
|
||||
|
||||
@NotBlank(message = "年龄不能为空")
|
||||
|
@ -33,15 +33,20 @@ public class UserController {
|
||||
public BaseResponse userRegister(@RequestBody @Validated UserRegisterVO userRegisterVO, BindingResult bindingResult) throws ParseException {
|
||||
// 判断是否有参数错误
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResultUtil.error(ErrorCode.PARAMETER_ERROR, Processing.getValidatedErrorList(bindingResult));
|
||||
return ResultUtil.error(ErrorCode.REQUEST_BODY_ERROR, Processing.getValidatedErrorList(bindingResult));
|
||||
}
|
||||
return userService.userRegister(userRegisterVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
* @param userDO
|
||||
* @return
|
||||
* <h1>用户登录</h1>
|
||||
* <hr/>
|
||||
* 用户登录接口
|
||||
*
|
||||
* @since v1.0.0
|
||||
* @param userDO 用户登录信息
|
||||
* @return {@link BaseResponse}
|
||||
* @author 176yunxuan
|
||||
*/
|
||||
@PostMapping("/user/login")
|
||||
public BaseResponse userLogin(@RequestBody UserDO userDO){
|
||||
|
20
src/main/java/com/jsl/oa/exception/BusinessException.java
Normal file
20
src/main/java/com/jsl/oa/exception/BusinessException.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.jsl.oa.exception;
|
||||
|
||||
import com.jsl.oa.utils.ErrorCode;
|
||||
|
||||
/**
|
||||
* <h1>业务异常类</h1>
|
||||
* <hr/>
|
||||
* 用于处理业务异常
|
||||
*
|
||||
* @since v1.0.0
|
||||
* @version v1.0.0
|
||||
* @author 筱锋xiao_lfeng
|
||||
* @see RuntimeException
|
||||
*/
|
||||
public class BusinessException extends RuntimeException {
|
||||
|
||||
public BusinessException(ErrorCode errorCode) {
|
||||
super(errorCode.getOutput() + "|" + errorCode.getMessage());
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.jsl.oa.services;
|
||||
|
||||
import com.jsl.oa.common.doData.UserDO;
|
||||
import com.jsl.oa.common.voData.UserRegisterVO;
|
||||
import com.jsl.oa.exception.BusinessException;
|
||||
import com.jsl.oa.mapper.UserMapper;
|
||||
import com.jsl.oa.utils.BaseResponse;
|
||||
import com.jsl.oa.utils.ErrorCode;
|
||||
@ -61,7 +62,7 @@ public class UserServiceImpl implements UserService {
|
||||
if (userMapper.insertUser(userDO)) {
|
||||
return ResultUtil.success("注册成功");
|
||||
} else {
|
||||
return ResultUtil.error(ErrorCode.DATABASE_INSERT_ERROR);
|
||||
throw new BusinessException(ErrorCode.DATABASE_INSERT_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,11 +70,9 @@ public class UserServiceImpl implements UserService {
|
||||
public BaseResponse userLogin(UserDO userDO) {
|
||||
String pwd = userDO.getPassword();
|
||||
String encodePwd = userMapper.loginPassword(userDO);
|
||||
boolean a = BCrypt.checkpw(pwd, encodePwd);
|
||||
if(BCrypt.checkpw(pwd, encodePwd))
|
||||
{
|
||||
if (BCrypt.checkpw(pwd, encodePwd)) {
|
||||
return ResultUtil.success(userMapper.login(userDO));
|
||||
}else return ResultUtil.error(ErrorCode.WRONG_PASSWORD);
|
||||
} else return ResultUtil.error(ErrorCode.WRONG_PASSWORD);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,9 @@ import lombok.Getter;
|
||||
public enum ErrorCode {
|
||||
WRONG_PASSWORD("WrongPassword", 40010, "密码错误"),
|
||||
PARAMETER_ERROR("ParameterError", 40011, "参数错误"),
|
||||
USERNAME_EXIST("UsernameExist", 40012, "用户名已存在"),
|
||||
TIMESTAMP_ERROR("TimestampError", 40013, "时间戳错误"),
|
||||
REQUEST_BODY_ERROR("RequestBodyError", 40012, "请求体错误"),
|
||||
USERNAME_EXIST("UsernameExist", 40013, "用户名已存在"),
|
||||
TIMESTAMP_ERROR("TimestampError", 40014, "时间戳错误"),
|
||||
DATABASE_INSERT_ERROR("DatabaseInsertError", 50010, "数据库插入错误"),
|
||||
DATABASE_UPDATE_ERROR("DatabaseUpdateError", 50011, "数据库更新错误"),
|
||||
DATABASE_DELETE_ERROR("DatabaseDeleteError", 50012, "数据库删除错误");
|
||||
|
@ -1,8 +1,8 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/project
|
||||
username: root
|
||||
password: 12345
|
||||
url: jdbc:mysql://localhost:3306
|
||||
username: organize_oa
|
||||
password: 123456
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
mybatis:
|
||||
configuration:
|
||||
|
Loading…
x
Reference in New Issue
Block a user