package com.example.demo.admin.interceptor;

import com.example.demo.admin.common.ResponseDTO;
import com.example.demo.admin.module.admin.AdminService;

import javax.servlet.http.HttpServletRequest;

/**
 * 后台管理请求拦截器
 */
public class AdminInterceptor {

    public static ResponseDTO preHandle(HttpServletRequest request) {
        String token = request.getHeader("x-access-token");
        String token2 = request.getParameter("xAccessToken");
        if (token2 != null) {
            token = token2;
        }
        if (token != null && token.equals("LvJinCheng")) {
            //开发者免认证
            return null;
        }
        if (token == null || !token.equals(AdminService.ins.getSuperAdmin().getToken())) {
            ResponseDTO responseDTO = new ResponseDTO();
            responseDTO.setCode(-1000);
            responseDTO.setMsg("Token失效");
            return responseDTO;
        }
        return null;
    }
}
