diff --git a/index.js b/index.js index f4a4b84..6e590b6 100644 --- a/index.js +++ b/index.js @@ -37,11 +37,14 @@ function authNoRedirectHandler(req, res, next){ mysql_handler.con.query(`SELECT * FROM users WHERE id = "${req.user}"`, (err, result) => { // Get user from database if(err) console.log(err); let user = JSON.parse(JSON.stringify(result))[0]; // Parse user from database - // Set user to req.user - req.isAdmin = user.isAdmin; - req.username = user.username; - req.firstname = user.firstname; - req.lastname = user.lastname; + if(user.id){ + // Set user to req.user + req.isAdmin = user.isAdmin; + req.username = user.username; + req.firstname = user.firstname; + req.lastname = user.lastname; + } + next(); // Continue to next handler }); } @@ -59,7 +62,7 @@ function authenticatedHandler(req, res, next){ res.redirect("/login"); } else if(data.user){ // If authcookie is valid req.user = data.user; // Set user to data.user - mysql_handler.con.query(`SELECT * FROM users WHERE id = "${req.user}"`, (err, result) => { // Get user from database + mysql_handler.con.query(`SELECT * FROM users LEFT JOIN userinfos ON users.id=userinfos.userId WHERE users.id = "${req.user}"`, (err, result) => { // Get user from database if(err) console.log(err); let user = JSON.parse(JSON.stringify(result))[0]; // Parse user from database // Set user to req.user @@ -91,7 +94,7 @@ function notAuthenticatedHandler(req, res, next){ app.get("/", authNoRedirectHandler, (req, res) => { mysql_handler.con.query("SELECT * FROM products", function(err, result){ if(err) throw err; - + let dict = { title: "Startseite", user: req.user, @@ -101,6 +104,21 @@ 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) + +}); + + // Product Page app.get("/product/:productId", (req, res) => { let productId = req.params.productId; diff --git a/static/css/account.css b/static/css/account.css new file mode 100644 index 0000000..f9f4387 --- /dev/null +++ b/static/css/account.css @@ -0,0 +1,29 @@ +#account-info{ + display: block; + margin-left: auto; + margin-right: auto; + width: 500px; + margin-top: 60px; + margin-bottom: 60px; + border-bottom: 2px solid rgb(104, 117, 151);; +} + +#account-info p{ + height: 30px; +} + +h4{ + text-align: left; + margin-top: 10px; + margin-bottom: 5px; +} + +#order-info{ + display: block; + margin-left: auto; + margin-right: auto; + width: 500px; + margin-top: 60px; + margin-bottom: 60px; + border-bottom: 2px solid rgb(104, 117, 151);; +} diff --git a/static/css/header.css b/static/css/header.css index 8b1376f..8599dbb 100644 --- a/static/css/header.css +++ b/static/css/header.css @@ -67,6 +67,8 @@ body { transition-timing-function: linear; cursor: pointer; color:white; + padding-left: 5px; + padding-right: 5px; font-weight: bold; } diff --git a/views/account.ejs b/views/account.ejs new file mode 100644 index 0000000..ff1d400 --- /dev/null +++ b/views/account.ejs @@ -0,0 +1,22 @@ + + + + <%- include('partials/head'); %> + + + + <%- include('partials/header'); %> +

Ihr Konto

+
+

Persönliche Informationen

+

Vorname: <%= firstname %>

+

Nachname: <%= lastname %>

+

Benutzername: <%= username %>

+
+ +
+

Ihre Bestellungen

+
+ + + \ No newline at end of file