k94314517
2024-07-22 716ab46fb071ed48bc75d10fabed66bd8fcae6f1
代码提交
已修改2个文件
34 ■■■■ 文件已修改
server/service/src/main/java/com/doumee/config/Jwt/WebMvcConfig.java 32 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/impl/UsersServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/config/Jwt/WebMvcConfig.java
@@ -66,8 +66,14 @@
                Class<?> beanType = handlerMethod.getBeanType();
                Boolean checkFlag = false;
                if(!(
                    beanType.isAnnotationPresent(LoginRequired.class) || handlerMethod.hasMethodAnnotation(LoginRequired.class)
                            || beanType.isAnnotationPresent(UserLoginRequired.class) || handlerMethod.hasMethodAnnotation(UserLoginRequired.class))
                ){
                    return true;
                }
                // 有 @LoginRequired 注解,需要登录认证 客户端使用
                if ((beanType.isAnnotationPresent(LoginRequired.class) || handlerMethod.hasMethodAnnotation(LoginRequired.class))) {
                if (!checkFlag && (beanType.isAnnotationPresent(LoginRequired.class) || handlerMethod.hasMethodAnnotation(LoginRequired.class))) {
                    String token = request.getHeader(JwtTokenUtil.HEADER_KEY);
                    if(StringUtils.isBlank(token)){
                        throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录");
@@ -75,9 +81,8 @@
                    if (StringUtils.isNotBlank(token)) {
                        checkFlag = checkLogin(request,response,token);
                    }
                    // 有 @UserLoginRequired 注解,需要登录认证 内部人员使用
                }
                if(beanType.isAnnotationPresent(UserLoginRequired.class) || handlerMethod.hasMethodAnnotation(UserLoginRequired.class)){
                if(!checkFlag && (beanType.isAnnotationPresent(UserLoginRequired.class) || handlerMethod.hasMethodAnnotation(UserLoginRequired.class))){
                    String token = request.getHeader(JwtTokenUtil.HEADER_KEY);
                    if(StringUtils.isBlank(token)){
                        throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录");
@@ -85,6 +90,9 @@
                    if (StringUtils.isNotBlank(token)) {
                        checkFlag = checkPersonnelLogin(request,response,token);
                    }
                }
                if(!checkFlag){
                    throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录");
                }
                return true;
            }
@@ -96,12 +104,8 @@
    public Boolean checkLogin(HttpServletRequest request, HttpServletResponse response,String token){
        try {
            String tokenRedis = (String) redisTemplate.opsForValue().get(ZTConstants.CUSTOMER+"_"+token);
            if(StringUtils.isNotBlank(tokenRedis)){
                if(!tokenRedis.equals(token)){
                    throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME.getCode(),"长时间未操作,请重新登录");
                }
            }else{
                throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME.getCode(),"长时间未操作,请重新登录");
            if(StringUtils.isBlank(tokenRedis)){
                return false;
            }
            Long memberId = getTokenId(token);
            Member member = dao.queryForObject(" select  *  from `member` where id  = ?  limit 1  ", new BeanPropertyRowMapper<>(Member.class),memberId);
@@ -125,12 +129,8 @@
    public Boolean checkPersonnelLogin(HttpServletRequest request, HttpServletResponse response,String token){
        try {
            String tokenRedis = (String) redisTemplate.opsForValue().get(ZTConstants.BUSINESS+"_"+token);
            if(StringUtils.isNotBlank(tokenRedis)){
                if(!tokenRedis.equals(token)){
                    throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME.getCode(),"长时间未操作,请重新登录");
                }
            }else{
                throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME.getCode(),"长时间未操作,请重新登录");
            if(StringUtils.isBlank(tokenRedis)){
                return false;
            }
            Long userId = getTokenId(token);
            Users users = dao.queryForObject(" select  *  from `users` where id  = ?  limit 1  ", new BeanPropertyRowMapper<>(Users.class),userId);
@@ -159,7 +159,7 @@
    public Long getTokenId(String token){
        try {
            Integer lastIndex = token.lastIndexOf("_")+1;
            Long tokenId = Long.valueOf(token.substring(0,lastIndex));
            Long tokenId = Long.valueOf(token.substring(lastIndex));
            return tokenId;
        }catch (Exception e){
            throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录");
server/service/src/main/java/com/doumee/service/business/impl/UsersServiceImpl.java
@@ -367,7 +367,7 @@
//        JwtPayLoad payLoad = new JwtPayLoad(users.getId(),Constants.ONE);
//        String token = JwtTokenUtil.generateToken(payLoad);
//        redisTemplate.opsForValue().set(ZTConstants.BUSINESS+"_"+users.getId(),token);
        String token = JwtTokenUtil.generateTokenForZb(users.getId(),ZTConstants.BUSINESS,"",redisTemplate);
        String token = JwtTokenUtil.generateTokenForZb(users.getId(),ZTConstants.BUSINESS,users.getId()+"",redisTemplate);
        AccountResponse accountResponse = new AccountResponse();
        accountResponse.setToken(token);
        accountResponse.setUsers(users);