Update
This commit is contained in:
parent
9df97896c7
commit
6479d82933
@ -13,10 +13,8 @@ let firebaseadmin = admin.initializeApp({
|
||||
let database = firebaseadmin.database()
|
||||
|
||||
let app = express()
|
||||
|
||||
app.use(bodyParser.urlencoded({extended: true}))
|
||||
app.use(bodyParser.json({ limit: '10mb' }));
|
||||
|
||||
app.use(logger('dev'))
|
||||
app.use(express.static('views'))
|
||||
|
||||
@ -30,7 +28,7 @@ let transporter = nodemailer.createTransport({
|
||||
user: 'noreply.projectgg@gmail.com',
|
||||
pass: 'kynpef-5paqha-xaVxip'
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
app.get("/", function(request, responce) {
|
||||
@ -113,17 +111,11 @@ app.get('/my-products', function(request, responce){
|
||||
}
|
||||
else {
|
||||
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: ''
|
||||
},
|
||||
}
|
||||
var data = {'x': {desc: '', holder: '', id: 999, img: '', location: '', name: 'No products listed 😢', owner: '', price: '', public: '', stock: ''}}
|
||||
if (snapshot.val()) {data = snapshot.val()}
|
||||
responce.render('my-products.ejs', {products: data})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.log(error)
|
||||
@ -228,109 +220,112 @@ app.get('/product', function(request, responce){
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/purchase-api', function(request, responce){
|
||||
if (request.body.item && request.body.user) {
|
||||
admin.auth().verifyIdToken(request.body.user)
|
||||
.then(function(decodedToken) {
|
||||
let uid = decodedToken.uid;
|
||||
let product = request.body.item
|
||||
var productRef = database.ref("/products/"+product)
|
||||
productRef.once('value', function(snapshot) {
|
||||
var exists = (snapshot.val() !== null)
|
||||
if (exists){
|
||||
var productRef = database.ref("/products/"+product)
|
||||
productRef.update({owner:uid, status:"sold"})
|
||||
.then(function(){
|
||||
responce.send({success:true, error:null})
|
||||
})
|
||||
.catch(e => {console.log(e)})
|
||||
}
|
||||
else {
|
||||
responce.send({success:false, error:'Item does not exist'})
|
||||
}
|
||||
})
|
||||
.catch(e => {console.log(e)})
|
||||
})
|
||||
.catch(function(err) {
|
||||
responce.send({success:false, error:'invalid auth token'})
|
||||
});
|
||||
}
|
||||
else {
|
||||
responce.send({success:false, error:'invalid data'})
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/place-on-sale-api', function(request, responce){
|
||||
if (request.body.item && request.body.user) {
|
||||
admin.auth().verifyIdToken(request.body.user)
|
||||
.then(function(decodedToken) {
|
||||
let uid = decodedToken.uid;
|
||||
let productID = request.body.item
|
||||
var productRef = database.ref("/products/"+productID)
|
||||
|
||||
productRef.once('value',function(snapshot){
|
||||
let item = snapshot.val()
|
||||
if (item){
|
||||
let itemOwner = item.owner
|
||||
if (uid == itemOwner){
|
||||
productRef.update({status:"on-sale"})
|
||||
.then(function(){
|
||||
responce.send({success:true, error:null})
|
||||
})
|
||||
.catch(e => {console.log(e)})
|
||||
}
|
||||
else {
|
||||
responce.send({success:false, error:'You do not own this item'})
|
||||
}
|
||||
}
|
||||
else {
|
||||
responce.send({success:false, error:'Item does not exist'})
|
||||
}
|
||||
})
|
||||
.catch(e=>{
|
||||
console.log(e)
|
||||
responce.send({success:false, error:'other, ' + e})
|
||||
})
|
||||
})
|
||||
.catch(function(error) {
|
||||
responce.send({success:false, error:'invalid auth token'})
|
||||
})
|
||||
}
|
||||
else {
|
||||
responce.send({success:false, error:'invalid data'})
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/ship-api', function(request, responce){
|
||||
if (request.body.item && request.body.user) {
|
||||
admin.auth().verifyIdToken(request.body.user)
|
||||
.then(async function(decodedToken) {
|
||||
let uid = decodedToken.uid;
|
||||
let pid = request.body.item
|
||||
|
||||
if (await verifyExists(pid)){
|
||||
if (await verifyOwner(uid, pid)) {
|
||||
app.post('/request-api', async function(request, responce){
|
||||
if (request.body.prodID && request.body.authToken && request.body.usrMsg) {
|
||||
let bMsg = request.body.usrMsg
|
||||
let uid = await authCheck(request.body.authToken)
|
||||
if (uid) {
|
||||
let pid = request.body.prodID
|
||||
let productRef = database.ref("/products/"+ pid)
|
||||
productRef.update({status:"shipped"})
|
||||
.then(function(){
|
||||
processItemShipEmail(pid, uid)
|
||||
var snapshot = await productRef.once('value')
|
||||
if (snapshot.exists()) {
|
||||
let product = snapshot.val()
|
||||
let productName = product.name
|
||||
let productSeller = product.owner
|
||||
let usersRef = database.ref("/users")
|
||||
snapshot = await usersRef.orderByChild("UID").equalTo(productSeller).once('value')
|
||||
if (snapshot.exists()) {
|
||||
let vals = snapshot.val()
|
||||
let keys = Object.keys(vals)
|
||||
let seller = vals[keys[0]]
|
||||
let sellerName = seller.fName
|
||||
let sellerEmail = seller.email
|
||||
snapshot = await usersRef.orderByChild("UID").equalTo(uid).once('value')
|
||||
if (snapshot.exists()) {
|
||||
let vals = snapshot.val()
|
||||
let keys = Object.keys(vals)
|
||||
let buyer = vals[keys[0]]
|
||||
let buyerName = buyer.fName + ' ' + buyer.lName
|
||||
let buyerEmail = buyer.email
|
||||
let content = contentMaker(sellerName, buyerName, buyerEmail, productName, pid, bMsg)
|
||||
let rsp = sendEmail(sellerEmail, content)
|
||||
console.log(rsp)
|
||||
responce.send({success:true, error:null})
|
||||
})
|
||||
.catch(e => {console.log(e)})
|
||||
} else {
|
||||
responce.send({success:false, error:'Something very bad has happened..... Item buyer apparantly doesn\'t exist in the database'})
|
||||
}
|
||||
else {
|
||||
responce.send({success:false, error:'You do not own this item'})
|
||||
} else {
|
||||
responce.send({success:false, error:'Something very bad has happened..... Item owner apparantly doesn\'t exist in the database'})
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
responce.send({success:false, error:'Item does not exist'})
|
||||
}
|
||||
})
|
||||
.catch(function(error) {
|
||||
} else {
|
||||
responce.send({success:false, error:'invalid auth token'})
|
||||
})
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
responce.send({success:false, error:'invalid data'})
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/toggle-sale-api', async function(request, responce){
|
||||
if (request.body.prodID && request.body.authToken && (request.body.targetState != null)) {
|
||||
let uid = await authCheck(request.body.authToken)
|
||||
if (uid) {
|
||||
let pid = request.body.prodID
|
||||
let targetState = request.body.targetState
|
||||
let productRef = database.ref("/products/"+ pid)
|
||||
var snapshot = await productRef.once('value')
|
||||
if (snapshot.exists()) {
|
||||
let product = snapshot.val()
|
||||
if (product.owner == uid && product.status != "sold") {
|
||||
let status = "x"
|
||||
if (targetState == true) {
|
||||
status = "on-sale"
|
||||
} else {
|
||||
status = "off-sale"
|
||||
}
|
||||
productRef.update({status:status})
|
||||
.then(responce.send({success:true, error:null}))
|
||||
.catch(e => {responce.send({success:false, error:e})})
|
||||
} else {
|
||||
responce.send({success:false, error:'Unauthorized'})
|
||||
}
|
||||
} else {
|
||||
responce.send({success:false, error:'Item does not exist'})
|
||||
}
|
||||
} else {
|
||||
responce.send({success:false, error:'invalid auth token'})
|
||||
}
|
||||
} else {
|
||||
responce.send({success:false, error:'invalid data'})
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/sold-api', async function(request, responce){
|
||||
if (request.body.prodID && request.body.authToken) {
|
||||
let uid = await authCheck(request.body.authToken)
|
||||
if (uid) {
|
||||
let pid = request.body.prodID
|
||||
let productRef = database.ref("/products/"+ pid)
|
||||
var snapshot = await productRef.once('value')
|
||||
if (snapshot.exists()) {
|
||||
let product = snapshot.val()
|
||||
if (product.owner == uid) {
|
||||
productRef.update({status:"sold"})
|
||||
.then(responce.send({success:true, error:null}))
|
||||
.catch(e => {responce.send({success:false, error:e})})
|
||||
} else {
|
||||
responce.send({success:false, error:'Unauthorized'})
|
||||
}
|
||||
} else {
|
||||
responce.send({success:false, error:'Item does not exist'})
|
||||
}
|
||||
} else {
|
||||
responce.send({success:false, error:'invalid auth token'})
|
||||
}
|
||||
} else {
|
||||
responce.send({success:false, error:'invalid data'})
|
||||
}
|
||||
})
|
||||
@ -356,7 +351,7 @@ app.post('/login-user-api', function(request, responce){
|
||||
});
|
||||
}
|
||||
else {
|
||||
responce.send({error: 'invalid data'})
|
||||
responce.send({success:false, error: 'invalid data'})
|
||||
}
|
||||
})
|
||||
|
||||
@ -468,6 +463,17 @@ app.post('/update-product-api', function(request, responce){
|
||||
}
|
||||
})
|
||||
|
||||
function contentMaker(sName, bName, bEmail, pName, pid, bMsg){
|
||||
let text = "Hi " + sName + "\n \n" + bName + " is interested in your product " + pName + " (ID: " + pid + ")\n\nUser email: " + bEmail +"\n\nUser message:\n" + bMsg
|
||||
return text
|
||||
}
|
||||
|
||||
async function authCheck(token) {
|
||||
let uid = false
|
||||
decodedToken = await admin.auth().verifyIdToken(token).catch(e=>{console.log(e)})
|
||||
uid = decodedToken.uid
|
||||
return uid
|
||||
}
|
||||
|
||||
async function checkNewUser(user){
|
||||
let snapshot = await checkUserExists(user.uid)
|
||||
@ -531,49 +537,27 @@ async function verifyOwner(uid, pid) {
|
||||
}
|
||||
}
|
||||
|
||||
function processItemShipEmail(itemID, buyerID){
|
||||
let productRef = database.ref("/products/"+itemID)
|
||||
productRef.once('value',function(snapshot){
|
||||
let item = snapshot.val()
|
||||
let itemName = item.name
|
||||
let itemHolder = item.holder
|
||||
let usersRef = database.ref("/users")
|
||||
usersRef.orderByChild("UID").equalTo(itemHolder).once('value', function(snapshot){
|
||||
vals = snapshot.val()
|
||||
var keys = Object.keys(vals)
|
||||
uData = vals[keys[0]]
|
||||
let holderEmail = uData.email
|
||||
let clientRef = database.ref("/users")
|
||||
usersRef.orderByChild("UID").equalTo(buyerID).once('value', function(snapshot){
|
||||
cvals = snapshot.val()
|
||||
var ckeys = Object.keys(cvals)
|
||||
cData = cvals[ckeys[0]]
|
||||
let clientAddress = cData.address
|
||||
let emailContent = "Please ship Item: " + itemName + " (ItemID: " + itemID + ")\nShipping address: " + clientAddress
|
||||
sendEmail(holderEmail, emailContent)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function sendEmail(address, content){
|
||||
var mailOptions = {
|
||||
from: 'noreply.projectgg@gmail.com',
|
||||
from: 'Project GG',
|
||||
to: address,
|
||||
subject: 'Your Item has been requested',
|
||||
subject: 'Someone\'s interested!',
|
||||
text: content
|
||||
}
|
||||
transporter.sendMail(mailOptions, function(error, info){
|
||||
if (error) {
|
||||
console.log(error);
|
||||
} else {
|
||||
console.log('Email sent: ' + info.response);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
app.get('*', function(request, responce){
|
||||
responce.render('404.ejs')
|
||||
responce.status(404).render('404.ejs')
|
||||
})
|
||||
|
||||
app.post('*', function(request, responce){
|
||||
responce.status(404).send({success:false, error:"404"})
|
||||
})
|
||||
|
||||
exports.application = functions.https.onRequest(app)
|
||||
File diff suppressed because one or more lines are too long
@ -511,6 +511,19 @@ footer a {
|
||||
font-size: 20px;
|
||||
padding-top: 38px;
|
||||
}
|
||||
|
||||
.product-page-info input {
|
||||
margin-top: 20px;
|
||||
height: 40px;
|
||||
width: 500px;
|
||||
font-size: 15px;
|
||||
padding-left: 10px;
|
||||
margin-bottom: -10px;
|
||||
font-family: osl;
|
||||
border-radius: 0;
|
||||
border: 0.5px solid grey;
|
||||
}
|
||||
|
||||
.product-page-description {
|
||||
margin-top: 10px;
|
||||
}
|
||||
@ -570,13 +583,21 @@ footer a {
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: #df0000;
|
||||
text-align: center;
|
||||
font-size: 25px;
|
||||
font-family: osl;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.product-mgmt-buttons {
|
||||
display: inline-flex;
|
||||
}
|
||||
.product-mgmt-buttons button {
|
||||
margin-top: 38px;
|
||||
height: 40px;
|
||||
width: 100px;
|
||||
width: 150px;
|
||||
display: block;
|
||||
font-size: 19px;
|
||||
font-family: osl;
|
||||
|
||||
@ -1,65 +1,8 @@
|
||||
<!doctype html>
|
||||
<%- include("partials/header") %>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>GG Prototype</title>
|
||||
<meta name="description" content="GG Prototype Web">
|
||||
<meta name="author" content="Max">
|
||||
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-app.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-analytics.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-auth.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-storage.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-database.js"></script>
|
||||
<script src="js/fInit.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<div class="page">
|
||||
<div class="navbar">
|
||||
<div class="logon-crumbs">
|
||||
<div id="uname-field" style="display: none;">
|
||||
<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>
|
||||
</div>
|
||||
<div id="login-field" style="display: block;">
|
||||
<input id="fuid" type="text" placeholder="Username">
|
||||
<input id="fpwd" type="password" placeholder="Password">
|
||||
<button id="blogin" onclick={signinwithemail()} class="btn-login">➤</button>
|
||||
<button id="blogin_g" onclick={signinwithgoogle()} class="btn-g-login"><img src="media/g_logon.png" class="img-g-login" alt="img"></button>
|
||||
<button id="blogin_g" onclick={signinwithfb()} class="btn-fb-login"><img src="media/fb_logon.png" class="img-g-login" alt="img"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="user-info">
|
||||
<div class="notifications">
|
||||
🔔 | <%= 0%>
|
||||
</div>
|
||||
<div class="cart">
|
||||
🛒 | <%= 0%>
|
||||
</div>
|
||||
<div class="add-item">
|
||||
<a href="additmpage">⊕</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="user-message" style="display: <%= message %>;">
|
||||
<p>Product added successfully</p>
|
||||
</div>
|
||||
<div class="sbar">
|
||||
<img src="media/gg_logo.png" alt="img">
|
||||
<input id="sfield" type="text" placeholder="I Want...">
|
||||
<button id="sbutton" onclick={bSearch()}>Go!</button>
|
||||
<a href="#">Extras</a>
|
||||
</div>
|
||||
|
||||
<div class="space"></div>
|
||||
|
||||
<div class="welcome">
|
||||
<img src="media/welcome.png">
|
||||
@ -150,26 +93,4 @@
|
||||
</div>
|
||||
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<div class="links">
|
||||
<a href="#">Help</a>
|
||||
<a href="#">Contact</a>
|
||||
<a href="#">Legal</a>
|
||||
</div>
|
||||
<div class="legal">
|
||||
<a>© GG Sales 2019-2020. All Rights Reserved. </a>
|
||||
<a class="link" href="#">User Agreement</a>
|
||||
<a> ,</a>
|
||||
<a class="link" href="#">Privacy</a>
|
||||
<a> ,</a>
|
||||
<a class="link" href="#">Cookies</a>
|
||||
</div>
|
||||
<div class="location">
|
||||
GG Sales US 🇺🇸
|
||||
</div>
|
||||
</footer>
|
||||
<script src="js/fAuth.js"></script>
|
||||
<script src="js/fdb.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
<%- include("partials/footer") %>
|
||||
@ -88,8 +88,6 @@ function productUpdateEventHandler() {
|
||||
const item_id_element = document.getElementById("productID")
|
||||
const item_id = item_id_element.getAttribute("product_id")
|
||||
|
||||
const sessUid = firebase.auth().currentUser.uid
|
||||
|
||||
submitBtn.innerHTML = "Updating..."
|
||||
submitBtn.disabled = true
|
||||
|
||||
@ -137,63 +135,58 @@ function updateImgs() {
|
||||
})
|
||||
}
|
||||
|
||||
updateImgs();
|
||||
updateImgs()
|
||||
|
||||
function purchaseItem() {
|
||||
const purchaseBtn = document.getElementById('remember-to-add-auth-verificartion-to-js-handler')
|
||||
if (purchaseBtn.innerHTML == "Buy!") {
|
||||
purchaseBtn.setAttribute("style", "background: #ff813d; width:300px;")
|
||||
purchaseBtn.innerHTML = "Confirm?"
|
||||
function requestItem(){
|
||||
const reqBtn = document.getElementById('req-btn')
|
||||
const bMessage = document.getElementById('bMsg')
|
||||
if (reqBtn.innerHTML == "Request!") {
|
||||
if (firebase.auth().currentUser) {
|
||||
reqBtn.setAttribute("style", "background: #87e5ff; width:300px;")
|
||||
reqBtn.innerHTML = "Send?"
|
||||
bMessage.setAttribute('style', 'display: block;')
|
||||
} else {
|
||||
reqBtn.innerHTML = "Please sign in"
|
||||
reqBtn.setAttribute("style", "background: #FFa5af; width:300px;")
|
||||
}
|
||||
else if (purchaseBtn.innerHTML == "Confirm?") {
|
||||
}
|
||||
else if (reqBtn.innerHTML == "Send?") {
|
||||
if (firebase.auth().currentUser) {
|
||||
firebase.auth().currentUser.getIdToken().then(function(idToken) {
|
||||
var item_id_element = document.getElementById("productID")
|
||||
var item_id = item_id_element.getAttribute("product_id")
|
||||
const url = 'purchase-api'
|
||||
// The data we are going to send in our request
|
||||
let data = {
|
||||
item: item_id,
|
||||
user: idToken
|
||||
}
|
||||
// The parameters we are gonna pass to the fetch function
|
||||
let postData = {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
}
|
||||
reqBtn.innerHTML = "Sending..."
|
||||
reqBtn.disabled = true
|
||||
let userMessage = bMessage.value
|
||||
let item_id = document.getElementById("productID").getAttribute("product_id")
|
||||
const url = 'request-api'
|
||||
let data = {prodID: item_id, authToken: idToken, usrMsg: userMessage}
|
||||
let postData = {method: 'POST', body: JSON.stringify(data), headers: {'Content-Type': 'application/json'}}
|
||||
fetch(url, postData)
|
||||
.then(response => response.json())
|
||||
.then(function(result){
|
||||
console.log(result)
|
||||
if (result.success == true) {
|
||||
purchaseBtn.setAttribute("style", "background: #00DD00; width:500px; transition: 0.7s;")
|
||||
purchaseBtn.innerHTML = "Item Purchased, Congratulations!"
|
||||
reqBtn.setAttribute("style", "background: #00DD00; width:500px; transition: 0.7s;")
|
||||
reqBtn.innerHTML = "Done! Go Home"
|
||||
reqBtn.disabled = false
|
||||
}
|
||||
else {
|
||||
purchaseBtn.setAttribute("style", "background: red;")
|
||||
purchaseBtn.disabled = true
|
||||
purchaseBtn.innerHTML = "ERROR"
|
||||
reqBtn.setAttribute("style", "background: red;")
|
||||
reqBtn.disabled = true
|
||||
reqBtn.innerHTML = "ERROR"
|
||||
document.getElementById("api-response").innerHTML = "Error: " + result.error
|
||||
document.getElementById("api-response").setAttribute("style", "display: block")
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
reqBtn.innerHTML = "Please sign in"
|
||||
}
|
||||
}
|
||||
else {
|
||||
purchaseBtn.innerHTML = "Please log in to continue"
|
||||
purchaseBtn.setAttribute("style", "width: 500px;");
|
||||
window.location.replace('home')
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (purchaseBtn.innerHTML == "Item Purchased, Congratulations!") {
|
||||
window.location.replace("home")
|
||||
}
|
||||
else {
|
||||
purchaseBtn.disabled = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function edit_item() {
|
||||
firebase.auth().currentUser.getIdToken().then(function(idToken) {
|
||||
@ -204,39 +197,78 @@ function edit_item() {
|
||||
.catch(e => {console.log(e)})
|
||||
}
|
||||
|
||||
function place_item_on_sale() {
|
||||
function toggle_sale() {
|
||||
firebase.auth().currentUser.getIdToken().then(function(idToken) {
|
||||
var item_id_element = document.getElementById("productID")
|
||||
var item_id = item_id_element.getAttribute("product_id")
|
||||
var place_on_sale_button = document.getElementById("sellBtn")
|
||||
const url = 'place-on-sale-api'
|
||||
let data = {
|
||||
item: item_id,
|
||||
user: idToken
|
||||
}
|
||||
let postData = {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
}
|
||||
let item_id = document.getElementById("productID").getAttribute("product_id")
|
||||
let item_status = document.getElementById("productID").getAttribute("product_status")
|
||||
let toggle_sale_btn = document.getElementById("toggleSaleBtn")
|
||||
toggle_sale_btn.disabled = true
|
||||
var toggle_status = true
|
||||
if (item_status == 'on-sale') {toggle_status = false}
|
||||
const url = 'toggle-sale-api'
|
||||
let data = {prodID: item_id, authToken: idToken, targetState: toggle_status}
|
||||
let postData = { method: 'POST', body: JSON.stringify(data),headers: {'Content-Type': 'application/json'}}
|
||||
fetch(url, postData)
|
||||
.then(response => response.json())
|
||||
.then(function(result){
|
||||
console.log(result)
|
||||
if (result.success == true) {
|
||||
place_on_sale_button.setAttribute("style", "background: #00DD00; width:200px;")
|
||||
place_on_sale_button.innerHTML = "Item on sale!"
|
||||
place_on_sale_button.disabled = true
|
||||
toggle_sale_btn.setAttribute("style", "background: #00DD00; transition: 0.5s;")
|
||||
toggle_sale_btn.innerHTML = "Done!"
|
||||
let sold_btn = document.getElementById("soldBtn")
|
||||
let edit_button = document.getElementById("editBtn")
|
||||
sold_btn.disabled = true
|
||||
edit_button.disabled = true
|
||||
} else {
|
||||
toggle_sale_btn.setAttribute("style", "background: red;")
|
||||
toggle_sale_btn.innerHTML = "ERROR"
|
||||
document.getElementById("api-response").innerHTML = "Error: " + result.error
|
||||
document.getElementById("api-response").setAttribute("style", "display: block")
|
||||
|
||||
}
|
||||
})
|
||||
.catch (e=>{
|
||||
toggle_sale_btn.setAttribute("style", "background: red;")
|
||||
toggle_sale_btn.innerHTML = "ERROR"
|
||||
document.getElementById("api-response").innerHTML = "Error: " + e
|
||||
document.getElementById("api-response").setAttribute("style", "display: block")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function mark_as_sold(){
|
||||
firebase.auth().currentUser.getIdToken().then(function(idToken) {
|
||||
let item_id = document.getElementById("productID").getAttribute("product_id")
|
||||
let sold_btn = document.getElementById("soldBtn")
|
||||
const url = 'sold-api'
|
||||
let data = {prodID: item_id, authToken: idToken}
|
||||
let postData = { method: 'POST', body: JSON.stringify(data), headers: {'Content-Type': 'application/json'}}
|
||||
fetch(url, postData)
|
||||
.then(response => response.json())
|
||||
.then(function(result){
|
||||
if (result.success == true) {
|
||||
sold_btn.setAttribute("style", "background: #00DD00; width:200px;")
|
||||
sold_btn.innerHTML = "Sold!"
|
||||
sold_btn.disabled = true
|
||||
let sale_button = document.getElementById("toggleSaleBtn")
|
||||
let edit_button = document.getElementById("editBtn")
|
||||
sale_button.disabled = true
|
||||
edit_button.disabled = true
|
||||
}
|
||||
else {
|
||||
place_on_sale_button.setAttribute("style", "background: red;")
|
||||
place_on_sale_button.disabled = true
|
||||
place_on_sale_button.innerHTML = "ERROR"
|
||||
console.log(result.error)
|
||||
sold_btn.setAttribute("style", "background: red;")
|
||||
sold_btn.innerHTML = "ERROR"
|
||||
document.getElementById("api-response").innerHTML = "Error: " + e
|
||||
document.getElementById("api-response").setAttribute("style", "display: block")
|
||||
}
|
||||
})
|
||||
.catch (e=>{
|
||||
sold_btn.setAttribute("style", "background: red;")
|
||||
sold_btn.innerHTML = "ERROR"
|
||||
document.getElementById("api-response").innerHTML = "Error: " + e
|
||||
document.getElementById("api-response").setAttribute("style", "display: block")
|
||||
})
|
||||
})
|
||||
.catch(e => {console.log(e)})
|
||||
}
|
||||
|
||||
function ship_item() {
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 17 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 29 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 22 KiB |
@ -1,65 +1,7 @@
|
||||
<!doctype html>
|
||||
<%- include("partials/header") %>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>GG Prototype</title>
|
||||
<meta name="description" content="GG Prototype Web">
|
||||
<meta name="author" content="Max">
|
||||
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-app.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-analytics.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-auth.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-storage.js"></script>
|
||||
<script defer src="https://www.gstatic.com/firebasejs/7.14.1/firebase-database.js"></script>
|
||||
<script src="js/fInit.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<div class="page">
|
||||
<div class="navbar">
|
||||
<div class="logon-crumbs">
|
||||
<div id="uname-field" style="display: none;">
|
||||
<a id="uname-dom" class="user-name" onclick="my_products();">Unregistered user</a>
|
||||
<div class="user-logout">
|
||||
<a onclick={signout()}>Log out</a>
|
||||
</div>
|
||||
</div>
|
||||
<div id="login-field" style="display: block;">
|
||||
<input id="fuid" type="text" placeholder="Username">
|
||||
<input id="fpwd" type="password" placeholder="Password">
|
||||
<button id="blogin" onclick={signinwithemail()} class="btn-login">➤</button>
|
||||
<button id="blogin_g" onclick={signinwithgoogle()} class="btn-g-login"><img src="media/g_logon.png" class="img-g-login" alt="img"></button>
|
||||
<button id="blogin_g" onclick={signinwithfb()} class="btn-fb-login"><img src="media/fb_logon.png" class="img-g-login" alt="img"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="user-info">
|
||||
<div class="notifications">
|
||||
🔔 | <%= 0%>
|
||||
</div>
|
||||
<div class="cart">
|
||||
🛒 | <%= 0%>
|
||||
</div>
|
||||
<div class="add-item">
|
||||
<a href="additmpage">⊕</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sbar">
|
||||
<img src="media/gg_logo.png" onclick={window.location.replace('home')} alt="img">
|
||||
<input id="sfield" type="text" placeholder="I Want...">
|
||||
<button id="sbutton" onclick={bSearch()}>Go!</button>
|
||||
<a href="#">Extras</a>
|
||||
</div>
|
||||
|
||||
<div class="space"></div>
|
||||
|
||||
<div id="productID" style="display: none;" product_id="<%= key%>"></div>
|
||||
<div id="api-response" class="error-message" style="display: none;"></div>
|
||||
<div id="productID" style="display: none;" product_id="<%= key%>" product_status="<%= item.status%>"></div>
|
||||
<div class="product-page-container">
|
||||
<div class="product-page-info-container">
|
||||
<div class="product-page-img"><img class="dyn-img" src="media/noimage.png" title="<%= item.img %>"></div>
|
||||
@ -67,21 +9,22 @@
|
||||
<h2><%= item.name %> </h2>
|
||||
<p>Seller: You</p>
|
||||
<p>Location: <%= item.location %></p>
|
||||
<p>In stock: <%= item.stock %></p>
|
||||
<p>Quantity: <%= item.stock %></p>
|
||||
<p>Status: <%= item.status %></p>
|
||||
<p>Price: £<%= item.price %></p>
|
||||
<div class="product-mgmt-buttons">
|
||||
<% var editbtnStyle = ""%>
|
||||
<% if (item.status == "shipped") {editbtnStyle = "visibility:hidden;"} else {editbtnStyle = "visibility:all;"}%>
|
||||
<% if (item.status == "sold") {editbtnStyle = "visibility:hidden;"} else {editbtnStyle = "visibility:all;"}%>
|
||||
<div class="edit-btn" style=<%= editbtnStyle%>><button onclick={edit_item()} id="editBtn">Edit</button> </div>
|
||||
<% var sellbtnStyle = ""%>
|
||||
<% if (item.status == "sold") {sellbtnStyle = "visibility:all;"} else {sellbtnStyle = "visibility:hidden;"}%>
|
||||
<div class="sell-btn" style=<%= sellbtnStyle%>><button onclick={place_item_on_sale()} id="sellBtn">Sell</button> </div>
|
||||
<% var sellbtnText = "Place On Sale"%>
|
||||
<% var salebtnStyle = "visibility:hidden"%>
|
||||
<% if (item.status != "sold") {salebtnStyle = "visibility:all;"}%>
|
||||
<% if (item.status == "on-sale") {sellbtnText = "Take Off Sale"}%>
|
||||
<div class="sell-btn" style="<%= salebtnStyle%>"</div>><button onclick={toggle_sale()} id="toggleSaleBtn"><%= sellbtnText%></button> </div>
|
||||
<% var shipbtnStyle = ""%>
|
||||
<% if (item.owner == item.holder || item.status == "shipped") {shipbtnStyle = "visibility:hidden;"} else {shipbtnStyle = "visibility:all;"}%>
|
||||
<div class="ship-btn" style=<%= shipbtnStyle%>><button onclick={ship_item()} id="shipBtn">Ship</button> </div>
|
||||
<% if (item.status == "sold") {shipbtnStyle = "visibility:hidden;"} else {shipbtnStyle = "visibility:all;"}%>
|
||||
<div class="ship-btn" style=<%= shipbtnStyle%>><button onclick={mark_as_sold()} id="soldBtn">Mark Sold</button> </div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="product-page-description"><p><%= item.desc %></p></div>
|
||||
@ -92,26 +35,4 @@
|
||||
</div>
|
||||
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<div class="links">
|
||||
<a href="#">Help</a>
|
||||
<a href="#">Contact</a>
|
||||
<a href="#">Legal</a>
|
||||
</div>
|
||||
<div class="legal">
|
||||
<a>© GG Sales 2019-2020. All Rights Reserved. </a>
|
||||
<a class="link" href="#">User Agreement</a>
|
||||
<a> ,</a>
|
||||
<a class="link" href="#">Privacy</a>
|
||||
<a> ,</a>
|
||||
<a class="link" href="#">Cookies</a>
|
||||
</div>
|
||||
<div class="location">
|
||||
GG Sales US 🇺🇸
|
||||
</div>
|
||||
</footer>
|
||||
<script src="js/fAuth.js"></script>
|
||||
<script src="js/fdb.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
<%- include("partials/footer") %>
|
||||
@ -1,64 +1,4 @@
|
||||
<!doctype html>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>GG Prototype</title>
|
||||
<meta name="description" content="GG Prototype Web">
|
||||
<meta name="author" content="Max">
|
||||
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-app.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-analytics.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-auth.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-storage.js"></script>
|
||||
<script defer src="https://www.gstatic.com/firebasejs/7.14.1/firebase-database.js"></script>
|
||||
<script src="js/fInit.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<div class="page">
|
||||
<div class="navbar">
|
||||
<div class="logon-crumbs">
|
||||
<div id="uname-field" style="display: none;">
|
||||
<a id="uname-dom" class="user-name" href="home">Unregistered user</a>
|
||||
<div class="user-logout">
|
||||
<a onclick={signout()}>Log out</a>
|
||||
</div>
|
||||
</div>
|
||||
<div id="login-field" style="display: block;">
|
||||
<input id="fuid" type="text" placeholder="Username">
|
||||
<input id="fpwd" type="password" placeholder="Password">
|
||||
<button id="blogin" onclick={signinwithemail()} class="btn-login">➤</button>
|
||||
<button id="blogin_g" onclick={signinwithgoogle()} class="btn-g-login"><img src="media/g_logon.png" class="img-g-login" alt="img"></button>
|
||||
<button id="blogin_g" onclick={signinwithfb()} class="btn-fb-login"><img src="media/fb_logon.png" class="img-g-login" alt="img"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="user-info">
|
||||
<div class="notifications">
|
||||
🔔 | <%= 0%>
|
||||
</div>
|
||||
<div class="cart">
|
||||
🛒 | <%= 0%>
|
||||
</div>
|
||||
<div class="add-item">
|
||||
<a href="additmpage">⊕</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="sbar">
|
||||
<img src="media/gg_logo.png" onclick={window.location.replace('home')} alt="img">
|
||||
<input id="sfield" type="text" placeholder="I Want...">
|
||||
<button id="sbutton" onclick={bSearch()}>Go!</button>
|
||||
<a href="#">Extras</a>
|
||||
</div>
|
||||
|
||||
<div class="space"></div>
|
||||
<%- include("partials/header") %>
|
||||
|
||||
<div class="ship-adress">
|
||||
<button id="shippingaddressbutton" style="display: block" onclick={showShipField()}>Edit Your Shipping Address</button>
|
||||
@ -91,26 +31,4 @@
|
||||
</div>
|
||||
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<div class="links">
|
||||
<a href="#">Help</a>
|
||||
<a href="#">Contact</a>
|
||||
<a href="#">Legal</a>
|
||||
</div>
|
||||
<div class="legal">
|
||||
<a>© GG Sales 2019-2020. All Rights Reserved. </a>
|
||||
<a class="link" href="#">User Agreement</a>
|
||||
<a> ,</a>
|
||||
<a class="link" href="#">Privacy</a>
|
||||
<a> ,</a>
|
||||
<a class="link" href="#">Cookies</a>
|
||||
</div>
|
||||
<div class="location">
|
||||
GG Sales US 🇺🇸
|
||||
</div>
|
||||
</footer>
|
||||
<script src="js/fAuth.js"></script>
|
||||
<script src="js/fdb.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
<%- include("partials/footer") %>
|
||||
22
functions/views/partials/footer.ejs
Normal file
22
functions/views/partials/footer.ejs
Normal file
@ -0,0 +1,22 @@
|
||||
<footer>
|
||||
<div class="links">
|
||||
<a href="#">Help</a>
|
||||
<a href="#">Contact</a>
|
||||
<a href="#">Legal</a>
|
||||
</div>
|
||||
<div class="legal">
|
||||
<a>© GG Sales 2019-2020. All Rights Reserved. </a>
|
||||
<a class="link" href="#">User Agreement</a>
|
||||
<a> ,</a>
|
||||
<a class="link" href="#">Privacy</a>
|
||||
<a> ,</a>
|
||||
<a class="link" href="#">Cookies</a>
|
||||
</div>
|
||||
<div class="location">
|
||||
GG Sales US 🇺🇸
|
||||
</div>
|
||||
</footer>
|
||||
<script src="js/fAuth.js"></script>
|
||||
<script src="js/fdb.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
60
functions/views/partials/header.ejs
Normal file
60
functions/views/partials/header.ejs
Normal file
@ -0,0 +1,60 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>GG Prototype</title>
|
||||
<meta name="description" content="GG Prototype Web">
|
||||
<meta name="author" content="Max">
|
||||
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-app.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-analytics.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-auth.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-storage.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-database.js"></script>
|
||||
<script src="js/fInit.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<div class="page">
|
||||
<div class="navbar">
|
||||
<div class="logon-crumbs">
|
||||
<div id="uname-field" style="display: none;">
|
||||
<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>
|
||||
</div>
|
||||
<div id="login-field" style="display: block;">
|
||||
<input id="fuid" type="text" placeholder="Username">
|
||||
<input id="fpwd" type="password" placeholder="Password">
|
||||
<button id="blogin" onclick={signinwithemail()} class="btn-login">➤</button>
|
||||
<button id="blogin_g" onclick={signinwithgoogle()} class="btn-g-login"><img src="media/g_logon.png" class="img-g-login" alt="img"></button>
|
||||
<button id="blogin_g" onclick={signinwithfb()} class="btn-fb-login"><img src="media/fb_logon.png" class="img-g-login" alt="img"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="user-info">
|
||||
<div class="notifications">
|
||||
🔔 | <%= 0%>
|
||||
</div>
|
||||
<div class="cart">
|
||||
🛒 | <%= 0%>
|
||||
</div>
|
||||
<div class="add-item">
|
||||
<a href="additmpage">⊕</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sbar">
|
||||
<img src="media/gg_logo.png" onclick={window.location.replace('home')} alt="img">
|
||||
<input id="sfield" type="text" placeholder="I Want...">
|
||||
<button id="sbutton" onclick={bSearch()}>Go!</button>
|
||||
<a href="#">Extras</a>
|
||||
</div>
|
||||
|
||||
<div class="space"></div>
|
||||
@ -1,63 +1,5 @@
|
||||
<!doctype html>
|
||||
<%- include("partials/header") %>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>GG Prototype</title>
|
||||
<meta name="description" content="GG Prototype Web">
|
||||
<meta name="author" content="Max">
|
||||
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-app.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-analytics.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-auth.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-storage.js"></script>
|
||||
<script defer src="https://www.gstatic.com/firebasejs/7.14.1/firebase-database.js"></script>
|
||||
<script src="js/fInit.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<div class="page">
|
||||
<div class="navbar">
|
||||
<div class="logon-crumbs">
|
||||
<div id="uname-field" style="display: none;">
|
||||
<a id="uname-dom" class="user-name" onclick="my_products();">Unregistered user</a>
|
||||
<div class="user-logout">
|
||||
<a onclick={signout()}>Log out</a>
|
||||
</div>
|
||||
</div>
|
||||
<div id="login-field" style="display: block;">
|
||||
<input id="fuid" type="text" placeholder="Username">
|
||||
<input id="fpwd" type="password" placeholder="Password">
|
||||
<button id="blogin" onclick={signinwithemail()} class="btn-login">➤</button>
|
||||
<button id="blogin_g" onclick={signinwithgoogle()} class="btn-g-login"><img src="media/g_logon.png" class="img-g-login" alt="img"></button>
|
||||
<button id="blogin_g" onclick={signinwithfb()} class="btn-fb-login"><img src="media/fb_logon.png" class="img-g-login" alt="img"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="user-info">
|
||||
<div class="notifications">
|
||||
🔔 | <%= 0%>
|
||||
</div>
|
||||
<div class="cart">
|
||||
🛒 | <%= 0%>
|
||||
</div>
|
||||
<div class="add-item">
|
||||
<a href="additmpage">⊕</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sbar">
|
||||
<img src="media/gg_logo.png" onclick={window.location.replace('home')} alt="img">
|
||||
<input id="sfield" type="text" placeholder="I Want...">
|
||||
<button id="sbutton" onclick={bSearch()}>Go!</button>
|
||||
<a href="#">Extras</a>
|
||||
</div>
|
||||
|
||||
<div class="space"></div>
|
||||
<div id="api-response" class="purchase-message" style="display: none;color: #DD0000"></div>
|
||||
<div id="productID" style="display: none;" product_id="<%= key%>"></div>
|
||||
<div class="product-page-container">
|
||||
@ -67,9 +9,10 @@
|
||||
<h2><%= item.name %> </h2>
|
||||
<p>Seller: <%= seller %></p>
|
||||
<p>Location: <%= item.location %></p>
|
||||
<p>In stock: <%= item.stock %></p>
|
||||
<p>Quantity: <%= item.stock %></p>
|
||||
<p>Price: £<%= item.price %></p>
|
||||
<button onclick={purchaseItem()} id="remember-to-add-auth-verificartion-to-js-handler">Buy!</button>
|
||||
<input id="bMsg" type="text" placeholder="Your message to the seller" value="Hi, I would like to purchse your item" style="display: none;">
|
||||
<button onclick={requestItem()} id="req-btn">Request!</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="product-page-description"><p><%= item.desc %></p></div>
|
||||
@ -80,26 +23,4 @@
|
||||
</div>
|
||||
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<div class="links">
|
||||
<a href="#">Help</a>
|
||||
<a href="#">Contact</a>
|
||||
<a href="#">Legal</a>
|
||||
</div>
|
||||
<div class="legal">
|
||||
<a>© GG Sales 2019-2020. All Rights Reserved. </a>
|
||||
<a class="link" href="#">User Agreement</a>
|
||||
<a> ,</a>
|
||||
<a class="link" href="#">Privacy</a>
|
||||
<a> ,</a>
|
||||
<a class="link" href="#">Cookies</a>
|
||||
</div>
|
||||
<div class="location">
|
||||
GG Sales US 🇺🇸
|
||||
</div>
|
||||
</footer>
|
||||
<script src="js/fAuth.js"></script>
|
||||
<script src="js/fdb.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
<%- include("partials/footer") %>
|
||||
@ -1,64 +1,4 @@
|
||||
<!doctype html>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>GG Prototype</title>
|
||||
<meta name="description" content="GG Prototype Web">
|
||||
<meta name="author" content="Max">
|
||||
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-app.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-analytics.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-auth.js"></script>
|
||||
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-storage.js"></script>
|
||||
<script defer src="https://www.gstatic.com/firebasejs/7.14.1/firebase-database.js"></script>
|
||||
<script src="js/fInit.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<div class="page">
|
||||
<div class="navbar">
|
||||
<div class="logon-crumbs">
|
||||
<div id="uname-field" style="display: none;">
|
||||
<a id="uname-dom" class="user-name" href="home">Unregistered user</a>
|
||||
<div class="user-logout">
|
||||
<a onclick={signout()}>Log out</a>
|
||||
</div>
|
||||
</div>
|
||||
<div id="login-field" style="display: block;">
|
||||
<input id="fuid" type="text" placeholder="Username">
|
||||
<input id="fpwd" type="password" placeholder="Password">
|
||||
<button id="blogin" onclick={signinwithemail()} class="btn-login">➤</button>
|
||||
<button id="blogin_g" onclick={signinwithgoogle()} class="btn-g-login"><img src="media/g_logon.png" class="img-g-login" alt="img"></button>
|
||||
<button id="blogin_g" onclick={signinwithfb()} class="btn-fb-login"><img src="media/fb_logon.png" class="img-g-login" alt="img"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="user-info">
|
||||
<div class="notifications">
|
||||
🔔 | <%= 0%>
|
||||
</div>
|
||||
<div class="cart">
|
||||
🛒 | <%= 0%>
|
||||
</div>
|
||||
<div class="add-item">
|
||||
<a href="additmpage">⊕</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="sbar">
|
||||
<img src="media/gg_logo.png" onclick={window.location.replace('home')} alt="img">
|
||||
<input id="sfield" type="text" placeholder="I Want...">
|
||||
<button id="sbutton" onclick={bSearch()}>Go!</button>
|
||||
<a href="#">Extras</a>
|
||||
</div>
|
||||
|
||||
<div class="space"></div>
|
||||
<%- include("partials/header") %>
|
||||
|
||||
<div class="products">
|
||||
<p>Search results:</p>
|
||||
@ -75,35 +15,9 @@
|
||||
</div>
|
||||
</div>
|
||||
<% }) %>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="space"></div>
|
||||
</div>
|
||||
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<div class="links">
|
||||
<a href="#">Help</a>
|
||||
<a href="#">Contact</a>
|
||||
<a href="#">Legal</a>
|
||||
</div>
|
||||
<div class="legal">
|
||||
<a>© GG Sales 2019-2020. All Rights Reserved. </a>
|
||||
<a class="link" href="#">User Agreement</a>
|
||||
<a> ,</a>
|
||||
<a class="link" href="#">Privacy</a>
|
||||
<a> ,</a>
|
||||
<a class="link" href="#">Cookies</a>
|
||||
</div>
|
||||
<div class="location">
|
||||
GG Sales US 🇺🇸
|
||||
</div>
|
||||
</footer>
|
||||
<script src="js/fAuth.js"></script>
|
||||
<script src="js/fdb.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
<%- include("partials/footer") %>
|
||||
289
server.js
289
server.js
@ -9,7 +9,6 @@ let firebaseadmin = admin.initializeApp({
|
||||
databaseURL: "https://project-gg-3b754.firebaseio.com"
|
||||
})
|
||||
let database = firebaseadmin.database()
|
||||
let auth = admin.auth();
|
||||
|
||||
let app = express()
|
||||
app.use(bodyParser.urlencoded({extended: true}))
|
||||
@ -27,7 +26,7 @@ let transporter = nodemailer.createTransport({
|
||||
user: 'noreply.projectgg@gmail.com',
|
||||
pass: 'kynpef-5paqha-xaVxip'
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
app.get("/", function(request, responce) {
|
||||
@ -111,31 +110,16 @@ app.get('/my-products', function(request, responce){
|
||||
}
|
||||
else {
|
||||
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: ''
|
||||
},
|
||||
}
|
||||
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})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
.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>")
|
||||
@ -235,109 +219,112 @@ app.get('/product', function(request, responce){
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/purchase-api', function(request, responce){
|
||||
if (request.body.item && request.body.user) {
|
||||
admin.auth().verifyIdToken(request.body.user)
|
||||
.then(function(decodedToken) {
|
||||
let uid = decodedToken.uid;
|
||||
let product = request.body.item
|
||||
var productRef = database.ref("/products/"+product)
|
||||
productRef.once('value', function(snapshot) {
|
||||
var exists = (snapshot.val() !== null)
|
||||
if (exists){
|
||||
var productRef = database.ref("/products/"+product)
|
||||
productRef.update({owner:uid, status:"sold"})
|
||||
.then(function(){
|
||||
responce.send({success:true, error:null})
|
||||
})
|
||||
.catch(e => {console.log(e)})
|
||||
}
|
||||
else {
|
||||
responce.send({success:false, error:'Item does not exist'})
|
||||
}
|
||||
})
|
||||
.catch(e => {console.log(e)})
|
||||
})
|
||||
.catch(function(err) {
|
||||
responce.send({success:false, error:'invalid auth token'})
|
||||
});
|
||||
}
|
||||
else {
|
||||
responce.send({success:false, error:'invalid data'})
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/place-on-sale-api', function(request, responce){
|
||||
if (request.body.item && request.body.user) {
|
||||
admin.auth().verifyIdToken(request.body.user)
|
||||
.then(function(decodedToken) {
|
||||
let uid = decodedToken.uid;
|
||||
let productID = request.body.item
|
||||
var productRef = database.ref("/products/"+productID)
|
||||
|
||||
productRef.once('value',function(snapshot){
|
||||
let item = snapshot.val()
|
||||
if (item){
|
||||
let itemOwner = item.owner
|
||||
if (uid == itemOwner){
|
||||
productRef.update({status:"on-sale"})
|
||||
.then(function(){
|
||||
responce.send({success:true, error:null})
|
||||
})
|
||||
.catch(e => {console.log(e)})
|
||||
}
|
||||
else {
|
||||
responce.send({success:false, error:'You do not own this item'})
|
||||
}
|
||||
}
|
||||
else {
|
||||
responce.send({success:false, error:'Item does not exist'})
|
||||
}
|
||||
})
|
||||
.catch(e=>{
|
||||
console.log(e)
|
||||
responce.send({success:false, error:'other, ' + e})
|
||||
})
|
||||
})
|
||||
.catch(function(error) {
|
||||
responce.send({success:false, error:'invalid auth token'})
|
||||
})
|
||||
}
|
||||
else {
|
||||
responce.send({success:false, error:'invalid data'})
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/ship-api', function(request, responce){
|
||||
if (request.body.item && request.body.user) {
|
||||
admin.auth().verifyIdToken(request.body.user)
|
||||
.then(async function(decodedToken) {
|
||||
let uid = decodedToken.uid;
|
||||
let pid = request.body.item
|
||||
|
||||
if (await verifyExists(pid)){
|
||||
if (await verifyOwner(uid, pid)) {
|
||||
app.post('/request-api', async function(request, responce){
|
||||
if (request.body.prodID && request.body.authToken && request.body.usrMsg) {
|
||||
let bMsg = request.body.usrMsg
|
||||
let uid = await authCheck(request.body.authToken)
|
||||
if (uid) {
|
||||
let pid = request.body.prodID
|
||||
let productRef = database.ref("/products/"+ pid)
|
||||
productRef.update({status:"shipped"})
|
||||
.then(function(){
|
||||
processItemShipEmail(pid, uid)
|
||||
var snapshot = await productRef.once('value')
|
||||
if (snapshot.exists()) {
|
||||
let product = snapshot.val()
|
||||
let productName = product.name
|
||||
let productSeller = product.owner
|
||||
let usersRef = database.ref("/users")
|
||||
snapshot = await usersRef.orderByChild("UID").equalTo(productSeller).once('value')
|
||||
if (snapshot.exists()) {
|
||||
let vals = snapshot.val()
|
||||
let keys = Object.keys(vals)
|
||||
let seller = vals[keys[0]]
|
||||
let sellerName = seller.fName
|
||||
let sellerEmail = seller.email
|
||||
snapshot = await usersRef.orderByChild("UID").equalTo(uid).once('value')
|
||||
if (snapshot.exists()) {
|
||||
let vals = snapshot.val()
|
||||
let keys = Object.keys(vals)
|
||||
let buyer = vals[keys[0]]
|
||||
let buyerName = buyer.fName + ' ' + buyer.lName
|
||||
let buyerEmail = buyer.email
|
||||
let content = contentMaker(sellerName, buyerName, buyerEmail, productName, pid, bMsg)
|
||||
let rsp = sendEmail(sellerEmail, content)
|
||||
console.log(rsp)
|
||||
responce.send({success:true, error:null})
|
||||
})
|
||||
.catch(e => {console.log(e)})
|
||||
} else {
|
||||
responce.send({success:false, error:'Something very bad has happened..... Item buyer apparantly doesn\'t exist in the database'})
|
||||
}
|
||||
else {
|
||||
responce.send({success:false, error:'You do not own this item'})
|
||||
} else {
|
||||
responce.send({success:false, error:'Something very bad has happened..... Item owner apparantly doesn\'t exist in the database'})
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
responce.send({success:false, error:'Item does not exist'})
|
||||
}
|
||||
})
|
||||
.catch(function(error) {
|
||||
} else {
|
||||
responce.send({success:false, error:'invalid auth token'})
|
||||
})
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
responce.send({success:false, error:'invalid data'})
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/toggle-sale-api', async function(request, responce){
|
||||
if (request.body.prodID && request.body.authToken && (request.body.targetState != null)) {
|
||||
let uid = await authCheck(request.body.authToken)
|
||||
if (uid) {
|
||||
let pid = request.body.prodID
|
||||
let targetState = request.body.targetState
|
||||
let productRef = database.ref("/products/"+ pid)
|
||||
var snapshot = await productRef.once('value')
|
||||
if (snapshot.exists()) {
|
||||
let product = snapshot.val()
|
||||
if (product.owner == uid && product.status != "sold") {
|
||||
let status = "x"
|
||||
if (targetState == true) {
|
||||
status = "on-sale"
|
||||
} else {
|
||||
status = "off-sale"
|
||||
}
|
||||
productRef.update({status:status})
|
||||
.then(responce.send({success:true, error:null}))
|
||||
.catch(e => {responce.send({success:false, error:e})})
|
||||
} else {
|
||||
responce.send({success:false, error:'Unauthorized'})
|
||||
}
|
||||
} else {
|
||||
responce.send({success:false, error:'Item does not exist'})
|
||||
}
|
||||
} else {
|
||||
responce.send({success:false, error:'invalid auth token'})
|
||||
}
|
||||
} else {
|
||||
responce.send({success:false, error:'invalid data'})
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/sold-api', async function(request, responce){
|
||||
if (request.body.prodID && request.body.authToken) {
|
||||
let uid = await authCheck(request.body.authToken)
|
||||
if (uid) {
|
||||
let pid = request.body.prodID
|
||||
let productRef = database.ref("/products/"+ pid)
|
||||
var snapshot = await productRef.once('value')
|
||||
if (snapshot.exists()) {
|
||||
let product = snapshot.val()
|
||||
if (product.owner == uid) {
|
||||
productRef.update({status:"sold"})
|
||||
.then(responce.send({success:true, error:null}))
|
||||
.catch(e => {responce.send({success:false, error:e})})
|
||||
} else {
|
||||
responce.send({success:false, error:'Unauthorized'})
|
||||
}
|
||||
} else {
|
||||
responce.send({success:false, error:'Item does not exist'})
|
||||
}
|
||||
} else {
|
||||
responce.send({success:false, error:'invalid auth token'})
|
||||
}
|
||||
} else {
|
||||
responce.send({success:false, error:'invalid data'})
|
||||
}
|
||||
})
|
||||
@ -363,7 +350,7 @@ app.post('/login-user-api', function(request, responce){
|
||||
});
|
||||
}
|
||||
else {
|
||||
responce.send({error: 'invalid data'})
|
||||
responce.send({success:false, error: 'invalid data'})
|
||||
}
|
||||
})
|
||||
|
||||
@ -475,37 +462,17 @@ app.post('/update-product-api', function(request, responce){
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
app.post('/demo-api', function(request, responce){
|
||||
if (request.body.item && request.body.user) {
|
||||
admin.auth().verifyIdToken(request.body.user)
|
||||
.then(async function(decodedToken) {
|
||||
if (await verifyExists(request.body.item)){
|
||||
if (await verifyOwner(decodedToken.uid, request.body.item)) {
|
||||
responce.send({success:true, error:null, data:"x"})
|
||||
function contentMaker(sName, bName, bEmail, pName, pid, bMsg){
|
||||
let text = "Hi " + sName + "\n \n" + bName + " is interested in your product " + pName + " (ID: " + pid + ")\n\nUser email: " + bEmail +"\n\nUser message:\n" + bMsg
|
||||
return text
|
||||
}
|
||||
else {
|
||||
responce.send({success:false, error:'You do not own this item'})
|
||||
}
|
||||
}
|
||||
else {
|
||||
responce.send({success:false, error:'Item does not exist'})
|
||||
}
|
||||
})
|
||||
.catch(function(error) {
|
||||
responce.send({success:false, error:'invalid auth token'})
|
||||
console.log(error)
|
||||
});
|
||||
}
|
||||
else {
|
||||
responce.send({success:false, error: 'invalid data'})
|
||||
}
|
||||
})
|
||||
|
||||
async function authCheck(token) {
|
||||
let uid = false
|
||||
decodedToken = await admin.auth().verifyIdToken(token).catch(e=>{console.log(e)})
|
||||
uid = decodedToken.uid
|
||||
return uid
|
||||
}
|
||||
|
||||
async function checkNewUser(user){
|
||||
let snapshot = await checkUserExists(user.uid)
|
||||
@ -572,47 +539,25 @@ async function verifyOwner(uid, pid) {
|
||||
|
||||
function sendEmail(address, content){
|
||||
var mailOptions = {
|
||||
from: 'noreply.projectgg@gmail.com',
|
||||
from: 'Project GG',
|
||||
to: address,
|
||||
subject: 'Your Item has been requested',
|
||||
subject: 'Someone\'s interested!',
|
||||
text: content
|
||||
}
|
||||
transporter.sendMail(mailOptions, function(error, info){
|
||||
if (error) {
|
||||
console.log(error);
|
||||
} else {
|
||||
console.log('Email sent: ' + info.response);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function processItemShipEmail(itemID, buyerID){
|
||||
let productRef = database.ref("/products/"+itemID)
|
||||
productRef.once('value',function(snapshot){
|
||||
let item = snapshot.val()
|
||||
let itemName = item.name
|
||||
let itemHolder = item.holder
|
||||
let usersRef = database.ref("/users")
|
||||
usersRef.orderByChild("UID").equalTo(itemHolder).once('value', function(snapshot){
|
||||
vals = snapshot.val()
|
||||
var keys = Object.keys(vals)
|
||||
uData = vals[keys[0]]
|
||||
let holderEmail = uData.email
|
||||
let clientRef = database.ref("/users")
|
||||
usersRef.orderByChild("UID").equalTo(buyerID).once('value', function(snapshot){
|
||||
cvals = snapshot.val()
|
||||
var ckeys = Object.keys(cvals)
|
||||
cData = cvals[ckeys[0]]
|
||||
let clientAddress = cData.address
|
||||
let emailContent = "Please ship Item: " + itemName + " (ItemID: " + itemID + ")\nShipping address: " + clientAddress
|
||||
sendEmail(holderEmail, emailContent)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
app.get('*', function(request, responce){
|
||||
responce.render('404.ejs')
|
||||
responce.status(404).render('404.ejs')
|
||||
})
|
||||
|
||||
app.post('*', function(request, responce){
|
||||
responce.status(404).send({success:false, error:"404"})
|
||||
})
|
||||
|
||||
var port = 5000
|
||||
|
||||
Loading…
Reference in New Issue
Block a user