diff --git a/index.js b/index.js index 6e590b6..2b1c5d9 100644 --- a/index.js +++ b/index.js @@ -43,6 +43,7 @@ function authNoRedirectHandler(req, res, next){ req.username = user.username; req.firstname = user.firstname; req.lastname = user.lastname; + req.email = user.email; } next(); // Continue to next handler @@ -70,6 +71,7 @@ function authenticatedHandler(req, res, next){ req.username = user.username; req.firstname = user.firstname; req.lastname = user.lastname; + req.email = user.email; next(); // Continue to next handler }); } @@ -106,21 +108,27 @@ app.get("/", authNoRedirectHandler, (req, res) => { // Account app.get("/account", authenticatedHandler, (req, res) => { - let dict = { - title: "Account", - user: req.user, - isAdmin: req.isAdmin, - username: req.username, - firstname: req.firstname, - lastname: req.lastname - } - res.render('account', dict) - + mysql_handler.con.query(`SELECT orders.id, products.name, order_products.quantity, order_products.price + FROM orders LEFT JOIN order_products ON orders.id=order_products.orderId + LEFT JOIN products ON order_products.productId=products.id WHERE orders.userId = '${req.user}' ORDER BY orders.id DESC`, (err, result) => { + if(err) console.log(err); + let dict = { + title: "Account", + user: req.user, + isAdmin: req.isAdmin, + username: req.username, + firstname: req.firstname, + lastname: req.lastname, + email: req.email, + orders: JSON.parse(JSON.stringify(result)) + } + res.render('account', dict) + }) }); // Product Page -app.get("/product/:productId", (req, res) => { +app.get("/product/:productId", authNoRedirectHandler, (req, res) => { let productId = req.params.productId; mysql_handler.con.query(`SELECT s.name AS sellerName, p.name AS productName, p.description AS productDescription, p.id AS id, price,quantity, delivery_time, p.categoryId @@ -145,7 +153,8 @@ app.get("/product/:productId", (req, res) => { productDescription: "ez", loggedIn: true, reviews: reviews, - category: category, + category: category, + user: req.user, } res.render('product', dict) }); @@ -171,7 +180,7 @@ app.post("/review/create/:productId", authenticatedHandler,(req, res) => { }); // Search Page -app.get("/search", (req, res) => { +app.get("/search", authNoRedirectHandler,(req, res) => { var products = [ { title: "Panasonic LUMIX DC-GH5M2ME", @@ -201,7 +210,8 @@ app.get("/search", (req, res) => { let dict = { title: "Suche", - products: products + products: products, + user: req.user, } mysql_handler.con.query("SELECT * FROM products", function(err, result){ @@ -230,7 +240,8 @@ app.get("/order/:productId/:quantity/", authenticatedHandler, (req, res) => { title: "Bestellung", error: error, product: result, - quantity: req.params.quantity + quantity: req.params.quantity, + user: req.user, } res.render('order', dict); diff --git a/static/css/account.css b/static/css/account.css index f9f4387..567f3f4 100644 --- a/static/css/account.css +++ b/static/css/account.css @@ -2,7 +2,7 @@ display: block; margin-left: auto; margin-right: auto; - width: 500px; + width: 600px; margin-top: 60px; margin-bottom: 60px; border-bottom: 2px solid rgb(104, 117, 151);; @@ -22,8 +22,22 @@ h4{ display: block; margin-left: auto; margin-right: auto; - width: 500px; + width: 600px; margin-top: 60px; margin-bottom: 60px; border-bottom: 2px solid rgb(104, 117, 151);; } + +#order-info table{ + width: 100%; + border-collapse: collapse; + border-spacing: 0; + border: 1px solid rgb(104, 117, 151); + text-align: center; + border:0; +} + +#order-info table tr{ + height: 50px; + border-bottom: 1px solid grey; +} \ No newline at end of file diff --git a/views/account.ejs b/views/account.ejs index ff1d400..045bd7f 100644 --- a/views/account.ejs +++ b/views/account.ejs @@ -12,10 +12,34 @@

Vorname: <%= firstname %>

Nachname: <%= lastname %>

Benutzername: <%= username %>

+

E-Mail: <%= email.substring(0,email.length/3) %><% for(var i = 0; i < email.length - email.length/4; i++){ %>*<% } %> +

Ihre Bestellungen

+ + + + + + + + + + + + <% for(var i = 0; i < orders.length; i++){ %> + + + + + + + + <% } %> + +
BestellnummerProduktnameAnzahlStückpreisGesamtpreis
<%= orders[i].id %><%= orders[i].name %><%= orders[i].quantity %><%= orders[i].price %><%= orders[i].price * orders[i].quantity%> €
diff --git a/views/partials/header.ejs b/views/partials/header.ejs index ff22551..dab99a2 100644 --- a/views/partials/header.ejs +++ b/views/partials/header.ejs @@ -1,6 +1,6 @@
-