Guest User

Untitled

a guest
Jun 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. package be.mct.actions;
  2.  
  3. import be.mct.entities.BeerLover;
  4. import java.util.Map;
  5. import javax.persistence.EntityManager;
  6. import javax.persistence.PersistenceContext;
  7. import javax.faces.application.FacesMessage;
  8. import javax.faces.component.ContextCallback;
  9. import javax.faces.component.UIComponent;
  10. import javax.faces.context.FacesContext;
  11.  
  12. public class LoginAction {
  13.  
  14. @PersistenceContext
  15. private EntityManager em;
  16. private BeerLover user;
  17. private Map<String, Object> context;
  18.  
  19. public String execute() {
  20. String qry = "SELECT u FROM BeerLover u" +
  21. " WHERE u.name = :name AND u.password =:password";
  22. try {
  23. BeerLover identity = (BeerLover) em.createQuery(qry).setParameter("name", user.getName()).setParameter("password", user.getPassword()).getSingleResult();
  24. context.put("identity", identity);
  25. return "yours";
  26.  
  27. } catch (Exception ex) {
  28. FacesContext fCtx = FacesContext.getCurrentInstance();
  29. fCtx.getViewRoot().invokeOnComponent(fCtx, "errorLogin",
  30. new ContextCallback() {
  31.  
  32. public void invokeContextCallback(FacesContext context, UIComponent component) {
  33. String clientId = component.getClientId(context);
  34. FacesMessage msg = new FacesMessage();
  35. msg.setDetail("Foute inloggegevens!");
  36. FacesContext.getCurrentInstance().addMessage(clientId, msg);
  37. }
  38. });
  39. return "login";
  40. }
  41. }
  42.  
  43. public BeerLover getUser() {
  44. return user;
  45. }
  46.  
  47. public void setUser(BeerLover user) {
  48. this.user = user;
  49. }
  50.  
  51. public Map<String, Object> getContext() {
  52. return context;
  53. }
  54.  
  55. public void setContext(Map<String, Object> context) {
  56. this.context = context;
  57. }
  58. }
Add Comment
Please, Sign In to add comment