70 lines
1.6 KiB
Java
70 lines
1.6 KiB
Java
package managedbean.systemAdmin;
|
|
|
|
import java.io.Serializable;
|
|
|
|
import javax.faces.application.FacesMessage;
|
|
import javax.faces.bean.ManagedBean;
|
|
import javax.faces.bean.SessionScoped;
|
|
import javax.faces.context.FacesContext;
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
import common.SessionUtils;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
@ManagedBean(name = "login")
|
|
@SessionScoped
|
|
public class LoginMBean implements Serializable {
|
|
|
|
private static final long serialVersionUID = 1094801825228386363L;
|
|
|
|
private String Password;
|
|
private String msg;
|
|
private String userName;
|
|
|
|
public String getPassword() {
|
|
return Password;
|
|
}
|
|
|
|
public void setPassword(String pwd) {
|
|
this.Password = pwd;
|
|
}
|
|
|
|
public String getMsg() {
|
|
return msg;
|
|
}
|
|
|
|
public void setMsg(String msg) {
|
|
this.msg = msg;
|
|
}
|
|
|
|
public String getUserName() {
|
|
return userName;
|
|
}
|
|
|
|
public void setUserName(String user) {
|
|
this.userName = user;
|
|
}
|
|
|
|
// validate login
|
|
public String validateUsernamePassword() {
|
|
// TODO: Validar login
|
|
boolean valid = this.userName.startsWith("a");
|
|
if (valid) {
|
|
HttpSession session = SessionUtils.getSession();
|
|
session.setAttribute("username", userName);
|
|
return "home";
|
|
} else {
|
|
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,
|
|
"Usuario o contraseña incorrecta", "Por favor, intentalo de nuevo"));
|
|
return "login";
|
|
}
|
|
}
|
|
|
|
// logout event, invalidate session
|
|
public String logout() {
|
|
HttpSession session = SessionUtils.getSession();
|
|
session.invalidate();
|
|
return "home";
|
|
}
|
|
}
|