package com.cnooc.expert.config;

import com.cnooc.expert.common.interceptor.LoginInterceptor;
import com.cnooc.expert.common.interceptor.WebAuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class TheWebMvcConfigurer implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // 注册登录拦截器，并设置拦截路径和排除路径
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**") // 拦截所有路径
                .excludePathPatterns( // 排除一些路径
                        "/sys/**",
                        "/verify/**",
                        "/person/**",
                        "/text/**",
                        "/error/**",
                        "/error"
                );

        registry.addInterceptor(webAuthInterceptor());
    }

    @Bean
    public WebAuthInterceptor webAuthInterceptor() {
        return new WebAuthInterceptor();
    }

}
