From c091084584c91c9001382cfafd086891249970d5 Mon Sep 17 00:00:00 2001 From: joethei Date: Mon, 3 Jun 2019 18:12:16 +0200 Subject: [PATCH] + login, but only tested for nonexistent users as there is no register yet --- src/main/java/de/hsel/itech/db/PaymentDB.java | 37 ++++++------ src/main/java/de/hsel/itech/db/UserDB.java | 20 ++++++- .../java/de/hsel/itech/jsf/PaymentBean.java | 23 ++++++++ src/main/java/de/hsel/itech/jsf/UserBean.java | 53 ++++++++++++++++++ src/main/resources/icon.png | Bin 1431 -> 0 bytes src/main/webapp/login.xhtml | 36 ++++++++++++ 6 files changed, 152 insertions(+), 17 deletions(-) create mode 100644 src/main/java/de/hsel/itech/jsf/PaymentBean.java create mode 100644 src/main/java/de/hsel/itech/jsf/UserBean.java delete mode 100644 src/main/resources/icon.png create mode 100644 src/main/webapp/login.xhtml 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 bb1355d11d9c4b5671df0e3fc03156aba2c6b5f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1431 zcma)+`!~}K0LH&FbK913OQa!k4>=5Pl-$YY9g18w!kZXMZio1O$uTM_L~gHGt_d}f zOD%~=OL83zSHJet`#I-%KIi!do(xxE$j3 z20T31Y6U-pAX8bP=G`dC`ZNZxQ-z)9B% zcUqaPo0a!9TC<(>zRV+)WEP9MH^(vfSk(JYqop0oNaeZ>M(12dU&qE`0$lY^2nQbw zi`$HdtOEJ)P|z8?4&f$Gm%)p2E|E~C5(kB!i|zq5SXG?5Z)jJMaA6Zz%K*Q#oI!R0 z5}<5I62w@mX-?&VmXm0XW@$|3FM4p94x^D;_yp_)Rrr~HT0Kw+U3SMh*J-S&3!@%B zHP<7vyr;20w)L1dW*HuWJb^s|odsvI*o^T}`gf}SdVnEnHNoX1VgvAnUUP@MSy&Ip-FdFr#D2Lq=hH$z9ZS`>%QOY+&-9PEQT1*5 zTU)qVK5fAZZS8Ivx0oNbV#Z1Xs*v*6TO0f*4^M`2$_F&pZzdjy`B=HXRmt1ARhNMK zMRy{p4eb;%nt2oRio%O!>-gs@&|ITP1~+2zgTjjTL%*U28o$;;x}*JjWP zIpjM;td3B{!#2#OX+jfA+GowCzYLi-X1JxwmpaiBuR5y?cn)+>!aCvb3YBzET+xpX;(vBMVIxG z>;Nr}LCHtJqVX@H=CFDizHhm(yjZfy``6{7LR8`1T03%AhOs45F|XgX^F9Zl9qv{l z1uV%Sp9rtpUL%v zl#0wV7|tv_;a~RC3hm4AgFWMh(^Hg>G3t#iVgf-jDj~Uy1|I6N99hF6yt_(X&Ai2N z{$VTrip3%lMfu~AcDsKtKeMbvle5FXJ-7ccGQR*7%mpP$ z!=y5T5Yvh`L+XXb3sRTeSA(X=bT$+JINh@+8pXt=5P35D{-kE{1V>jXzZzkpw)?Dr Mqb<(n(J4~Oe-z85nE(I) 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 +
+
+
+ + +
+ +
+
+