mirror of
https://github.com/DerTyp7/shop-ejs-expressjs.git
synced 2025-10-29 20:42:10 +01:00
login fix
This commit is contained in:
41
index.js
41
index.js
@@ -36,17 +36,25 @@ function authNoRedirectHandler(req, res, next){
|
|||||||
} else if(data.user){ // If authcookie is valid
|
} else if(data.user){ // If authcookie is valid
|
||||||
req.user = data.user; // Set user to data.user
|
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 WHERE id = "${req.user}"`, (err, result) => { // Get user from database
|
||||||
|
|
||||||
if(err) console.log(err);
|
if(err) console.log(err);
|
||||||
let user = JSON.parse(JSON.stringify(result))[0]; // Parse user from database
|
let user = JSON.parse(JSON.stringify(result))[0]; // Parse user from database
|
||||||
if(user.id){
|
console.log("Moin3")
|
||||||
// Set user to req.user
|
try{
|
||||||
req.isAdmin = user.isAdmin;
|
if(user.id){
|
||||||
req.username = user.username;
|
console.log("Moin4")
|
||||||
req.firstname = user.firstname;
|
// Set user to req.user
|
||||||
req.lastname = user.lastname;
|
req.isAdmin = user.isAdmin;
|
||||||
req.email = user.email;
|
req.username = user.username;
|
||||||
|
req.firstname = user.firstname;
|
||||||
|
req.lastname = user.lastname;
|
||||||
|
req.email = user.email;
|
||||||
|
}
|
||||||
|
}catch{
|
||||||
|
res.redirect('/logout')
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
console.log("Moin5")
|
||||||
next(); // Continue to next handler
|
next(); // Continue to next handler
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -66,13 +74,16 @@ function authenticatedHandler(req, res, next){
|
|||||||
req.user = data.user; // Set user to data.user
|
req.user = data.user; // Set user to data.user
|
||||||
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
|
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);
|
if(err) console.log(err);
|
||||||
let user = JSON.parse(JSON.stringify(result))[0]; // Parse user from database
|
if(result.length > 0){
|
||||||
// Set user to req.user
|
let user = JSON.parse(JSON.stringify(result))[0]; // Parse user from database
|
||||||
req.isAdmin = user.isAdmin;
|
// Set user to req.user
|
||||||
req.username = user.username;
|
req.isAdmin = user.isAdmin;
|
||||||
req.firstname = user.firstname;
|
req.username = user.username;
|
||||||
req.lastname = user.lastname;
|
req.firstname = user.firstname;
|
||||||
req.email = user.email;
|
req.lastname = user.lastname;
|
||||||
|
req.email = user.email;
|
||||||
|
|
||||||
|
}
|
||||||
next(); // Continue to next handler
|
next(); // Continue to next handler
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
display: block;
|
display: block;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
width: 600px;
|
|
||||||
margin-top: 60px;
|
margin-top: 60px;
|
||||||
margin-bottom: 60px;
|
margin-bottom: 60px;
|
||||||
border-bottom: 2px solid rgb(104, 117, 151);;
|
border-bottom: 2px solid rgb(104, 117, 151);
|
||||||
|
padding-left: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#account-info p{
|
#account-info p{
|
||||||
@@ -22,7 +22,6 @@ h4{
|
|||||||
display: block;
|
display: block;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
width: 600px;
|
|
||||||
margin-top: 60px;
|
margin-top: 60px;
|
||||||
margin-bottom: 60px;
|
margin-bottom: 60px;
|
||||||
border-bottom: 2px solid rgb(104, 117, 151);;
|
border-bottom: 2px solid rgb(104, 117, 151);;
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ h1, h2{
|
|||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display:block;
|
display:block;
|
||||||
text-align: left;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.text-redirect{
|
.text-redirect{
|
||||||
|
|||||||
@@ -6,41 +6,47 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<%- include('partials/header'); %>
|
<%- include('partials/header'); %>
|
||||||
<h1>Ihr Konto</h1>
|
<div class="content">
|
||||||
<div id="account-info">
|
<h1 class="text-center">Ihr Konto</h1>
|
||||||
<h3>Persönliche Informationen</h3>
|
<div id="account-info">
|
||||||
<p><b>Vorname:</b> <%= firstname %></p>
|
<h3>Persönliche Informationen</h3><br>
|
||||||
<p><b>Nachname:</b> <%= lastname %></p>
|
<p><b>Vorname:</b> <%= firstname %></p>
|
||||||
<p><b>Benutzername: </b><%= username %></p>
|
<p><b>Nachname:</b> <%= lastname %></p>
|
||||||
<p><b>E-Mail: </b><%= email.substring(0,email.length/3) %><% for(var i = 0; i < email.length - email.length/4; i++){ %>*<% } %>
|
<p><b>Benutzername: </b><%= username %></p>
|
||||||
</p>
|
<p><b>E-Mail: </b><%= email.substring(0,email.length/3) %><% for(var i = 0; i < email.length - email.length/4; i++){ %>*<% } %>
|
||||||
</div>
|
<p><b>Adresse: </b></p>
|
||||||
|
</p>
|
||||||
<div id="order-info">
|
</div>
|
||||||
<h3>Ihre Bestellungen</h3>
|
|
||||||
<table>
|
<div id="order-info">
|
||||||
<thead>
|
<h3>Ihre Bestellungen</h3>
|
||||||
<tr>
|
<table>
|
||||||
<th>Bestellnummer</th>
|
<thead>
|
||||||
<th>Produktname</th>
|
|
||||||
<th>Anzahl</th>
|
|
||||||
<th>Stückpreis</th>
|
|
||||||
<th>Gesamtpreis</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<% for(var i = 0; i < orders.length; i++){ %>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= orders[i].id %></td>
|
<th>Bestellnummer</th>
|
||||||
<td><%= orders[i].name %></td>
|
<th>Produktname</th>
|
||||||
<td><%= orders[i].quantity %></td>
|
<th>Status</th>
|
||||||
<td><%= orders[i].price %></td>
|
<th>Anzahl</th>
|
||||||
<td><%= orders[i].price * orders[i].quantity%> €</td>
|
<th>Stückpreis</th>
|
||||||
|
<th>Gesamtpreis</th>
|
||||||
</tr>
|
</tr>
|
||||||
<% } %>
|
</thead>
|
||||||
</tbody>
|
<tbody>
|
||||||
</table>
|
<% for(var i = 0; i < orders.length; i++){ %>
|
||||||
|
<tr>
|
||||||
|
<td><%= orders[i].id %></td>
|
||||||
|
<td><%= orders[i].name %></td>
|
||||||
|
<td>In Progress</td>
|
||||||
|
<td><%= orders[i].quantity %></td>
|
||||||
|
<td><%= orders[i].price %></td>
|
||||||
|
<td><%= orders[i].price * orders[i].quantity%> €</td>
|
||||||
|
</tr>
|
||||||
|
<% } %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -6,8 +6,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<%- include('partials/header'); %>
|
<%- include('partials/header'); %>
|
||||||
<h1>Ihre Bestellung</h1>
|
<br>
|
||||||
<p id="error-text"><%- error %></p>
|
<h1 class="text-center">Ihre Bestellung</h1>
|
||||||
|
<p style="width:100%; display:block;"class="error-text text-center"><%- error %></p>
|
||||||
|
|
||||||
<div id="order-info">
|
<div id="order-info">
|
||||||
<p><b>Produktname:</b> <%= product.name %></p>
|
<p><b>Produktname:</b> <%= product.name %></p>
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
<link rel="stylesheet" href="/css/order.css">
|
<link rel="stylesheet" href="/css/order.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1 style="color:rgb(6, 170, 6)">Ihre Bestellung wurde in Auftrag gegeben!</h1>
|
<h1 style="color:rgb(6, 170, 6)" class="text-center">Ihre Bestellung wurde in Auftrag gegeben!</h1>
|
||||||
<h3>Trackingnummer: <label style="color:rgb(6, 156, 170)"><%= trackingnumber %></label></h3>
|
<h3 class="text-center">Trackingnummer: <label style="color:rgb(6, 156, 170)"><%= trackingnumber %></label></h3>
|
||||||
<a class="text-redirect" href="/">Zurück zur Startseite</a>
|
<a class="text-redirect text-center" href="/">Zurück zur Startseite</a>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -8,9 +8,9 @@
|
|||||||
<%- include('partials/header'); %>
|
<%- include('partials/header'); %>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="filtersDIV">
|
<div class="filtersDIV" style="display:none">
|
||||||
<br/>
|
<br/>
|
||||||
<h3 style="text-align: center;"> FILTER COMMING SOON </h3>
|
<h3 style="text-align: center; "> FILTER COMMING SOON </h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if (products.length == 0) { %>
|
<% if (products.length == 0) { %>
|
||||||
|
|||||||
Reference in New Issue
Block a user