added account

This commit is contained in:
Janis M
2022-03-28 14:46:15 +02:00
parent a0f059d955
commit 6fc6f1e9be
4 changed files with 78 additions and 7 deletions

View File

@@ -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
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
@@ -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;

29
static/css/account.css Normal file
View File

@@ -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);;
}

View File

@@ -67,6 +67,8 @@ body {
transition-timing-function: linear;
cursor: pointer;
color:white;
padding-left: 5px;
padding-right: 5px;
font-weight: bold;
}

22
views/account.ejs Normal file
View File

@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<%- include('partials/head'); %>
<link rel="stylesheet" href="/css/account.css">
</head>
<body>
<%- include('partials/header'); %>
<h1>Ihr Konto</h1>
<div id="account-info">
<h3>Persönliche Informationen</h3>
<p><b>Vorname:</b> <%= firstname %></p>
<p><b>Nachname:</b> <%= lastname %></p>
<p><b>Benutzername: </b><%= username %></p>
</div>
<div id="order-info">
<h3>Ihre Bestellungen</h3>
</div>
</body>
</html>