Advertisement
Guest User

Untitled

a guest
Jun 16th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. @Named
  2. @RequestScoped
  3. public class UserLoginBean implements Serializable {
  4.  
  5. @EJB(mappedName = "java:global/CatalogServer/UserLoggedController!com.jasiolek173.character.catalog.Controller.IUserLoggedController")
  6. private IUserLoggedController userLoggedController;
  7. @Inject
  8. private Receiver receiver;
  9. private String username;
  10. private String password;
  11.  
  12. public String getUsername() {
  13. return username;
  14. }
  15.  
  16. public void setUsername(String username) {
  17. this.username = username;
  18. }
  19.  
  20. public String getPassword() {
  21. return password;
  22. }
  23.  
  24. public void setPassword(String password) {
  25. this.password = password;
  26. }
  27.  
  28. @PostConstruct
  29. public void init() {
  30. if (Util.getUserName() != null) {
  31. Util.redirect("index.xhtml");
  32. }
  33. }
  34.  
  35. public void login() {
  36. FacesContext context = FacesContext.getCurrentInstance();
  37. HttpServletRequest request = (HttpServletRequest)
  38. context.getExternalContext().getRequest();
  39. try {
  40. if (userLoggedController.isUserLoggedIn(username)) {
  41. MessageAdder.warn("User with that username is logged in");
  42. } else {
  43. request.login(this.username, this.password);
  44. userLoggedController.addUserToLoggedIn(username);
  45. MessageAdder.info("Log in !");
  46. receiver.setupReceiver();
  47. Util.redirect("index.xhtml");
  48. }
  49. } catch (ServletException e) {
  50. MessageAdder.error("Log in failed.");
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement