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