From a8492b725775508754db0f73378b80686acb9106 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 10 Jun 2020 21:32:35 +0100 Subject: [PATCH] Update --- functions/views/css/style.css | 22 +++++++++++++++++++++- functions/views/js/fAuth.src.js | 1 + functions/views/js/fdb.src.js | 1 + functions/views/my-product.ejs | 6 +++--- functions/views/my-products.ejs | 4 ++++ package-lock.json | 9 +++++++++ package.json | 1 + server.js | 27 +++++++++++++++++++++++---- 8 files changed, 63 insertions(+), 8 deletions(-) diff --git a/functions/views/css/style.css b/functions/views/css/style.css index eb58f60..a3874eb 100644 --- a/functions/views/css/style.css +++ b/functions/views/css/style.css @@ -93,6 +93,7 @@ --admin-reject-btn: #F43030; --admin-reject-btn-hover: violet; --admin-reject-btn-active: black; + --heading: #7C7C7C; } body { @@ -492,11 +493,30 @@ input:focus, textarea:focus, select:focus{ .products p { font-family: osl; font-size: 25px; - color: #7C7C7C; + color: var(--heading); margin-bottom: 10px; margin-top: 10px; } +.profile a { + font-family: osl; + font-size: 25px; + color: var(--product-page-info-btn); + margin-bottom: 20px; + margin-top: 20px; + cursor: pointer; + transition: 0.3s; +} + +.profile a:hover { + color: var(--violet); +} + +.profile a:active { + color: var(--white); + transition: 0.1s; +} + .product-list-container { display: flex; justify-content: space-between; diff --git a/functions/views/js/fAuth.src.js b/functions/views/js/fAuth.src.js index 6388740..0ea915d 100644 --- a/functions/views/js/fAuth.src.js +++ b/functions/views/js/fAuth.src.js @@ -1,3 +1,4 @@ +// @ts-nocheck function checkAuth(){ firebase.auth().onAuthStateChanged(function(user){ if (user) { diff --git a/functions/views/js/fdb.src.js b/functions/views/js/fdb.src.js index db6971b..700cfc2 100644 --- a/functions/views/js/fdb.src.js +++ b/functions/views/js/fdb.src.js @@ -1,4 +1,5 @@ // https://javascript-minifier.com +// @ts-nocheck function checkFields() { if (document.getElementById('pName').value && document.getElementById('pDesc').value && document.getElementById('pLoc').value && document.getElementById('pPrice').value diff --git a/functions/views/my-product.ejs b/functions/views/my-product.ejs index 4e66b9b..bb0a0ca 100644 --- a/functions/views/my-product.ejs +++ b/functions/views/my-product.ejs @@ -14,15 +14,15 @@

Price: £<%= item.price %>

<% var editbtnStyle = ""%> - <% if (item.status == "sold") {editbtnStyle = "visibility:hidden;"} else {editbtnStyle = "visibility:all;"}%> + <% if (item.status == "on-sale" || item.status == "off-sale") {editbtnStyle = "visibility:all;"} else {editbtnStyle = "visibility:hidden;"}%>
>
<% var sellbtnText = "Place On Sale"%> <% var salebtnStyle = "visibility:hidden"%> - <% if (item.status != "sold") {salebtnStyle = "visibility:all;"}%> + <% if (item.status == "on-sale" || item.status == "off-sale") {salebtnStyle = "visibility:all;"}%> <% if (item.status == "on-sale") {sellbtnText = "Take Off Sale"}%>
<% var shipbtnStyle = ""%> - <% if (item.status == "sold") {shipbtnStyle = "visibility:hidden;"} else {shipbtnStyle = "visibility:all;"}%> + <% if (item.status != "on-sale") {shipbtnStyle = "visibility:hidden;"} else {shipbtnStyle = "visibility:all;"}%>
>
diff --git a/functions/views/my-products.ejs b/functions/views/my-products.ejs index db79582..15b5e45 100644 --- a/functions/views/my-products.ejs +++ b/functions/views/my-products.ejs @@ -8,6 +8,10 @@
+
+ My Profile +
+

My products:

diff --git a/package-lock.json b/package-lock.json index cba405c..2486456 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1426,6 +1426,15 @@ "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz", "integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg==" }, + "cookie-parser": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.5.tgz", + "integrity": "sha512-f13bPUj/gG/5mDr+xLmSxxDsB9DQiTIfhJS/sqjrmfAWiAN+x2O4i/XguTL9yDZ+/IFDanJ+5x7hC4CXT9Tdzw==", + "requires": { + "cookie": "0.4.0", + "cookie-signature": "1.0.6" + } + }, "cookie-signature": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", diff --git a/package.json b/package.json index 37dbc78..a98d71b 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "license": "ISC", "dependencies": { "body-parser": "^1.19.0", + "cookie-parser": "^1.4.5", "ejs": "^3.1.2", "express": "^4.17.1", "firebase": "^7.14.3", diff --git a/server.js b/server.js index 1c826c3..dc92985 100644 --- a/server.js +++ b/server.js @@ -16,6 +16,10 @@ app.use(bodyParser.json()) app.use(logger('dev')) app.use(express.static('views')) +const cookieParser = require('cookie-parser')(); +app.use(cookieParser); + + app.set('view engine', 'ejs') app.set('views', __dirname + '/views') @@ -29,6 +33,15 @@ let transporter = nodemailer.createTransport({ }) +const validateFirebaseIdToken = (req, res, next) => { + console.log("Running pre-function") + console.log(req.cookies); //// <----- issue this is empty {} why?? + console.log("Finished pre function") + next(); +}; + +app.use(validateFirebaseIdToken) + app.get("/", function(request, responce) { homePage(request, responce) }) @@ -115,10 +128,16 @@ app.get('/my-products', function(request, responce){ }) } else { - dbRef.orderByChild('owner').equalTo(uid).once('value', function(snapshot){ - var data = {'x': {holder: '',id: 999,img: '',location: '',name: 'No products listed 😢',owner: '',price: '',stock: ''}} - if (snapshot.val()) {data = snapshot.val()} - responce.render('my-products.ejs', {products: data}) + let usersRef = database.ref("/users") + usersRef.orderByChild("UID").equalTo(uid).once('value', function(snapshot){ + vals = snapshot.val() + var keys = Object.keys(vals) + sellerDBID = keys[0] + dbRef.orderByChild('owner').equalTo(uid).once('value', function(snapshot){ + var data = {'x': {holder: '',id: 999,img: '',location: '',name: 'No products listed 😢',owner: '',price: '',stock: ''}} + if (snapshot.val()) {data = snapshot.val()} + responce.render('my-products.ejs', {products: data, dbid:sellerDBID}) + }) }) } })