package eu.semberal.reminders.stripes.action;
import eu.semberal.reminders.entity.User;
import eu.semberal.reminders.service.AdminService;
import eu.semberal.reminders.service.InvalidCredentialsException;
import eu.semberal.reminders.stripes.action.secure.DashboardActionBean;
import net.sourceforge.stripes.action.*;
import net.sourceforge.stripes.integration.spring.SpringBean;
import net.sourceforge.stripes.validation.LocalizableError;
/**
* This actionbean handler user login. Doesnt do any validation, just decides if login is ok.
*
* @author Lukas Sembera
*/
public class LoginActionBean extends AbstractActionBean {
@SpringBean("adminService") private AdminService adminService;
private String email;
private String password;
@DefaultHandler
@DontBind
public Resolution form() {
return new ForwardResolution("/WEB-INF/pages/login.jsp");
}
public Resolution login() {
try {
User u = adminService.authenticateUser(email, password, true);
getContext().setUser(u);
return new RedirectResolution(DashboardActionBean.class);
} catch (InvalidCredentialsException e) {
getContext().getRequest().setAttribute("loginFailed", true);
return new ForwardResolution("/WEB-INF/pages/login.jsp");
}
}
/* getters and setters */
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}