liukangdong
2024-09-29 b2d360d9113b6955287108ca9e90d76a1f3c1419
server/service/src/main/java/com/doumee/config/Jwt/WebMvcConfig.java
@@ -66,30 +66,19 @@
                Class<?> beanType = handlerMethod.getBeanType();
                Boolean checkFlag = false;
                if(!(
                    beanType.isAnnotationPresent(LoginRequired.class) || handlerMethod.hasMethodAnnotation(LoginRequired.class)
                            || beanType.isAnnotationPresent(UserLoginRequired.class) || handlerMethod.hasMethodAnnotation(UserLoginRequired.class))
                if(!( handlerMethod.hasMethodAnnotation(LoginRequired.class) || handlerMethod.hasMethodAnnotation(UserLoginRequired.class))
                ){
                    return true;
                }
                // 有 @LoginRequired 注解,需要登录认证 客户端使用
                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(),"未登录");
                    }
                    if (StringUtils.isNotBlank(token)) {
                        checkFlag = checkLogin(request,response,token);
                    }
                String token = request.getHeader(JwtTokenUtil.HEADER_KEY);
                if(StringUtils.isBlank(token)){
                    throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录");
                }
                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(),"未登录");
                    }
                    if (StringUtils.isNotBlank(token)) {
                if (handlerMethod.hasMethodAnnotation(LoginRequired.class)) {
                        checkFlag = checkLogin(request,response,token);
                }
                if(!checkFlag && handlerMethod.hasMethodAnnotation(UserLoginRequired.class)){
                        checkFlag = checkPersonnelLogin(request,response,token);
                    }
                }
                if(!checkFlag){
                    throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录");
@@ -112,14 +101,19 @@
            if(Objects.isNull(member)){
                throw new BusinessException(ResponseStatus.DATA_EMPTY);
            }
            if(Objects.isNull(member.getOpenid())){
                throw new BusinessException(ResponseStatus.USER_DISABLE_TIME.getCode(),"用户已注销,请重新登录");
            }
            if(Constants.equalsInteger(member.getIsdeleted(),Constants.ONE)){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"用户已删除,请联系管理员");
                throw new BusinessException(ResponseStatus.USER_DISABLE_TIME.getCode(),"用户已删除,请联系管理员");
            }
            if(!Constants.equalsInteger(member.getStatus(),Constants.ZERO)){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"用户已禁用,请联系管理员");
                throw new BusinessException(ResponseStatus.USER_DISABLE_TIME.getCode(),"用户已禁用,请联系管理员");
            }
            request.setAttribute(JwtTokenUtil.UserId_Name, memberId);
            request.setAttribute(JwtTokenUtil.UserType, ZTConstants.CUSTOMER);
            request.setAttribute(JwtTokenUtil.HEADER_KEY, ZTConstants.CUSTOMER+"_"+token);
            request.setAttribute(JwtTokenUtil.UserInfo, tokenRedis);
            return true;
        } catch (IllegalArgumentException | JwtException e) {
            throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录");
@@ -138,13 +132,15 @@
                throw new BusinessException(ResponseStatus.DATA_EMPTY);
            }
            if(Constants.equalsInteger(users.getIsdeleted(),Constants.ONE)){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"用户已删除,请联系管理员");
                throw new BusinessException(ResponseStatus.USER_DISABLE_TIME.getCode(),"用户已删除,请联系管理员");
            }
            if(!StringUtils.equals(users.getStatus(),Constants.ONE+"")){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"用户已禁用,请联系管理员");
                throw new BusinessException(ResponseStatus.USER_DISABLE_TIME.getCode(),"用户状态异常,请重新登录");
            }
            request.setAttribute(JwtTokenUtil.UserId_Name, userId);
            request.setAttribute(JwtTokenUtil.UserType, ZTConstants.BUSINESS);
            request.setAttribute(JwtTokenUtil.HEADER_KEY, ZTConstants.CUSTOMER+"_"+token);
            request.setAttribute(JwtTokenUtil.UserInfo, tokenRedis);
            return true;
        } catch (IllegalArgumentException | JwtException e) {
            throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录");