mirror of
https://github.com/DerTyp7/shop-ejs-expressjs.git
synced 2025-10-29 12:32:11 +01:00
added account
This commit is contained in:
32
index.js
32
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;
|
||||
|
||||
29
static/css/account.css
Normal file
29
static/css/account.css
Normal 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);;
|
||||
}
|
||||
@@ -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
22
views/account.ejs
Normal 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>
|
||||
Reference in New Issue
Block a user