package controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import manager.PersonnelManager;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import domain.Personnel;
import domain.Responsable;
import domain.Secretary;
public class PersonnelLoginCTRL extends SimpleFormController {
private PersonnelManager pmng;
/**
* Returns the value of the attribute pmng
* @return the pmng of type PersonnelManager
*/
public PersonnelManager getPmng() {
return pmng;
}
/**
* Initiates the attribute pmng with the value of pmng
* @param pmng the value for pmng to set
*/
public void setPmng(PersonnelManager pmng) {
this.pmng = pmng;
}
public PersonnelLoginCTRL() {
setCommandName("personnel");
setCommandClass(Personnel.class);
setFormView("personnellogin");
}
/* (non-Javadoc)
* @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
*/
@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException be) throws Exception {
HttpSession session = request.getSession(true);
//session.setMaxInactiveInterval(5);
ModelAndView mav = null;
String login = request.getParameter("login");
String password = request.getParameter("password");
System.out.println("ICICICICIC "+password);
if(login == null || password == null || login.equals("") || password.equals("")){
be.rejectValue("login", "login.valide","Tous les champs sont obligatoires");
return showForm(request,response,be);
}
Personnel pers = this.pmng.findByLoginAndPassword(login, password);
if(pers == null){
be.rejectValue("login", "login.valide","Identifiant(s) invalide(s)");
return showForm(request,response,be);
}else if (pers.getClass().isAssignableFrom(Responsable.class)){
session.setAttribute("responsable", pers);
}else if(pers.getClass().isAssignableFrom(Secretary.class)){
session.setAttribute("secretary", pers);
}
//System.out.println(password);
mav = new ModelAndView("login-ok");
return mav;
}
}