// Path: src/main/java/com/pollistics/utils/AuthHandlerInterceptor.java
// public class AuthHandlerInterceptor extends HandlerInterceptorAdapter {
// 	@Override
// 	public void postHandle(final HttpServletRequest request,
// 						   final HttpServletResponse response, final Object handler,
// 						   final ModelAndView modelAndView) throws Exception {
// 
// 		Authentication auth = SecurityContextHolder.getContext().getAuthentication();
// 		if(auth != null) {
// 			Object user = auth.getPrincipal();
// 			if (modelAndView != null && user instanceof User) {
// 				modelAndView.getModelMap().addAttribute("user", (User) user);
// 			}
// 		}
// 	}
// }


import org.jtwig.environment.EnvironmentConfigurationBuilder;
import org.jtwig.hot.reloading.HotReloadingExtension;
import org.jtwig.spring.JtwigViewResolver;
import org.jtwig.spring.asset.SpringAssetExtension;
import org.jtwig.spring.asset.resolver.AssetResolver;
import org.jtwig.spring.asset.resolver.BaseAssetResolver;
import org.jtwig.spring.boot.config.JtwigViewResolverConfigurer;
import org.jtwig.web.servlet.JtwigRenderer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import com.pollistics.utils.AuthHandlerInterceptor;
package com.pollistics.config;



@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter implements JtwigViewResolverConfigurer {

	@Override
	public void configure(JtwigViewResolver viewResolver) {
		viewResolver.setRenderer(new JtwigRenderer(
			EnvironmentConfigurationBuilder.configuration()
				.extensions()
				.add(new HotReloadingExtension())
				.add(new SpringAssetExtension())
				.and()
				.build()
		));
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(authInterceptor());
	}

	@Bean
	public AssetResolver assetResolver () {
		BaseAssetResolver assetResolver = new BaseAssetResolver();
		assetResolver.setPrefix("");
		return assetResolver;
	}

	@Bean
// Path: src/main/java/com/pollistics/utils/AuthHandlerInterceptor.java
// public class AuthHandlerInterceptor extends HandlerInterceptorAdapter {
// 	@Override
// 	public void postHandle(final HttpServletRequest request,
// 						   final HttpServletResponse response, final Object handler,
// 						   final ModelAndView modelAndView) throws Exception {
// 
// 		Authentication auth = SecurityContextHolder.getContext().getAuthentication();
// 		if(auth != null) {
// 			Object user = auth.getPrincipal();
// 			if (modelAndView != null && user instanceof User) {
// 				modelAndView.getModelMap().addAttribute("user", (User) user);
// 			}
// 		}
// 	}
// }


// Path: src/main/java/com/pollistics/config/WebConfig.java
import org.jtwig.environment.EnvironmentConfigurationBuilder;
import org.jtwig.hot.reloading.HotReloadingExtension;
import org.jtwig.spring.JtwigViewResolver;
import org.jtwig.spring.asset.SpringAssetExtension;
import org.jtwig.spring.asset.resolver.AssetResolver;
import org.jtwig.spring.asset.resolver.BaseAssetResolver;
import org.jtwig.spring.boot.config.JtwigViewResolverConfigurer;
import org.jtwig.web.servlet.JtwigRenderer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import com.pollistics.utils.AuthHandlerInterceptor;

package com.pollistics.config;



@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter implements JtwigViewResolverConfigurer {

	@Override
	public void configure(JtwigViewResolver viewResolver) {
		viewResolver.setRenderer(new JtwigRenderer(
			EnvironmentConfigurationBuilder.configuration()
				.extensions()
				.add(new HotReloadingExtension())
				.add(new SpringAssetExtension())
				.and()
				.build()
		));
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(authInterceptor());
	}

	@Bean
	public AssetResolver assetResolver () {
		BaseAssetResolver assetResolver = new BaseAssetResolver();
		assetResolver.setPrefix("");
		return assetResolver;
	}

	@Bean
	public AuthHandlerInterceptor authInterceptor() {