Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.clubmanagementsys.spierewka.beans;
- import com.clubmanagementsys.spierewka.jpa.dao.ManagerFacade;
- import com.clubmanagementsys.spierewka.jpa.dao.PlayerFacade;
- import com.clubmanagementsys.spierewka.jpa.dao.UserFacade;
- import com.clubmanagementsys.spierewka.jpa.entities.Manager;
- import com.clubmanagementsys.spierewka.jpa.entities.Player;
- import com.clubmanagementsys.spierewka.jpa.entities.User;
- import java.io.Serializable;
- import javax.ejb.EJB;
- import javax.faces.application.FacesMessage;
- import javax.faces.bean.ManagedBean;
- import javax.faces.bean.ManagedProperty;
- import javax.faces.bean.SessionScoped;
- import javax.faces.context.ExternalContext;
- import javax.faces.context.FacesContext;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- /**
- *
- * @author pawelspierewka
- */
- @ManagedBean
- @SessionScoped
- public class LoginController implements Serializable {
- private static final long serialVersionUID = 1L;
- private String login;
- private String password;
- private boolean isLogged;
- private boolean btnProfileFormState = false;
- @EJB
- private UserFacade userFacade;
- @EJB
- private ManagerFacade managerFacade;
- @EJB
- private PlayerFacade playerFacade;
- @ManagedProperty(value="#{navigationController}")
- private NavigationController navigationController;
- @ManagedProperty(value="#{user}")
- private User user;
- @ManagedProperty(value="#{player}")
- private Player player;
- @ManagedProperty(value="#{manager}")
- private Manager manager;
- public LoginController() {
- }
- public String getLogin() {
- return login;
- }
- public void setLogin(String login) {
- this.login = login;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public boolean isLoggedIn() {
- return isLogged;
- }
- public void setIsLoggedIn(boolean isLogged) {
- this.isLogged = isLogged;
- }
- public void setNavigationController(NavigationController navigationController) {
- this.navigationController = navigationController;
- }
- public User getUser() {
- return user;
- }
- public void setUser(User user) {
- this.user = user;
- }
- public void setPlayer(Player player) {
- this.player = player;
- }
- public void setManager(Manager manager) {
- this.manager = manager;
- }
- public boolean getBtnProfileFormState() {
- return btnProfileFormState;
- }
- public void setBtnProfileFormState(boolean btnProfileFormState) {
- this.btnProfileFormState = btnProfileFormState;
- }
- public String loginControl() {
- user = userFacade.loginControl(login, password);
- if(user != null) {
- FacesContext context = FacesContext.getCurrentInstance();
- context.getExternalContext().getSessionMap().put("user", user);
- isLogged = true;
- return navigationController.redirectToHome();
- } else {
- FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Nieprawidłowy login lub hasło."));
- return null;
- }
- }
- public String logoutControl() {
- ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
- HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
- HttpSession session = (HttpSession)ectx.getSession(false);
- session.invalidate();
- isLogged = false;
- user = null;
- return navigationController.redirectToLogin();
- }
- public boolean toggleBtnProfileFormState() {
- if(btnProfileFormState) {
- return btnProfileFormState = false;
- } else {
- return btnProfileFormState = true;
- }
- }
- public String saveProfileInfo() {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement