From 84db67dccd36025be5df1d5a779a2668b4b70146 Mon Sep 17 00:00:00 2001 From: Janis M Date: Wed, 30 Mar 2022 11:02:31 +0200 Subject: [PATCH] login fix --- index.js | 41 +++++++++++++++--------- static/css/account.css | 5 ++- static/css/style.css | 1 - views/account.ejs | 70 ++++++++++++++++++++++------------------- views/order.ejs | 5 +-- views/order_success.ejs | 6 ++-- views/search.ejs | 4 +-- 7 files changed, 74 insertions(+), 58 deletions(-) diff --git a/index.js b/index.js index a82d855..3e002f0 100644 --- a/index.js +++ b/index.js @@ -36,17 +36,25 @@ function authNoRedirectHandler(req, res, next){ } 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 + 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; - req.email = user.email; + console.log("Moin3") + try{ + if(user.id){ + console.log("Moin4") + // Set user to req.user + req.isAdmin = user.isAdmin; + 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 }); } @@ -66,13 +74,16 @@ function authenticatedHandler(req, res, next){ 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 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; - req.email = user.email; + if(result.length > 0){ + 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; + req.email = user.email; + + } next(); // Continue to next handler }); } diff --git a/static/css/account.css b/static/css/account.css index 567f3f4..09719ba 100644 --- a/static/css/account.css +++ b/static/css/account.css @@ -2,10 +2,10 @@ display: block; margin-left: auto; margin-right: auto; - width: 600px; margin-top: 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{ @@ -22,7 +22,6 @@ h4{ display: block; margin-left: auto; margin-right: auto; - width: 600px; margin-top: 60px; margin-bottom: 60px; border-bottom: 2px solid rgb(104, 117, 151);; diff --git a/static/css/style.css b/static/css/style.css index 70c6a7d..1a25b05 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -30,7 +30,6 @@ h1, h2{ margin-right: auto; width: 100%; display:block; - text-align: left; } .text-redirect{ diff --git a/views/account.ejs b/views/account.ejs index 045bd7f..040d9df 100644 --- a/views/account.ejs +++ b/views/account.ejs @@ -6,41 +6,47 @@ <%- include('partials/header'); %> -

Ihr Konto

-
-

Persönliche Informationen

-

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++){ %> +
+

Ihr Konto

+
+

Persönliche Informationen


+

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++){ %>*<% } %> +

Adresse:

+

+
+ +
+

Ihre Bestellungen

+
BestellnummerProduktnameAnzahlStückpreisGesamtpreis
+ - - - - - + + + + + + - <% } %> - -
<%= orders[i].id %><%= orders[i].name %><%= orders[i].quantity %><%= orders[i].price %><%= orders[i].price * orders[i].quantity%> €BestellnummerProduktnameStatusAnzahlStückpreisGesamtpreis
+ + + <% for(var i = 0; i < orders.length; i++){ %> + + <%= orders[i].id %> + <%= orders[i].name %> + In Progress + <%= orders[i].quantity %> + <%= orders[i].price %> + <%= orders[i].price * orders[i].quantity%> € + + <% } %> + + +
+ \ No newline at end of file diff --git a/views/order.ejs b/views/order.ejs index 27e34ad..1716f9c 100644 --- a/views/order.ejs +++ b/views/order.ejs @@ -6,8 +6,9 @@ <%- include('partials/header'); %> -

Ihre Bestellung

-

<%- error %>

+
+

Ihre Bestellung

+

<%- error %>

Produktname: <%= product.name %>

diff --git a/views/order_success.ejs b/views/order_success.ejs index c4328d9..a67f80a 100644 --- a/views/order_success.ejs +++ b/views/order_success.ejs @@ -5,8 +5,8 @@ -

Ihre Bestellung wurde in Auftrag gegeben!

-

Trackingnummer:

- Zurück zur Startseite +

Ihre Bestellung wurde in Auftrag gegeben!

+

Trackingnummer:

+ Zurück zur Startseite \ No newline at end of file diff --git a/views/search.ejs b/views/search.ejs index 0fd95c3..8a24a8e 100644 --- a/views/search.ejs +++ b/views/search.ejs @@ -8,9 +8,9 @@ <%- include('partials/header'); %> -
+ <% if (products.length == 0) { %>