package com.copy.trade.interceptor;


import com.copy.trade.constant.DogeApi;
import com.copy.trade.entity.po.Customer;
import com.copy.trade.service.ICustomerService;
import com.copy.trade.util.WebAssert;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Slf4j
@Component
public class AuthenticationInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 非controller请求直接跳过
        if (!(handler instanceof HandlerMethod)) {
            return true;
        }
        //String tokenHeader = request.getHeader(DogeApi.TOKEN_NAME);
        //boolean hasAuth = !StringUtils.isBlank(tokenHeader);
        //WebAssert.hasAuth(hasAuth, "4001");
        //Object admin = request.getSession().getAttribute(DogeApi.SESSION_ADMIN);
		/*
		 * log.info("admin={}", admin); if(admin != null) { //验证登陆 return true; } else {
		 * return true; }
		 */
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }

}
