package org.holer.server.interceptor;

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

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

@Component
public class ViewInterceptor implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest req, HttpServletResponse rep, Object handler) throws Exception {
        HttpSession session = req.getSession(false);
        if (null == session) {
            rep.sendRedirect("/login.html");
            return false;
        }
        Object token = session.getAttribute("NOSUM-AUTH-TOKEN");
        if (null == token) {
            rep.sendRedirect("/login.html");
            return false;
        }
        return true;
    }
}
