package cn.pluss.platform.controller.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import cn.pluss.platform.entity.MerchantMenber;




/**
 * @author yuchen
 *
 * @Description 
 */
@Slf4j
@Component
public class AuthFilter implements Filter {

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain arg2)
			throws IOException, ServletException {
		HttpServletRequest request=(HttpServletRequest) req;
		log.info("requestURI : {}", request.getRequestURI());
		log.info("requestMethod : {}", request.getMethod());
		log.info("requestParams : {}", request.getParameterMap());
		HttpServletResponse response= (HttpServletResponse) resp;
		MerchantMenber merchantMenber = (MerchantMenber) request.getSession().getAttribute("sessionMerchantMenber");
		String url = request.getRequestURI();
		if(merchantMenber==null) {
			if(!url.contains("CallBack")
					&& !url.contains("wechat")
					&& !url.contains("merchant")
					&& !url.contains("myVIPCard")
					&& !url.contains("resources")
					&& !url.contains("openCardSuccess")
					&& !url.contains("vipOpenCard")
					&& !url.contains("auth")
					&& !url.contains("jft")
					&& !url.contains("getMemberInfo")
					&& !url.contains("aliPay")
					&& !url.contains("test")
					&& !url.contains("life")
					&& !url.contains("getPhoneCode")
					&& !url.contains("api")
					&& !url.contains("user")
					&& !url.contains("activity")
					&& !url.contains("kaptcha")
					&& !url.contains("aliyun")) {
				request.getRequestDispatcher("/vip/myVIPCard").forward(req, resp);
				return;
			}
		}
		arg2.doFilter(request, response);
	}

}

