package com.command;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import modele.ActionStatus;
import modele.UserSession;
import dao.Dao;
/**
* Servlet implementation class FrontController point d'entrer de toute les
* requete
*/
public class LoginCommand extends FrontCommand {
@Override
public void processRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
/*
* get user login and password values
*/
String curUserName = request.getParameter("login");
String curpassword = request.getParameter("password");
String resultPage = null;
UserSession session = UserSession.getInstance();
ActionStatus a = Dao.validLogin(curUserName, curpassword);
if (a.isStatusValue()) {
Dao.setCurrentUser(curUserName);
request.setAttribute("ressources", Dao.getUser(curUserName)
.getRessources());
session.authentifiedUser = Dao.getUser(curUserName);
session.sessionID = request.getSession().getId();
} else {
request.setAttribute("Message", a.getStatusDescription());
resultPage = "/jsp/DisplayMessage.jsp";
forward(resultPage, request, response);
return;
}
response.setContentType("text/html");
resultPage = "/jsp/menu.jsp";
forward(resultPage, request, response);
}
}