Created
July 26, 2017 09:32
-
-
Save SakaDream/74903668c10677d011dd755cb55f1a69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sakadream.jsf.controller; | |
import com.sakadream.jsf.func.Functions; | |
import javax.faces.application.FacesMessage; | |
import javax.faces.bean.ManagedBean; | |
import javax.faces.bean.RequestScoped; | |
import javax.faces.context.FacesContext; | |
import javax.servlet.http.HttpSession; | |
import java.io.Serializable; | |
import java.sql.SQLException; | |
/** | |
* Created by Phan Ba Hai on 17/07/2017. | |
*/ | |
@ManagedBean(name = "login", eager = true) | |
@RequestScoped | |
public class LoginController implements Serializable { | |
private Functions func = new Functions(); | |
public String login() throws SQLException, ClassNotFoundException { | |
FacesContext context = FacesContext.getCurrentInstance(); | |
String username = func.getParameterByName("username"); | |
String password = func.getParameterByName("password"); | |
boolean valid = func.checkLogin(username, password); | |
if(valid) return "home"; | |
else { | |
context.addMessage("loginForm", | |
new FacesMessage(FacesMessage.SEVERITY_ERROR, "Username or password not valid, please try again!", "")); | |
return null; | |
} | |
} | |
public String logout() { | |
HttpSession session = func.getSession(); | |
session.invalidate(); | |
return "login"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment