SHARE
TWEET

Untitled

a guest Mar 20th, 2016 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String surname=loginController.getCurrentUser().getSurname();
  2.    
  3. <h:form class="form">              
  4.  
  5.     <p:growl id="growl" showDetail="false" />
  6.  
  7.     <pm:field>
  8.         <h:inputText id="username" value="#{userLogin.username}" label="Username" required="true" requiredMessage="Username: This field is required." title="Enter your username." pt:placeholder="Username" />                    
  9.     </pm:field>
  10.  
  11.     <pm:field>
  12.         <h:inputSecret  id="password" value="#{userLogin.password}" label="Password" required="true" requiredMessage="Password: This field is required." title="Enter your password." pt:placeholder="Password" />
  13.     </pm:field>                
  14.  
  15.     <p:commandButton value="Login" action="#{loginController.login}" update="growl" styleClass="buttonStyle"/>                  
  16.  
  17. </h:form>
  18.    
  19. @Named
  20. @SessionScoped
  21. public class LoginController implements Serializable {
  22.  
  23.     private static final long serialVersionUID = -6322113716363932422L;
  24.  
  25.     public void start(){
  26.  
  27.         //Redirecting if the user is not logged in.
  28.     }
  29.  
  30.     public void check(){
  31.  
  32.         //Redirecting to home page if the user is logged in.
  33.     }
  34.  
  35.     public String login(){      
  36.  
  37.         if(userService.login(userLogin)){
  38.  
  39.             currentUser=userService.getCurrnetUser(userLogin.getUsername());
  40.  
  41.             return "home?faces-redirect=true";          
  42.         }
  43.         else{
  44.  
  45.             facesContext.addMessage(null, new FacesMessage("Data entered are incorrect"));
  46.             return null;
  47.         }
  48.     }
  49.  
  50.     public String logout(){
  51.  
  52.         currentUser=null;
  53.  
  54.         return "login?faces-redirect=true";
  55.     }
  56.  
  57.     public boolean isLoggedIn() {
  58.  
  59.           return currentUser!=null;
  60.     }
  61.  
  62.     @Produces
  63.     @LoggedIn
  64.     public UserAccount getCurrentUser(){
  65.  
  66.         return currentUser;
  67.     }  
  68.  
  69.     @Inject
  70.     private FacesContext facesContext;
  71.  
  72.     @Inject
  73.     private UserServiceImpl userService;
  74.  
  75.     @Named
  76.     @Produces
  77.     @RequestScoped
  78.     private UserAccount userLogin=new UserAccount();
  79.  
  80.     private UserAccount currentUser;
  81. }
  82.    
  83. @Named
  84. @RequestScoped
  85. public class DataServiceImpl implements DataService {
  86.  
  87.     @Override
  88.     public void addData(String[] data) {
  89.  
  90.         //Proccess some data
  91.  
  92.         String surname=loginController.getCurrentUser().getSurname();
  93.  
  94.         //Proccess some data
  95.     }
  96.  
  97.     @Inject
  98.     private LoginController loginController;
  99. }
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