+ login, but only tested for nonexistent users as there is no register yet
This commit is contained in:
parent
5fe9880ffe
commit
c091084584
|
@ -45,11 +45,20 @@ public class PaymentDB {
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<Payment> get(@NotNull User user) {
|
public List<Payment> get(@NotNull User user) {
|
||||||
List<Payment> list = new ArrayList<>();
|
List<Payment> list = new ArrayList<>();
|
||||||
|
Map.Entry<ResultSet, Connection> entry = database.getResultSetByValue(database.tableUserPayment, "user", user.getId());
|
||||||
|
assert entry != null;
|
||||||
|
|
||||||
List<Long> ids = database.getIds(database.tableUserPayment);
|
try {
|
||||||
for(long id : ids) {
|
ResultSet rs = entry.getKey();
|
||||||
list.add(get(id));
|
while(rs.next()) {
|
||||||
|
list.add(get(rs.getLong("id")));
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.getValue().close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,20 +67,16 @@ public class PaymentDB {
|
||||||
Map.Entry<User, PaymentType> metadata = getMetadata(id);
|
Map.Entry<User, PaymentType> metadata = getMetadata(id);
|
||||||
assert metadata != null;
|
assert metadata != null;
|
||||||
|
|
||||||
String typeName = metadata.getValue().getName();
|
switch (metadata.getValue().getName()) {
|
||||||
if(typeName.equals("PayPal")) {
|
case "PayPal":
|
||||||
return getPayPal(id, metadata.getKey());
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,13 +33,31 @@ public class UserDB {
|
||||||
|
|
||||||
ResultSet rs = entry.getKey();
|
ResultSet rs = entry.getKey();
|
||||||
try {
|
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) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public User get(String name) {
|
||||||
|
Map.Entry<ResultSet, Connection> entry = database.getResultSetsByValue(database.tableUser, "name", name);
|
||||||
|
assert entry != null;
|
||||||
|
|
||||||
try {
|
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();
|
entry.getValue().close();
|
||||||
|
return user;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Payment> getMethods() {
|
||||||
|
return Database.getInstance().payment().get(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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 "";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Binary file not shown.
Before Width: | Height: | Size: 1.4 KiB |
|
@ -0,0 +1,36 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
|
xmlns:h="http://xmlns.jcp.org/jsf/html"
|
||||||
|
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
|
||||||
|
xmlns:f="http://xmlns.jcp.org/jsf/core">
|
||||||
|
<f:view>
|
||||||
|
<ui:composition template="template.xhtml">
|
||||||
|
|
||||||
|
<ui:define name="content">
|
||||||
|
|
||||||
|
<h:panelGroup layout="block" styleClass="row" rendered="#{not userBean.correctPassword}">
|
||||||
|
<aside class="m-col-s-3 m-push-l-4 m-note m-danger">
|
||||||
|
<h3>Passwort oder Benutzername falsch</h3>
|
||||||
|
</aside>
|
||||||
|
</h:panelGroup>
|
||||||
|
|
||||||
|
<div class="m-row">
|
||||||
|
<div class="m-col-l-6 m-push-l-4">
|
||||||
|
<h:form>
|
||||||
|
<h:inputText id="username" value="#{userBean.username}">Nutzername</h:inputText>
|
||||||
|
<br/>
|
||||||
|
<h:inputSecret id="password" value="#{userBean.password}">Passwort</h:inputSecret>
|
||||||
|
|
||||||
|
<h:commandButton action="#{userBean.login}">Login</h:commandButton>
|
||||||
|
</h:form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</ui:define>
|
||||||
|
|
||||||
|
</ui:composition>
|
||||||
|
</f:view>
|
||||||
|
</html>
|
Loading…
Reference in New Issue