diff --git a/faces-config.NavData b/faces-config.NavData index 187ec92..298bfc5 100644 --- a/faces-config.NavData +++ b/faces-config.NavData @@ -1,6 +1,6 @@ - - - - - - + + + + + + diff --git a/src/main/java/dat076/frukostklubben/bb/CustomerController.java b/src/main/java/dat076/frukostklubben/bb/CustomerController.java index 439bff1..fbc8210 100644 --- a/src/main/java/dat076/frukostklubben/bb/CustomerController.java +++ b/src/main/java/dat076/frukostklubben/bb/CustomerController.java @@ -1,7 +1,3 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package dat076.frukostklubben.bb; import java.util.ArrayList; diff --git a/src/main/java/dat076/frukostklubben/bb/SignupBB.java b/src/main/java/dat076/frukostklubben/bb/SignupBB.java index 235cb54..dc93104 100644 --- a/src/main/java/dat076/frukostklubben/bb/SignupBB.java +++ b/src/main/java/dat076/frukostklubben/bb/SignupBB.java @@ -1,11 +1,7 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package dat076.frukostklubben.bb; -import dat076.frukostklubben.ejb.CustomerEJB; -import dat076.frukostklubben.model.Customer; +import dat076.frukostklubben.ejb.UserEJB; +import dat076.frukostklubben.model.User; import javax.ejb.EJB; import javax.enterprise.context.RequestScoped; import javax.faces.application.FacesMessage; @@ -16,20 +12,19 @@ /** * * @author Julia + * Edited by: Anders, 2012-10-17 */ @Named("signup") -@RequestScoped //created once for every request +@RequestScoped public class SignupBB { - + // ====================================== // = Attributes = // ====================================== @EJB - CustomerEJB customerRegistry; - - private Customer customer = new Customer(); - + UserEJB userRegistry; + private User user = new User(); private String passwdConfirm; // ====================================== @@ -37,13 +32,12 @@ public class SignupBB { // ====================================== public String doCreateCustomer() { - //log.log(Level.INFO, "New Customer Login {0} Passwd {1}", new Object[]{login, passwd}); try { - customer = customerRegistry.createCustomer(customer); - return "index.xhtml"; //or some confirmation page + user = userRegistry.createUser(user); + return "index.xhtml"; } catch (Exception e) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Bad Login name")); - return null; // Same page + return null; // Stay on same page } } @@ -51,17 +45,16 @@ public String doCreateCustomer() { // = Getters & Setters = // ====================================== - public Customer getCustomer(){ - return this.customer; + public User getUser(){ + return this.user; } - public void setCutomer(Customer customer){ - this.customer = customer; + public void setUser(User user){ + this.user = user; } public void passwdConfirm(String passwdConfirm){ this.passwdConfirm = passwdConfirm; - //do something real... } public String getpasswdConfirm(){ diff --git a/src/main/java/dat076/frukostklubben/ejb/CustomerEJB.java b/src/main/java/dat076/frukostklubben/ejb/CustomerEJB.java deleted file mode 100644 index 3afc03f..0000000 --- a/src/main/java/dat076/frukostklubben/ejb/CustomerEJB.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package dat076.frukostklubben.ejb; - -import dat076.frukostklubben.model.Customer; -import java.util.List; -import javax.ejb.LocalBean; -import javax.ejb.Stateless; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.TypedQuery; - -/** - * - * @author freein - */ -@Stateless -@LocalBean -public class CustomerEJB implements CustomerEJBRemote { - - @PersistenceContext(unitName = "projectPU") - private EntityManager em; - - @Override - public List findCustomers() { - TypedQuery query = em.createNamedQuery("findAllCustomers", Customer.class); - return query.getResultList(); - } - - @Override - public Customer findCustomerById(Long id) { - return em.find(Customer.class, id); - } - - @Override - public Customer createCustomer(Customer customer) { - em.persist(customer); - return customer; - } - - @Override - public void deleteCustomer(Customer customer) { - em.remove(em.merge(customer)); - } - - @Override - public Customer updateCustomer(Customer customer) { - return em.merge(customer); - } -} diff --git a/src/main/java/dat076/frukostklubben/ejb/CustomerEJBRemote.java b/src/main/java/dat076/frukostklubben/ejb/CustomerEJBRemote.java deleted file mode 100644 index 2747588..0000000 --- a/src/main/java/dat076/frukostklubben/ejb/CustomerEJBRemote.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package dat076.frukostklubben.ejb; - -import dat076.frukostklubben.model.Customer; -import java.util.List; -import javax.ejb.Remote; - -/** - * - * @author freein - */ -@Remote -public interface CustomerEJBRemote { - List findCustomers(); - Customer findCustomerById(Long id); - Customer createCustomer(Customer customer); - void deleteCustomer(Customer customer); - Customer updateCustomer(Customer customer); -} diff --git a/src/main/java/dat076/frukostklubben/ejb/UserEJB.java b/src/main/java/dat076/frukostklubben/ejb/UserEJB.java new file mode 100644 index 0000000..0decf38 --- /dev/null +++ b/src/main/java/dat076/frukostklubben/ejb/UserEJB.java @@ -0,0 +1,49 @@ +package dat076.frukostklubben.ejb; + +import dat076.frukostklubben.model.User; +import java.util.List; +import javax.ejb.LocalBean; +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.TypedQuery; + +/** + * + * @author freein + * Edited by: Anders, 2012-10-17 + */ +@Stateless +@LocalBean +public class UserEJB implements UserEJBRemote { + + @PersistenceContext(unitName = "projectPU") + private EntityManager em; + + @Override + public List findUsers() { + TypedQuery query = em.createNamedQuery("findAllUsers", User.class); + return query.getResultList(); + } + + @Override + public User findUserById(Long id) { + return em.find(User.class, id); + } + + @Override + public User createUser(User user) { + em.persist(user); + return user; + } + + @Override + public void deleteUser(User user) { + em.remove(em.merge(user)); + } + + @Override + public User updateUser(User user) { + return em.merge(user); + } +} diff --git a/src/main/java/dat076/frukostklubben/ejb/UserEJBRemote.java b/src/main/java/dat076/frukostklubben/ejb/UserEJBRemote.java new file mode 100644 index 0000000..7fd0873 --- /dev/null +++ b/src/main/java/dat076/frukostklubben/ejb/UserEJBRemote.java @@ -0,0 +1,19 @@ +package dat076.frukostklubben.ejb; + +import dat076.frukostklubben.model.User; +import java.util.List; +import javax.ejb.Remote; + +/** + * + * @author freein + * Edited by: Anders, 2012-10-17 + */ +@Remote +public interface UserEJBRemote { + List findUsers(); + User findUserById(Long id); + User createUser(User customer); + void deleteUser(User customer); + User updateUser(User customer); +} diff --git a/src/main/java/dat076/frukostklubben/model/Customer.java b/src/main/java/dat076/frukostklubben/model/User.java similarity index 72% rename from src/main/java/dat076/frukostklubben/model/Customer.java rename to src/main/java/dat076/frukostklubben/model/User.java index 7253ffe..a1a3400 100644 --- a/src/main/java/dat076/frukostklubben/model/Customer.java +++ b/src/main/java/dat076/frukostklubben/model/User.java @@ -17,10 +17,19 @@ /** * * @author Fredrik + * Edited by: Anders, 2012-10-17 */ @Entity -@NamedQuery(name = "findAllCustomers", query = "SELECT c FROM Customer c") -public class Customer implements Serializable { +@NamedQuery(name = "findAllUsers", query = "SELECT u FROM User u") +public class User implements Serializable { + + // Access level for user account. + public enum Access{ + ADMIN, + USER + } + + @Id @GeneratedValue private long id; @@ -31,15 +40,19 @@ public class Customer implements Serializable { @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) private Address address; private String password; + private Access access; - public Customer(String firstName, String lastName, String mail, Address address) { + + + public User(String firstName, String lastName, String mail, Address address, Access access) { this.firstName = firstName; this.lastName = lastName; this.mail = mail; this.address = address; + this.access = access; } - public Customer() { + public User() { } public long getId() { @@ -52,9 +65,7 @@ public String getPassword() { public void setPassword(String password) { this.password = password; - } - - + } public void setId(long id) { this.id = id; @@ -91,6 +102,12 @@ public Address getAddress() { public void setAddress(Address address) { this.address = address; } - - + + public void setAccess(Access access) { + this.access = access; + } + + public Access getAccess() { + return access; + } } diff --git a/src/main/webapp/pages/index.xhtml b/src/main/webapp/pages/index.xhtml index 7e96162..e5def55 100644 --- a/src/main/webapp/pages/index.xhtml +++ b/src/main/webapp/pages/index.xhtml @@ -6,7 +6,6 @@ xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:ace="http://www.icefaces.org/icefaces/components"> -
@@ -14,25 +13,20 @@

Search for a flight now!

-


+


- -


-

- -


-

- + +


+

+ +


+

+ - +
- - -
-
- - + \ No newline at end of file diff --git a/src/main/webapp/pages/signup.xhtml b/src/main/webapp/pages/signup.xhtml index 046f5a8..1c513e4 100644 --- a/src/main/webapp/pages/signup.xhtml +++ b/src/main/webapp/pages/signup.xhtml @@ -20,30 +20,30 @@


-

+


-

+


-

+


-

+


-

+


-

+


-

+


-