+
This commit is contained in:
parent
84b4f1e3d3
commit
62ee6bdb67
@ -1,79 +1,79 @@
|
|||||||
package com.jsl.oa.aspect;
|
//package com.jsl.oa.aspect;
|
||||||
|
//
|
||||||
import com.jsl.oa.utils.ErrorCode;
|
//import com.jsl.oa.utils.ErrorCode;
|
||||||
import com.jsl.oa.utils.ResultUtil;
|
//import com.jsl.oa.utils.ResultUtil;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
//import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
//import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
//import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.springframework.stereotype.Component;
|
//import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
//import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
//import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
//
|
||||||
import javax.servlet.http.HttpServletRequest;
|
//import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Objects;
|
//import java.util.Objects;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* <h1>用户控制器切面</h1>
|
// * <h1>用户控制器切面</h1>
|
||||||
* <hr/>
|
// * <hr/>
|
||||||
* 用于用户控制器的切面
|
// * 用于用户控制器的切面
|
||||||
*
|
// *
|
||||||
* @since v1.0.0
|
// * @since v1.0.0
|
||||||
* @version v1.0.0
|
// * @version v1.0.0
|
||||||
* @author 筱锋xiao_lfeng
|
// * @author 筱锋xiao_lfeng
|
||||||
*/
|
// */
|
||||||
@Aspect
|
//@Aspect
|
||||||
@Component
|
//@Component
|
||||||
public class UserControllerAspect {
|
//public class UserControllerAspect {
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* <h1>用户控制器切面</h1>
|
// * <h1>用户控制器切面</h1>
|
||||||
* <hr/>
|
// * <hr/>
|
||||||
* 用于用户控制器的切面
|
// * 用于用户控制器的切面
|
||||||
*
|
// *
|
||||||
* @since v1.0.0
|
// * @since v1.0.0
|
||||||
* @param pjp ProceedingJoinPoint对象
|
// * @param pjp ProceedingJoinPoint对象
|
||||||
* @return {@link Object}
|
// * @return {@link Object}
|
||||||
* @throws Throwable 异常
|
// * @throws Throwable 异常
|
||||||
*/
|
// */
|
||||||
@Around("execution(* com.jsl.oa.controllers.UserController.*(..))")
|
// @Around("execution(* com.jsl.oa.controllers.UserController.*(..))")
|
||||||
public Object controllerAround(ProceedingJoinPoint pjp) throws Throwable {
|
// public Object controllerAround(ProceedingJoinPoint pjp) throws Throwable {
|
||||||
// 获取HttpServletRequest对象
|
// // 获取HttpServletRequest对象
|
||||||
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
// HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
||||||
|
//
|
||||||
// 时间戳检查
|
// // 时间戳检查
|
||||||
if (checkTimestamp(request)) {
|
// if (checkTimestamp(request)) {
|
||||||
// TODO: 2023/12/21 0001 后期固定业务(如:日志处理)
|
// // TODO: 2023/12/21 0001 后期固定业务(如:日志处理)
|
||||||
return pjp.proceed();
|
// return pjp.proceed();
|
||||||
} else {
|
// } else {
|
||||||
return ResultUtil.error(ErrorCode.TIMESTAMP_ERROR);
|
// return ResultUtil.error(ErrorCode.TIMESTAMP_ERROR);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* <h1>时间戳检查</h1>
|
// * <h1>时间戳检查</h1>
|
||||||
* <hr/>
|
// * <hr/>
|
||||||
* 用于检查时间戳是否合法,合法时间范围正负5秒
|
// * 用于检查时间戳是否合法,合法时间范围正负5秒
|
||||||
*
|
// *
|
||||||
* @since v1.0.0
|
// * @since v1.0.0
|
||||||
* @param request HttpServletRequest对象
|
// * @param request HttpServletRequest对象
|
||||||
* @return {@link Boolean}
|
// * @return {@link Boolean}
|
||||||
*/
|
// */
|
||||||
public Boolean checkTimestamp(HttpServletRequest request) {
|
// public Boolean checkTimestamp(HttpServletRequest request) {
|
||||||
// 获取请求头中的时间戳
|
// // 获取请求头中的时间戳
|
||||||
String getTimestamp = request.getHeader("Timestamp");
|
// String getTimestamp = request.getHeader("Timestamp");
|
||||||
// 判断是否为空
|
// // 判断是否为空
|
||||||
if (getTimestamp == null || getTimestamp.isEmpty()) {
|
// if (getTimestamp == null || getTimestamp.isEmpty()) {
|
||||||
return false;
|
// return false;
|
||||||
} else {
|
// } else {
|
||||||
if (getTimestamp.length() == 10) {
|
// if (getTimestamp.length() == 10) {
|
||||||
getTimestamp += "000";
|
// getTimestamp += "000";
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
// 获取当前时间戳
|
// // 获取当前时间戳
|
||||||
long nowTimestamp = System.currentTimeMillis();
|
// long nowTimestamp = System.currentTimeMillis();
|
||||||
|
//
|
||||||
// 时间误差允许前后五秒钟
|
// // 时间误差允许前后五秒钟
|
||||||
return nowTimestamp - Long.parseLong(getTimestamp) <= 5000 && nowTimestamp - Long.parseLong(getTimestamp) >= -5000;
|
// return nowTimestamp - Long.parseLong(getTimestamp) <= 5000 && nowTimestamp - Long.parseLong(getTimestamp) >= -5000;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.jsl.oa.controllers;
|
package com.jsl.oa.controllers;
|
||||||
|
|
||||||
|
import com.jsl.oa.common.doData.UserDO;
|
||||||
import com.jsl.oa.common.voData.UserRegisterVO;
|
import com.jsl.oa.common.voData.UserRegisterVO;
|
||||||
import com.jsl.oa.services.UserService;
|
import com.jsl.oa.services.UserService;
|
||||||
import com.jsl.oa.utils.BaseResponse;
|
import com.jsl.oa.utils.BaseResponse;
|
||||||
@ -36,4 +37,10 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
return userService.userRegister(userRegisterVO);
|
return userService.userRegister(userRegisterVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/user/login")
|
||||||
|
public BaseResponse userLogin(@RequestBody UserDO userDO){
|
||||||
|
|
||||||
|
return userService.userLogin(userDO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,4 +18,10 @@ public interface UserMapper {
|
|||||||
"VALUES " +
|
"VALUES " +
|
||||||
"(#{userNum}, #{username}, #{password}, #{sex}, #{age}, #{unit}, #{filed}, #{hometown}, #{kind}, #{status})")
|
"(#{userNum}, #{username}, #{password}, #{sex}, #{age}, #{unit}, #{filed}, #{hometown}, #{kind}, #{status})")
|
||||||
Boolean insertUser(UserDO userDO);
|
Boolean insertUser(UserDO userDO);
|
||||||
|
|
||||||
|
@Select("select * from users where user_num = #{userNum} ")
|
||||||
|
UserDO login(UserDO userDO);
|
||||||
|
|
||||||
|
@Select("select password from users where user_num = #{userNum}")
|
||||||
|
String loginPassword(UserDO userDO);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.jsl.oa.services;
|
package com.jsl.oa.services;
|
||||||
|
|
||||||
|
import com.jsl.oa.common.doData.UserDO;
|
||||||
import com.jsl.oa.common.voData.UserRegisterVO;
|
import com.jsl.oa.common.voData.UserRegisterVO;
|
||||||
import com.jsl.oa.utils.BaseResponse;
|
import com.jsl.oa.utils.BaseResponse;
|
||||||
|
|
||||||
@ -7,4 +8,6 @@ import java.text.ParseException;
|
|||||||
|
|
||||||
public interface UserService {
|
public interface UserService {
|
||||||
BaseResponse userRegister(UserRegisterVO userRegisterVO) throws ParseException;
|
BaseResponse userRegister(UserRegisterVO userRegisterVO) throws ParseException;
|
||||||
|
|
||||||
|
BaseResponse userLogin(UserDO userDO);
|
||||||
}
|
}
|
||||||
|
@ -64,4 +64,16 @@ public class UserServiceImpl implements UserService {
|
|||||||
return ResultUtil.error(ErrorCode.DATABASE_INSERT_ERROR);
|
return ResultUtil.error(ErrorCode.DATABASE_INSERT_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
return ResultUtil.success(userMapper.login(userDO));
|
||||||
|
}else return ResultUtil.error(ErrorCode.WRONG_PASSWORD);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
url: jdbc:mysql://localhost:3306
|
url: jdbc:mysql://localhost:3306/project
|
||||||
username: organize_oa
|
username: root
|
||||||
password: 123456
|
password: 12345
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
mybatis:
|
||||||
|
configuration:
|
||||||
|
map-underscore-to-camel-case: true
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user