public WOActionResults doLoginAction() {
WOComponent nextPage = null;
EOEditingContext ec = ERXEC.newEditingContext();
String username = (String) request().formValueForKey("username");
String password = (String) request().formValueForKey("password");
Object redirect = request().formValueForKey("redirect");
Cliente user = Cliente.fetchCliente(ec, Cliente.EMAIL.eq(username));
if (user == null) {
//errore.. utente nn trovato;
nextPage = pageWithName(LoginPage.class);
nextPage.takeValueForKey("utente non trovato", "error");
nextPage.takeValueForKey(username, "username");
nextPage.takeValueForKey(redirect, "redirectTo");
return nextPage;
}
if (! user.password().equals(password)) {
//errore.. password sbagliata
nextPage = pageWithName(LoginPage.class);
nextPage.takeValueForKey("password sbagliata", "error");
nextPage.takeValueForKey(username, "username");
nextPage.takeValueForKey(redirect, "redirectTo");
return nextPage;
}
if (user.activationDate() != 0) {
//errore.. utente non attivo
nextPage = pageWithName(LoginPage.class);
nextPage.takeValueForKey("Utente non ancora attivo. Per favore procedi con l'attivazione", "error");
nextPage.takeValueForKey(username, "username");
nextPage.takeValueForKey(redirect, "redirectTo");
return nextPage;
}
ERXApplication.log.info(context().hasSession()); // it returns false
user = (Cliente) EOUtilities.localInstanceOfObject(session().defaultEditingContext(), user);
ERXApplication.log.info(context().hasSession()); // it returns true
((Session)session()).setUser(user);
if (redirect.equals("account"))
nextPage = pageWithName(AccountPage.class);
return nextPage;
}