package com.mzh.library.controller;

import com.mzh.library.entity.AuthenticatedUser;
import com.mzh.library.util.SessionAttributes;

import java.io.IOException;

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

public class DashboardServlet extends HttpServlet {
    private static final String DASHBOARD_JSP = "/WEB-INF/jsp/dashboard.jsp";

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession(false);
        AuthenticatedUser user = session == null
            ? null
            : (AuthenticatedUser) session.getAttribute(SessionAttributes.AUTHENTICATED_USER);
        request.setAttribute("currentUser", user);
        request.getRequestDispatcher(DASHBOARD_JSP).forward(request, response);
    }
}
