package zall.page;

import zall.ZalleryServlet;
import zall.bean.User;
import zall.manager.AuthenticationManager;
import zutil.db.DBConnection;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 *
 */
@WebServlet(LogoutServlet.URI)
public class LogoutServlet extends ZalleryServlet {

    public static final String URI = "/logout";

    public void doGet(HttpServletRequest request, HttpServletResponse response, DBConnection db) throws SQLException, IOException {
        User user = AuthenticationManager.getUserSession(request.getSession());

        AuthenticationManager.reset(db, user);
        AuthenticationManager.rmUserSession(request.getSession());

        response.sendRedirect("/login");
    }

}
