Update
This commit is contained in:
parent
6fd448e28f
commit
4785c6e8b8
@ -2,6 +2,7 @@ const functions = require('firebase-functions');
|
||||
|
||||
var express = require('express')
|
||||
var logger = require('morgan')
|
||||
var bodyParser = require('body-parser')
|
||||
var admin = require("firebase-admin");
|
||||
var serviceAccount = require("./project-gg-3b754-firebase-adminsdk-4848h-5a5778b77b.json");
|
||||
|
||||
@ -13,6 +14,9 @@ var database = firebaseadmin.database()
|
||||
|
||||
var app = express()
|
||||
|
||||
app.use(bodyParser.json())
|
||||
app.use(bodyParser.urlencoded({extended: true}))
|
||||
|
||||
app.use(logger('dev'))
|
||||
app.use(express.static('views'))
|
||||
|
||||
@ -22,21 +26,14 @@ app.set('views', __dirname + '/views')
|
||||
|
||||
|
||||
app.get("/", function(request, responce) {
|
||||
var dbRef = database.ref("/products")
|
||||
dbRef.limitToLast(5).once('value', function(snapshot){
|
||||
var data = {}
|
||||
data = snapshot.val()
|
||||
var x = "none"
|
||||
if (request.query.itemAdded == "true") {
|
||||
x = 'block'
|
||||
}
|
||||
responce.render('home.ejs', {products: data, message: x})
|
||||
})
|
||||
|
||||
// responce.render("home.ejs")
|
||||
homePage(request, responce)
|
||||
})
|
||||
|
||||
app.get("/home", function(request, responce) {
|
||||
homePage(request, responce)
|
||||
})
|
||||
|
||||
function homePage(request, responce) {
|
||||
var dbRef = database.ref("/products")
|
||||
dbRef.limitToLast(5).once('value', function(snapshot){
|
||||
var data = {}
|
||||
@ -47,14 +44,48 @@ app.get("/home", function(request, responce) {
|
||||
}
|
||||
responce.render('home.ejs', {products: data, message: x})
|
||||
})
|
||||
|
||||
// responce.render("home.ejs")
|
||||
})
|
||||
}
|
||||
|
||||
app.get('/additmpage', function(request, responce){
|
||||
responce.render('add-item.ejs')
|
||||
})
|
||||
|
||||
app.get('/my-products', function(request, responce){
|
||||
if (request.query.uToken) {
|
||||
admin.auth().verifyIdToken(request.query.uToken)
|
||||
.then(function(decodedToken) {
|
||||
let uid = decodedToken.uid;
|
||||
var dbRef = database.ref("/products")
|
||||
dbRef.orderByChild('owner').equalTo(uid).once('value', function(snapshot){
|
||||
var data = {
|
||||
'x': {
|
||||
desc: '',
|
||||
holder: '',
|
||||
id: 999,
|
||||
img: '',
|
||||
location: '',
|
||||
name: 'No products listed 😢',
|
||||
owner: '',
|
||||
price: '',
|
||||
public: '',
|
||||
stock: ''
|
||||
},
|
||||
}
|
||||
if (snapshot.val()) {data = snapshot.val()}
|
||||
console.log(data)
|
||||
responce.render('my-products.ejs', {products: data})
|
||||
})
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.log(error)
|
||||
responce.send("<h1>Bad Auth Token</h1><a href='home'>Home</a>")
|
||||
});
|
||||
}
|
||||
else {
|
||||
responce.send("<h1>No Auth Token Provided</h1><a href='home'>Home</a>")
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/product', function(request, responce){
|
||||
if (request.query.productid) {
|
||||
var dbRef = database.ref("/products/"+request.query.productid)
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
<div class="navbar">
|
||||
<div class="logon-crumbs">
|
||||
<div id="uname-field" style="display: none;">
|
||||
<a id="uname-dom" class="user-name" href="/">Unregistered user</a>
|
||||
<a id="uname-dom" class="user-name" href="javascript:;" onclick="my_products();">Unregistered user</a>
|
||||
<div class="user-logout">
|
||||
<a onclick={signout()}>Log out</a>
|
||||
</div>
|
||||
@ -62,9 +62,9 @@
|
||||
|
||||
<div class="e-404">
|
||||
<h1>It's a 404!</h1>
|
||||
<a href='home'>Home</a>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="space"></div>
|
||||
</div>
|
||||
|
||||
@ -89,6 +89,6 @@
|
||||
</div>
|
||||
</footer>
|
||||
<script src="js/fAuth.js"></script>
|
||||
<script src="js/fStore.js"></script>
|
||||
<script src="js/fdb.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -25,7 +25,7 @@
|
||||
<div class="navbar">
|
||||
<div class="logon-crumbs">
|
||||
<div id="uname-field" style="display: none;">
|
||||
<a id="uname-dom" class="user-name" href="my-products">Unregistered user</a>
|
||||
<a id="uname-dom" class="user-name" href="javascript:;" onclick="my_products();">Unregistered user</a>
|
||||
<div class="user-logout">
|
||||
<a onclick={signout()}>Log out</a>
|
||||
</div>
|
||||
|
||||
@ -501,9 +501,13 @@ footer a {
|
||||
}
|
||||
.my-product-container {
|
||||
padding-top: 15px;
|
||||
width: 300px;
|
||||
width: 100%;
|
||||
display: inline-flex;
|
||||
}
|
||||
.my-product-container a {
|
||||
width: 20%;
|
||||
max-height: 20%;
|
||||
}
|
||||
.my-product-container img {
|
||||
width: 100%;
|
||||
max-height: 100%;
|
||||
@ -518,6 +522,7 @@ footer a {
|
||||
font-family: nunito;
|
||||
color: #CA5555;
|
||||
font-size: 25px;
|
||||
width: 100%;
|
||||
}
|
||||
.top {
|
||||
padding-top: 5px;
|
||||
|
||||
@ -69,6 +69,7 @@ function signinwithemail(){
|
||||
|
||||
function signout(){
|
||||
firebase.auth().signOut()
|
||||
window.location.replace(window.location.href.split("?")[0])
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -89,7 +89,7 @@ function updateImgs() {
|
||||
// console.log(images)
|
||||
Array.from(images).forEach((image) => {
|
||||
var pathReference = rootReference.child(image.title)
|
||||
pathReference.getDownloadURL().then(function(url) {image.src = url})
|
||||
pathReference.getDownloadURL().then(function(url) {image.src = url}).catch(e => {console.log(e.message)})
|
||||
})
|
||||
}
|
||||
|
||||
@ -109,12 +109,7 @@ function purchaseItem() {
|
||||
|
||||
function my_products() {
|
||||
firebase.auth().currentUser.getIdToken().then(function(idToken) {
|
||||
let data = JSON.stringify({uToken: idToken})
|
||||
|
||||
fetch("my-products", {
|
||||
method: "POST",
|
||||
headers: {"Content-type": "application/json"},
|
||||
body: data
|
||||
})
|
||||
window.location.replace("my-products?uToken=" + idToken)
|
||||
})
|
||||
.catch(e => {console.log(e)})
|
||||
}
|
||||
@ -24,7 +24,7 @@
|
||||
<div class="navbar">
|
||||
<div class="logon-crumbs">
|
||||
<div id="uname-field" style="display: none;">
|
||||
<a id="uname-dom" class="user-name" href="my-products">Unregistered user</a>
|
||||
<a id="uname-dom" class="user-name" href="home">Unregistered user</a>
|
||||
<div class="user-logout">
|
||||
<a onclick={signout()}>Log out</a>
|
||||
</div>
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
<div class="navbar">
|
||||
<div class="logon-crumbs">
|
||||
<div id="uname-field" style="display: none;">
|
||||
<a id="uname-dom" class="user-name" href="my-products">Unregistered user</a>
|
||||
<a id="uname-dom" class="user-name" href="javascript:;" onclick="my_products();">Unregistered user</a>
|
||||
<div class="user-logout">
|
||||
<a onclick={signout()}>Log out</a>
|
||||
</div>
|
||||
|
||||
31
server.js
31
server.js
@ -56,27 +56,42 @@ app.get('/additmpage', function(request, responce){
|
||||
responce.render('add-item.ejs')
|
||||
})
|
||||
|
||||
app.post('/my-products', function(request, responce){
|
||||
admin.auth().verifyIdToken(request.body.uToken)
|
||||
app.get('/my-products', function(request, responce){
|
||||
if (request.query.uToken) {
|
||||
admin.auth().verifyIdToken(request.query.uToken)
|
||||
.then(function(decodedToken) {
|
||||
let uid = decodedToken.uid;
|
||||
var dbRef = database.ref("/products")
|
||||
dbRef.orderByChild('owner').equalTo(uid).once('value', function(snapshot){
|
||||
var data = {}
|
||||
data = snapshot.val()
|
||||
var data = {
|
||||
'x': {
|
||||
desc: '',
|
||||
holder: '',
|
||||
id: 999,
|
||||
img: '',
|
||||
location: '',
|
||||
name: 'No products listed 😢',
|
||||
owner: '',
|
||||
price: '',
|
||||
public: '',
|
||||
stock: ''
|
||||
},
|
||||
}
|
||||
if (snapshot.val()) {data = snapshot.val()}
|
||||
console.log(data)
|
||||
responce.render('my-products.ejs', {products: data})
|
||||
})
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.log(error)
|
||||
responce.send("<h1>Bad Auth Token</h1><a href='home'>Home</a>")
|
||||
});
|
||||
}
|
||||
else {
|
||||
responce.send("<h1>No Auth Token Provided</h1><a href='home'>Home</a>")
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
app.get('/product', function(request, responce){
|
||||
if (request.query.productid) {
|
||||
var dbRef = database.ref("/products/"+request.query.productid)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user