diff --git a/src/main/java/de/hsel/itech/db/PaymentDB.java b/src/main/java/de/hsel/itech/db/PaymentDB.java index 0f87a51..1cec6a0 100644 --- a/src/main/java/de/hsel/itech/db/PaymentDB.java +++ b/src/main/java/de/hsel/itech/db/PaymentDB.java @@ -45,11 +45,20 @@ public class PaymentDB { @NotNull public List get(@NotNull User user) { List list = new ArrayList<>(); + Map.Entry entry = database.getResultSetByValue(database.tableUserPayment, "user", user.getId()); + assert entry != null; - List ids = database.getIds(database.tableUserPayment); - for(long id : ids) { - list.add(get(id)); + try { + ResultSet rs = entry.getKey(); + while(rs.next()) { + list.add(get(rs.getLong("id"))); + } + + entry.getValue().close(); + } catch (SQLException e) { + e.printStackTrace(); } + return list; } @@ -58,20 +67,16 @@ public class PaymentDB { Map.Entry metadata = getMetadata(id); assert metadata != null; - String typeName = metadata.getValue().getName(); - if(typeName.equals("PayPal")) { - return getPayPal(id, metadata.getKey()); + switch (metadata.getValue().getName()) { + case "PayPal": + return getPayPal(id, metadata.getKey()); + case "CreditCard": + return getCreditCard(id, metadata.getKey()); + case "DebitCard": + return getDebitCard(id, metadata.getKey()); + case "Invoice": + return getInvoice(id, metadata.getKey()); } - if(typeName.equals("CreditCard")) { - return getCreditCard(id, metadata.getKey()); - } - if(typeName.equals("DebitCard")) { - return getDebitCard(id, metadata.getKey()); - } - if(typeName.equals("Invoice")) { - return getInvoice(id, metadata.getKey()); - } - return null; } diff --git a/src/main/java/de/hsel/itech/db/UserDB.java b/src/main/java/de/hsel/itech/db/UserDB.java index 36bbd15..809a738 100644 --- a/src/main/java/de/hsel/itech/db/UserDB.java +++ b/src/main/java/de/hsel/itech/db/UserDB.java @@ -33,13 +33,31 @@ public class UserDB { ResultSet rs = entry.getKey(); try { - return new User(rs.getString("email"), rs.getString("name"), rs.getString("password"), rs.getShort("type")); + User user = null; + while(rs.next()) { + user = new User(id, rs.getString("email"), rs.getString("name"), rs.getString("password"), rs.getShort("type")); + } + entry.getValue().close(); + return user; } catch (SQLException e) { e.printStackTrace(); } + return null; + } + + @Nullable + public User get(String name) { + Map.Entry entry = database.getResultSetsByValue(database.tableUser, "name", name); + assert entry != null; try { + ResultSet rs = entry.getKey(); + User user = null; + while(rs.next()) { + user = new User(rs.getLong("id"), rs.getString("email"), rs.getString("name"), rs.getString("password"), rs.getShort("type")); + } entry.getValue().close(); + return user; } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/main/java/de/hsel/itech/jsf/PaymentBean.java b/src/main/java/de/hsel/itech/jsf/PaymentBean.java new file mode 100644 index 0000000..64524a3 --- /dev/null +++ b/src/main/java/de/hsel/itech/jsf/PaymentBean.java @@ -0,0 +1,23 @@ +package de.hsel.itech.jsf; + +import de.hsel.itech.db.Database; +import de.hsel.itech.db.pojo.Payment; +import de.hsel.itech.db.pojo.User; + +import javax.faces.annotation.ManagedProperty; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; +import java.util.List; + +@ManagedBean +@SessionScoped +public class PaymentBean { + + @ManagedProperty("#{userBean.user}") + private User user; + + public List getMethods() { + return Database.getInstance().payment().get(user); + } + +} \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/jsf/UserBean.java b/src/main/java/de/hsel/itech/jsf/UserBean.java new file mode 100644 index 0000000..149b4ee --- /dev/null +++ b/src/main/java/de/hsel/itech/jsf/UserBean.java @@ -0,0 +1,53 @@ +package de.hsel.itech.jsf; + +import de.hsel.itech.db.Database; +import de.hsel.itech.db.pojo.User; +import lombok.Getter; +import lombok.Setter; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; + +@ManagedBean +@SessionScoped +public class UserBean { + + @Getter + private User user; + + @Getter + @Setter + private String username; + + @Getter + @Setter + private String password; + + @Getter + private boolean loggedIn = false; + + @Getter + private boolean correctPassword = true; + + + public String login() { + Database db = Database.getInstance(); + User user = db.user().get(username); + + if (user == null) { + correctPassword = false; + return ""; + } + + if (db.user().verify(user, password)) { + loggedIn = true; + this.user = user; + return "index.xhtml"; + } + correctPassword = false; + return ""; + + + } + +} \ No newline at end of file diff --git a/src/main/resources/icon.png b/src/main/resources/icon.png deleted file mode 100644 index bb1355d..0000000 Binary files a/src/main/resources/icon.png and /dev/null differ diff --git a/src/main/webapp/login.xhtml b/src/main/webapp/login.xhtml new file mode 100644 index 0000000..2571f88 --- /dev/null +++ b/src/main/webapp/login.xhtml @@ -0,0 +1,36 @@ + + + + + + + + + + + + +
+
+ + Nutzername +
+ Passwort + + Login +
+
+
+ + +
+ +
+
+