SHARE
TWEET

Untitled

a guest Jul 21st, 2017 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. import com.mysql.jdbc.Statement;
  7. import java.io.IOException;
  8. import java.io.Serializable;
  9. import java.sql.Connection;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import java.util.Random;
  13. import java.util.logging.Level;
  14. import java.util.logging.Logger;
  15. import javax.enterprise.context.RequestScoped;
  16. import javax.faces.application.FacesMessage;
  17. import javax.faces.bean.ManagedBean;
  18. import javax.faces.bean.SessionScoped;
  19. import javax.faces.component.UIMessage;
  20. import javax.faces.context.ExternalContext;
  21. import javax.faces.context.FacesContext;
  22. import javax.faces.event.ActionEvent;
  23. import javax.servlet.http.HttpSession;
  24. import org.primefaces.context.RequestContext;
  25.  
  26. /**
  27.  *
  28.  * @author serendipity
  29.  */
  30. @ManagedBean(name="LoginBean")
  31. @RequestScoped
  32. public class LoginBean {
  33. boolean loggedIn = false;
  34.  
  35.     public boolean isLoggedIn() {
  36.         return loggedIn;
  37.     }
  38.     private String username;
  39.  
  40.     private String password;
  41.  
  42.     public String getUsername() {
  43.         return username;
  44.     }
  45.  
  46.     public void setUsername(String username) {
  47.         this.username = username;
  48.     }
  49.  
  50.     public String getPassword() {
  51.         return password;
  52.     }
  53.  
  54.     public void setPassword(String password) {
  55.         this.password = password;
  56.     }
  57.  
  58.     public boolean   login(ActionEvent actionEvent) throws IOException {
  59.         RequestContext context = RequestContext.getCurrentInstance();
  60.         FacesMessage msg = null;
  61.        
  62.             if(username != null  && username.equals("admin") && password != null  && password.equals("admin")) {
  63.             loggedIn = true;
  64.             msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Dobrodošli", username);
  65.         } else {
  66.             loggedIn = false;
  67.             msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Napaka", "Napačni podatki");
  68.         }
  69.                
  70.           FacesContext.getCurrentInstance().addMessage(null, msg);
  71.             context.addCallbackParam("loggedIn", loggedIn);
  72.  
  73.          //    FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(), null, "index.xhtml");
  74.      if(loggedIn){return true;
  75.          
  76.        //  FacesContext.getCurrentInstance().getExternalContext().redirect("index.xhtml?faces-redirect=true");
  77.      
  78.  
  79.      }else return false;
  80.    
  81.  
  82.         /*    FacesContext fc = FacesContext.getCurrentInstance();
  83.             ExternalContext ec= fc.getExternalContext();
  84.             ec.redirect("response.xhtml");
  85.             fc.responseComplete();}
  86.             //  FacesContext.getCurrentInstance().renderResponse();*/
  87.     //FacesContext.getCurrentInstance().getExternalContext().dispatch("index.xhtml");
  88.  
  89.         }
  90.  
  91.  
  92. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top