l.info("Processing Login Request from session "+req.getSession().getId());
Visitor v = login.getVistor();
Customer cust = null;
View resultView = null;
try {
cust = service.authenticateCustomer(req.getParameter(Parameters.EMAIL.getId()), req.getParameter(Parameters.PASSWORD.getId()));
if (cust != null) {
l.info("Login Successful for "+cust.getPerson().getLogin());
v.setCustomer(cust);
v.setAuthenticated(true);
v.setKnown(true);
v.setRemember(req.getParameter(Parameters.REMEMBER_ME.getId()) != null);
req.getSession().setAttribute(SESSION_ATTRIBUTE_VISITOR, v);
req.getSession().setAttribute(SESSION_ATTRIBUTE_USER_NAME, v.getEmail());
login.setForm(FormName.LOGIN);
login.setSuccess(true);
}
else {
resultView = getLoginView("Invalid email or password. Please try again.", getMainView());
}
} catch (Exception e) {
l.log(Level.INFO, "Failed authentication", e);
resultView = getLoginView("Invalid email or password. Please try again.", getMainView());
}
if (v.isAuthenticated()) try {
CartService cs = new CartService();
l.info("retrieving cart for customerId:"+cust.getId());
req.getSession().setAttribute(SESSION_ATTRIBUTE_CART, cs.getByCustomerId(cust.getId()));
if (login.getRedirect() != null) {
l.info("redirecting to "+login.getRedirect());
resultView = new View();
resultView.setRedirectPath(login.getRedirect());
}
else {
resultView = processPostLogin();
}