Advertisement
Guest User

Untitled

a guest
Jan 27th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.04 KB | None | 0 0
  1. package com.clubmanagementsys.spierewka.beans;
  2.  
  3. import com.clubmanagementsys.spierewka.jpa.dao.ManagerFacade;
  4. import com.clubmanagementsys.spierewka.jpa.dao.PlayerFacade;
  5. import com.clubmanagementsys.spierewka.jpa.dao.UserFacade;
  6. import com.clubmanagementsys.spierewka.jpa.entities.Manager;
  7. import com.clubmanagementsys.spierewka.jpa.entities.Player;
  8. import com.clubmanagementsys.spierewka.jpa.entities.User;
  9. import java.io.Serializable;
  10. import javax.ejb.EJB;
  11. import javax.faces.application.FacesMessage;
  12. import javax.faces.bean.ManagedBean;
  13. import javax.faces.bean.ManagedProperty;
  14. import javax.faces.bean.SessionScoped;
  15. import javax.faces.context.ExternalContext;
  16. import javax.faces.context.FacesContext;
  17. import javax.servlet.http.HttpServletResponse;
  18. import javax.servlet.http.HttpSession;
  19.  
  20. /**
  21.  *
  22.  * @author pawelspierewka
  23.  */
  24. @ManagedBean
  25. @SessionScoped
  26. public class LoginController implements Serializable {
  27.    
  28.     private static final long serialVersionUID = 1L;
  29.  
  30.     private String login;
  31.     private String password;
  32.     private boolean isLogged;
  33.     private boolean btnProfileFormState = false;
  34.    
  35.     @EJB
  36.     private UserFacade userFacade;
  37.    
  38.     @EJB
  39.     private ManagerFacade managerFacade;
  40.    
  41.     @EJB
  42.     private PlayerFacade playerFacade;
  43.    
  44.     @ManagedProperty(value="#{navigationController}")
  45.     private NavigationController navigationController;
  46.    
  47.     @ManagedProperty(value="#{user}")
  48.     private User user;
  49.    
  50.     @ManagedProperty(value="#{player}")
  51.     private Player player;
  52.    
  53.     @ManagedProperty(value="#{manager}")
  54.     private Manager manager;
  55.    
  56.     public LoginController() {
  57.     }
  58.  
  59.     public String getLogin() {
  60.         return login;
  61.     }
  62.  
  63.     public void setLogin(String login) {
  64.         this.login = login;
  65.     }
  66.  
  67.     public String getPassword() {
  68.         return password;
  69.     }
  70.  
  71.     public void setPassword(String password) {
  72.         this.password = password;
  73.     }
  74.    
  75.     public boolean isLoggedIn() {
  76.         return isLogged;
  77.     }
  78.    
  79.     public void setIsLoggedIn(boolean isLogged) {
  80.         this.isLogged = isLogged;
  81.     }
  82.  
  83.     public void setNavigationController(NavigationController navigationController) {
  84.         this.navigationController = navigationController;
  85.     }
  86.    
  87.     public User getUser() {
  88.         return user;
  89.     }
  90.    
  91.     public void setUser(User user) {
  92.         this.user = user;
  93.     }
  94.  
  95.     public void setPlayer(Player player) {
  96.         this.player = player;
  97.     }
  98.  
  99.     public void setManager(Manager manager) {
  100.         this.manager = manager;
  101.     }
  102.  
  103.     public boolean getBtnProfileFormState() {
  104.         return btnProfileFormState;
  105.     }
  106.  
  107.     public void setBtnProfileFormState(boolean btnProfileFormState) {
  108.         this.btnProfileFormState = btnProfileFormState;
  109.     }
  110.    
  111.     public String loginControl() {
  112.         user = userFacade.loginControl(login, password);
  113.         if(user != null) {
  114.             FacesContext context = FacesContext.getCurrentInstance();
  115.             context.getExternalContext().getSessionMap().put("user", user);
  116.             isLogged = true;
  117.             return navigationController.redirectToHome();
  118.         } else {
  119.             FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Nieprawidłowy login lub hasło."));
  120.             return null;
  121.         }
  122.     }
  123.    
  124.     public String logoutControl() {
  125.         ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
  126.         HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
  127.         HttpSession session = (HttpSession)ectx.getSession(false);
  128.         session.invalidate();
  129.         isLogged = false;
  130.         user = null;
  131.         return navigationController.redirectToLogin();
  132.     }
  133.  
  134.     public boolean toggleBtnProfileFormState() {
  135.         if(btnProfileFormState) {
  136.             return btnProfileFormState = false;
  137.         } else {
  138.             return btnProfileFormState = true;
  139.         }
  140.     }
  141.    
  142.     public String saveProfileInfo() {
  143.         return null;
  144.     }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement