Front-end performance optimization to master the industry practical, professional, cutting-edge solutions

v:ititit111222333

    /** * intercepts before accessing controller */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        // Get the userId and userToken from the header
        String userId = request.getParameter("userId");
        String userToken = request.getParameter("userToken");
        if (StringUtils.isBlank(userId) && StringUtils.isBlank(userToken)) {
            buildErrorMsg(response, IMOOCJSONResult.errorMsg("User not logged in"));
            return false;
        }
        String USER_TOKEN = "USER";
        String uniqueUserToken = redisOperator.get(USER_TOKEN + ":" + userId);
        // Check whether the tokens are consistent
        if(! uniqueUserToken.equals(userToken)) { buildErrorMsg(response, IMOOCJSONResult.errorMsg("Account remote login"));
        }
        // Return true to be considered interception passed
        return true;
    }
Copy the code