Update
This commit is contained in:
parent
9df97896c7
commit
6479d82933
@ -13,10 +13,8 @@ let firebaseadmin = admin.initializeApp({
|
|||||||
let database = firebaseadmin.database()
|
let database = firebaseadmin.database()
|
||||||
|
|
||||||
let app = express()
|
let app = express()
|
||||||
|
|
||||||
app.use(bodyParser.urlencoded({extended: true}))
|
app.use(bodyParser.urlencoded({extended: true}))
|
||||||
app.use(bodyParser.json({ limit: '10mb' }));
|
app.use(bodyParser.json({ limit: '10mb' }));
|
||||||
|
|
||||||
app.use(logger('dev'))
|
app.use(logger('dev'))
|
||||||
app.use(express.static('views'))
|
app.use(express.static('views'))
|
||||||
|
|
||||||
@ -30,7 +28,7 @@ let transporter = nodemailer.createTransport({
|
|||||||
user: 'noreply.projectgg@gmail.com',
|
user: 'noreply.projectgg@gmail.com',
|
||||||
pass: 'kynpef-5paqha-xaVxip'
|
pass: 'kynpef-5paqha-xaVxip'
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
|
|
||||||
app.get("/", function(request, responce) {
|
app.get("/", function(request, responce) {
|
||||||
@ -113,17 +111,11 @@ app.get('/my-products', function(request, responce){
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dbRef.orderByChild('owner').equalTo(uid).once('value', function(snapshot){
|
dbRef.orderByChild('owner').equalTo(uid).once('value', function(snapshot){
|
||||||
var data = {
|
var data = {'x': {desc: '', holder: '', id: 999, img: '', location: '', name: 'No products listed 😢', owner: '', price: '', public: '', stock: ''}}
|
||||||
'x': {desc: '', holder: '', id: 999, img: '', location: '', name: 'No products listed 😢',
|
|
||||||
owner: '', price: '', public: '', stock: ''
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if (snapshot.val()) {data = snapshot.val()}
|
if (snapshot.val()) {data = snapshot.val()}
|
||||||
responce.render('my-products.ejs', {products: data})
|
responce.render('my-products.ejs', {products: data})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
console.log(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) {
|
app.post('/request-api', async function(request, responce){
|
||||||
admin.auth().verifyIdToken(request.body.user)
|
if (request.body.prodID && request.body.authToken && request.body.usrMsg) {
|
||||||
.then(function(decodedToken) {
|
let bMsg = request.body.usrMsg
|
||||||
let uid = decodedToken.uid;
|
let uid = await authCheck(request.body.authToken)
|
||||||
let product = request.body.item
|
if (uid) {
|
||||||
var productRef = database.ref("/products/"+product)
|
let pid = request.body.prodID
|
||||||
productRef.once('value', function(snapshot) {
|
let productRef = database.ref("/products/"+ pid)
|
||||||
var exists = (snapshot.val() !== null)
|
var snapshot = await productRef.once('value')
|
||||||
if (exists){
|
if (snapshot.exists()) {
|
||||||
var productRef = database.ref("/products/"+product)
|
let product = snapshot.val()
|
||||||
productRef.update({owner:uid, status:"sold"})
|
let productName = product.name
|
||||||
.then(function(){
|
let productSeller = product.owner
|
||||||
responce.send({success:true, error:null})
|
let usersRef = database.ref("/users")
|
||||||
})
|
snapshot = await usersRef.orderByChild("UID").equalTo(productSeller).once('value')
|
||||||
.catch(e => {console.log(e)})
|
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})
|
||||||
|
} else {
|
||||||
|
responce.send({success:false, error:'Something very bad has happened..... Item buyer apparantly doesn\'t exist in the database'})
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
responce.send({success:false, error:'Item does not exist'})
|
responce.send({success:false, error:'Something very bad has happened..... Item owner apparantly doesn\'t exist in the database'})
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
.catch(e => {console.log(e)})
|
responce.send({success:false, error:'Item does not exist'})
|
||||||
})
|
}
|
||||||
.catch(function(err) {
|
} else {
|
||||||
responce.send({success:false, error:'invalid auth token'})
|
responce.send({success:false, error:'invalid auth token'})
|
||||||
});
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
responce.send({success:false, error:'invalid data'})
|
responce.send({success:false, error:'invalid data'})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post('/place-on-sale-api', function(request, responce){
|
app.post('/toggle-sale-api', async function(request, responce){
|
||||||
if (request.body.item && request.body.user) {
|
if (request.body.prodID && request.body.authToken && (request.body.targetState != null)) {
|
||||||
admin.auth().verifyIdToken(request.body.user)
|
let uid = await authCheck(request.body.authToken)
|
||||||
.then(function(decodedToken) {
|
if (uid) {
|
||||||
let uid = decodedToken.uid;
|
let pid = request.body.prodID
|
||||||
let productID = request.body.item
|
let targetState = request.body.targetState
|
||||||
var productRef = database.ref("/products/"+productID)
|
let productRef = database.ref("/products/"+ pid)
|
||||||
|
var snapshot = await productRef.once('value')
|
||||||
productRef.once('value',function(snapshot){
|
if (snapshot.exists()) {
|
||||||
let item = snapshot.val()
|
let product = snapshot.val()
|
||||||
if (item){
|
if (product.owner == uid && product.status != "sold") {
|
||||||
let itemOwner = item.owner
|
let status = "x"
|
||||||
if (uid == itemOwner){
|
if (targetState == true) {
|
||||||
productRef.update({status:"on-sale"})
|
status = "on-sale"
|
||||||
.then(function(){
|
} else {
|
||||||
responce.send({success:true, error:null})
|
status = "off-sale"
|
||||||
})
|
|
||||||
.catch(e => {console.log(e)})
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
responce.send({success:false, error:'You do not own this item'})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
productRef.update({status:status})
|
||||||
responce.send({success:false, error:'Item does not exist'})
|
.then(responce.send({success:true, error:null}))
|
||||||
}
|
.catch(e => {responce.send({success:false, error:e})})
|
||||||
})
|
} else {
|
||||||
.catch(e=>{
|
responce.send({success:false, error:'Unauthorized'})
|
||||||
console.log(e)
|
}
|
||||||
responce.send({success:false, error:'other, ' + e})
|
} else {
|
||||||
})
|
responce.send({success:false, error:'Item does not exist'})
|
||||||
})
|
}
|
||||||
.catch(function(error) {
|
} else {
|
||||||
responce.send({success:false, error:'invalid auth token'})
|
responce.send({success:false, error:'invalid auth token'})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
responce.send({success:false, error:'invalid data'})
|
responce.send({success:false, error:'invalid data'})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post('/ship-api', function(request, responce){
|
app.post('/sold-api', async function(request, responce){
|
||||||
if (request.body.item && request.body.user) {
|
if (request.body.prodID && request.body.authToken) {
|
||||||
admin.auth().verifyIdToken(request.body.user)
|
let uid = await authCheck(request.body.authToken)
|
||||||
.then(async function(decodedToken) {
|
if (uid) {
|
||||||
let uid = decodedToken.uid;
|
let pid = request.body.prodID
|
||||||
let pid = request.body.item
|
let productRef = database.ref("/products/"+ pid)
|
||||||
|
var snapshot = await productRef.once('value')
|
||||||
if (await verifyExists(pid)){
|
if (snapshot.exists()) {
|
||||||
if (await verifyOwner(uid, pid)) {
|
let product = snapshot.val()
|
||||||
let productRef = database.ref("/products/"+pid)
|
if (product.owner == uid) {
|
||||||
productRef.update({status:"shipped"})
|
productRef.update({status:"sold"})
|
||||||
.then(function(){
|
.then(responce.send({success:true, error:null}))
|
||||||
processItemShipEmail(pid, uid)
|
.catch(e => {responce.send({success:false, error:e})})
|
||||||
responce.send({success:true, error:null})
|
} else {
|
||||||
})
|
responce.send({success:false, error:'Unauthorized'})
|
||||||
.catch(e => {console.log(e)})
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
responce.send({success:false, error:'You do not own this item'})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
responce.send({success:false, error:'Item does not exist'})
|
responce.send({success:false, error:'Item does not exist'})
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
.catch(function(error) {
|
responce.send({success:false, error:'invalid auth token'})
|
||||||
responce.send({success:false, error:'invalid auth token'})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
responce.send({success:false, error:'invalid data'})
|
responce.send({success:false, error:'invalid data'})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -356,7 +351,7 @@ app.post('/login-user-api', function(request, responce){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
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){
|
async function checkNewUser(user){
|
||||||
let snapshot = await checkUserExists(user.uid)
|
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){
|
function sendEmail(address, content){
|
||||||
var mailOptions = {
|
var mailOptions = {
|
||||||
from: 'noreply.projectgg@gmail.com',
|
from: 'Project GG',
|
||||||
to: address,
|
to: address,
|
||||||
subject: 'Your Item has been requested',
|
subject: 'Someone\'s interested!',
|
||||||
text: content
|
text: content
|
||||||
}
|
}
|
||||||
transporter.sendMail(mailOptions, function(error, info){
|
transporter.sendMail(mailOptions, function(error, info){
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
} else {
|
}
|
||||||
console.log('Email sent: ' + info.response);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
app.get('*', function(request, responce){
|
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)
|
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;
|
font-size: 20px;
|
||||||
padding-top: 38px;
|
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 {
|
.product-page-description {
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
@ -563,11 +576,19 @@ footer a {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.purchase-message {
|
.purchase-message {
|
||||||
color: #00df90;
|
color: #00df90;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 25px;
|
font-size: 25px;
|
||||||
font-family: osl;
|
font-family: osl;
|
||||||
padding-bottom: 10px;
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-message {
|
||||||
|
color: #df0000;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 25px;
|
||||||
|
font-family: osl;
|
||||||
|
padding-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.product-mgmt-buttons {
|
.product-mgmt-buttons {
|
||||||
@ -576,7 +597,7 @@ footer a {
|
|||||||
.product-mgmt-buttons button {
|
.product-mgmt-buttons button {
|
||||||
margin-top: 38px;
|
margin-top: 38px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
width: 100px;
|
width: 150px;
|
||||||
display: block;
|
display: block;
|
||||||
font-size: 19px;
|
font-size: 19px;
|
||||||
font-family: osl;
|
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 %>;">
|
<div class="user-message" style="display: <%= message %>;">
|
||||||
<p>Product added successfully</p>
|
<p>Product added successfully</p>
|
||||||
</div>
|
</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">
|
<div class="welcome">
|
||||||
<img src="media/welcome.png">
|
<img src="media/welcome.png">
|
||||||
@ -150,26 +93,4 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
<%- include("partials/footer") %>
|
||||||
<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>
|
|
||||||
@ -88,8 +88,6 @@ function productUpdateEventHandler() {
|
|||||||
const item_id_element = document.getElementById("productID")
|
const item_id_element = document.getElementById("productID")
|
||||||
const item_id = item_id_element.getAttribute("product_id")
|
const item_id = item_id_element.getAttribute("product_id")
|
||||||
|
|
||||||
const sessUid = firebase.auth().currentUser.uid
|
|
||||||
|
|
||||||
submitBtn.innerHTML = "Updating..."
|
submitBtn.innerHTML = "Updating..."
|
||||||
submitBtn.disabled = true
|
submitBtn.disabled = true
|
||||||
|
|
||||||
@ -137,64 +135,59 @@ function updateImgs() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
updateImgs();
|
updateImgs()
|
||||||
|
|
||||||
function purchaseItem() {
|
function requestItem(){
|
||||||
const purchaseBtn = document.getElementById('remember-to-add-auth-verificartion-to-js-handler')
|
const reqBtn = document.getElementById('req-btn')
|
||||||
if (purchaseBtn.innerHTML == "Buy!") {
|
const bMessage = document.getElementById('bMsg')
|
||||||
purchaseBtn.setAttribute("style", "background: #ff813d; width:300px;")
|
if (reqBtn.innerHTML == "Request!") {
|
||||||
purchaseBtn.innerHTML = "Confirm?"
|
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) {
|
if (firebase.auth().currentUser) {
|
||||||
firebase.auth().currentUser.getIdToken().then(function(idToken) {
|
firebase.auth().currentUser.getIdToken().then(function(idToken) {
|
||||||
var item_id_element = document.getElementById("productID")
|
reqBtn.innerHTML = "Sending..."
|
||||||
var item_id = item_id_element.getAttribute("product_id")
|
reqBtn.disabled = true
|
||||||
const url = 'purchase-api'
|
let userMessage = bMessage.value
|
||||||
// The data we are going to send in our request
|
let item_id = document.getElementById("productID").getAttribute("product_id")
|
||||||
let data = {
|
const url = 'request-api'
|
||||||
item: item_id,
|
let data = {prodID: item_id, authToken: idToken, usrMsg: userMessage}
|
||||||
user: idToken
|
let postData = {method: 'POST', body: JSON.stringify(data), headers: {'Content-Type': 'application/json'}}
|
||||||
}
|
|
||||||
// The parameters we are gonna pass to the fetch function
|
|
||||||
let postData = {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(data),
|
|
||||||
headers: {'Content-Type': 'application/json'}
|
|
||||||
}
|
|
||||||
fetch(url, postData)
|
fetch(url, postData)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(function(result){
|
.then(function(result){
|
||||||
console.log(result)
|
console.log(result)
|
||||||
if (result.success == true) {
|
if (result.success == true) {
|
||||||
purchaseBtn.setAttribute("style", "background: #00DD00; width:500px; transition: 0.7s;")
|
reqBtn.setAttribute("style", "background: #00DD00; width:500px; transition: 0.7s;")
|
||||||
purchaseBtn.innerHTML = "Item Purchased, Congratulations!"
|
reqBtn.innerHTML = "Done! Go Home"
|
||||||
|
reqBtn.disabled = false
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
purchaseBtn.setAttribute("style", "background: red;")
|
reqBtn.setAttribute("style", "background: red;")
|
||||||
purchaseBtn.disabled = true
|
reqBtn.disabled = true
|
||||||
purchaseBtn.innerHTML = "ERROR"
|
reqBtn.innerHTML = "ERROR"
|
||||||
document.getElementById("api-response").innerHTML = "Error: " + result.error
|
document.getElementById("api-response").innerHTML = "Error: " + result.error
|
||||||
document.getElementById("api-response").setAttribute("style", "display: block")
|
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;");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (purchaseBtn.innerHTML == "Item Purchased, Congratulations!") {
|
|
||||||
window.location.replace("home")
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
purchaseBtn.disabled = true
|
window.location.replace('home')
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function edit_item() {
|
function edit_item() {
|
||||||
firebase.auth().currentUser.getIdToken().then(function(idToken) {
|
firebase.auth().currentUser.getIdToken().then(function(idToken) {
|
||||||
var item_id_element = document.getElementById("productID")
|
var item_id_element = document.getElementById("productID")
|
||||||
@ -204,39 +197,78 @@ function edit_item() {
|
|||||||
.catch(e => {console.log(e)})
|
.catch(e => {console.log(e)})
|
||||||
}
|
}
|
||||||
|
|
||||||
function place_item_on_sale() {
|
function toggle_sale() {
|
||||||
firebase.auth().currentUser.getIdToken().then(function(idToken) {
|
firebase.auth().currentUser.getIdToken().then(function(idToken) {
|
||||||
var item_id_element = document.getElementById("productID")
|
let item_id = document.getElementById("productID").getAttribute("product_id")
|
||||||
var item_id = item_id_element.getAttribute("product_id")
|
let item_status = document.getElementById("productID").getAttribute("product_status")
|
||||||
var place_on_sale_button = document.getElementById("sellBtn")
|
let toggle_sale_btn = document.getElementById("toggleSaleBtn")
|
||||||
const url = 'place-on-sale-api'
|
toggle_sale_btn.disabled = true
|
||||||
let data = {
|
var toggle_status = true
|
||||||
item: item_id,
|
if (item_status == 'on-sale') {toggle_status = false}
|
||||||
user: idToken
|
const url = 'toggle-sale-api'
|
||||||
}
|
let data = {prodID: item_id, authToken: idToken, targetState: toggle_status}
|
||||||
let postData = {
|
let postData = { method: 'POST', body: JSON.stringify(data),headers: {'Content-Type': 'application/json'}}
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(data),
|
|
||||||
headers: {'Content-Type': 'application/json'}
|
|
||||||
}
|
|
||||||
fetch(url, postData)
|
fetch(url, postData)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(function(result){
|
.then(function(result){
|
||||||
console.log(result)
|
console.log(result)
|
||||||
if (result.success == true) {
|
if (result.success == true) {
|
||||||
place_on_sale_button.setAttribute("style", "background: #00DD00; width:200px;")
|
toggle_sale_btn.setAttribute("style", "background: #00DD00; transition: 0.5s;")
|
||||||
place_on_sale_button.innerHTML = "Item on sale!"
|
toggle_sale_btn.innerHTML = "Done!"
|
||||||
place_on_sale_button.disabled = true
|
let sold_btn = document.getElementById("soldBtn")
|
||||||
}
|
let edit_button = document.getElementById("editBtn")
|
||||||
else {
|
sold_btn.disabled = true
|
||||||
place_on_sale_button.setAttribute("style", "background: red;")
|
edit_button.disabled = true
|
||||||
place_on_sale_button.disabled = true
|
} else {
|
||||||
place_on_sale_button.innerHTML = "ERROR"
|
toggle_sale_btn.setAttribute("style", "background: red;")
|
||||||
console.log(result.error)
|
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 {
|
||||||
|
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() {
|
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">
|
<div id="api-response" class="error-message" style="display: none;"></div>
|
||||||
<head>
|
<div id="productID" style="display: none;" product_id="<%= key%>" product_status="<%= item.status%>"></div>
|
||||||
<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 class="product-page-container">
|
<div class="product-page-container">
|
||||||
<div class="product-page-info-container">
|
<div class="product-page-info-container">
|
||||||
<div class="product-page-img"><img class="dyn-img" src="media/noimage.png" title="<%= item.img %>"></div>
|
<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>
|
<h2><%= item.name %> </h2>
|
||||||
<p>Seller: You</p>
|
<p>Seller: You</p>
|
||||||
<p>Location: <%= item.location %></p>
|
<p>Location: <%= item.location %></p>
|
||||||
<p>In stock: <%= item.stock %></p>
|
<p>Quantity: <%= item.stock %></p>
|
||||||
<p>Status: <%= item.status %></p>
|
<p>Status: <%= item.status %></p>
|
||||||
<p>Price: £<%= item.price %></p>
|
<p>Price: £<%= item.price %></p>
|
||||||
<div class="product-mgmt-buttons">
|
<div class="product-mgmt-buttons">
|
||||||
<% var editbtnStyle = ""%>
|
<% 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>
|
<div class="edit-btn" style=<%= editbtnStyle%>><button onclick={edit_item()} id="editBtn">Edit</button> </div>
|
||||||
<% var sellbtnStyle = ""%>
|
<% var sellbtnText = "Place On Sale"%>
|
||||||
<% if (item.status == "sold") {sellbtnStyle = "visibility:all;"} else {sellbtnStyle = "visibility:hidden;"}%>
|
<% var salebtnStyle = "visibility:hidden"%>
|
||||||
<div class="sell-btn" style=<%= sellbtnStyle%>><button onclick={place_item_on_sale()} id="sellBtn">Sell</button> </div>
|
<% 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 = ""%>
|
<% var shipbtnStyle = ""%>
|
||||||
<% if (item.owner == item.holder || item.status == "shipped") {shipbtnStyle = "visibility:hidden;"} else {shipbtnStyle = "visibility:all;"}%>
|
<% if (item.status == "sold") {shipbtnStyle = "visibility:hidden;"} else {shipbtnStyle = "visibility:all;"}%>
|
||||||
<div class="ship-btn" style=<%= shipbtnStyle%>><button onclick={ship_item()} id="shipBtn">Ship</button> </div>
|
<div class="ship-btn" style=<%= shipbtnStyle%>><button onclick={mark_as_sold()} id="soldBtn">Mark Sold</button> </div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="product-page-description"><p><%= item.desc %></p></div>
|
<div class="product-page-description"><p><%= item.desc %></p></div>
|
||||||
@ -92,26 +35,4 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
<%- include("partials/footer") %>
|
||||||
<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>
|
|
||||||
@ -1,64 +1,4 @@
|
|||||||
<!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" 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>
|
|
||||||
|
|
||||||
<div class="ship-adress">
|
<div class="ship-adress">
|
||||||
<button id="shippingaddressbutton" style="display: block" onclick={showShipField()}>Edit Your Shipping Address</button>
|
<button id="shippingaddressbutton" style="display: block" onclick={showShipField()}>Edit Your Shipping Address</button>
|
||||||
@ -91,26 +31,4 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
<%- include("partials/footer") %>
|
||||||
<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>
|
|
||||||
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="api-response" class="purchase-message" style="display: none;color: #DD0000"></div>
|
||||||
<div id="productID" style="display: none;" product_id="<%= key%>"></div>
|
<div id="productID" style="display: none;" product_id="<%= key%>"></div>
|
||||||
<div class="product-page-container">
|
<div class="product-page-container">
|
||||||
@ -67,9 +9,10 @@
|
|||||||
<h2><%= item.name %> </h2>
|
<h2><%= item.name %> </h2>
|
||||||
<p>Seller: <%= seller %></p>
|
<p>Seller: <%= seller %></p>
|
||||||
<p>Location: <%= item.location %></p>
|
<p>Location: <%= item.location %></p>
|
||||||
<p>In stock: <%= item.stock %></p>
|
<p>Quantity: <%= item.stock %></p>
|
||||||
<p>Price: £<%= item.price %></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>
|
</div>
|
||||||
<div class="product-page-description"><p><%= item.desc %></p></div>
|
<div class="product-page-description"><p><%= item.desc %></p></div>
|
||||||
@ -80,26 +23,4 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
<%- include("partials/footer") %>
|
||||||
<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>
|
|
||||||
@ -1,64 +1,4 @@
|
|||||||
<!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" 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>
|
|
||||||
|
|
||||||
<div class="products">
|
<div class="products">
|
||||||
<p>Search results:</p>
|
<p>Search results:</p>
|
||||||
@ -75,35 +15,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% }) %>
|
<% }) %>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="space"></div>
|
<div class="space"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
<%- include("partials/footer") %>
|
||||||
<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>
|
|
||||||
285
server.js
285
server.js
@ -9,7 +9,6 @@ let firebaseadmin = admin.initializeApp({
|
|||||||
databaseURL: "https://project-gg-3b754.firebaseio.com"
|
databaseURL: "https://project-gg-3b754.firebaseio.com"
|
||||||
})
|
})
|
||||||
let database = firebaseadmin.database()
|
let database = firebaseadmin.database()
|
||||||
let auth = admin.auth();
|
|
||||||
|
|
||||||
let app = express()
|
let app = express()
|
||||||
app.use(bodyParser.urlencoded({extended: true}))
|
app.use(bodyParser.urlencoded({extended: true}))
|
||||||
@ -27,7 +26,7 @@ let transporter = nodemailer.createTransport({
|
|||||||
user: 'noreply.projectgg@gmail.com',
|
user: 'noreply.projectgg@gmail.com',
|
||||||
pass: 'kynpef-5paqha-xaVxip'
|
pass: 'kynpef-5paqha-xaVxip'
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
|
|
||||||
app.get("/", function(request, responce) {
|
app.get("/", function(request, responce) {
|
||||||
@ -111,31 +110,16 @@ app.get('/my-products', function(request, responce){
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dbRef.orderByChild('owner').equalTo(uid).once('value', function(snapshot){
|
dbRef.orderByChild('owner').equalTo(uid).once('value', function(snapshot){
|
||||||
var data = {
|
var data = {'x': {holder: '',id: 999,img: '',location: '',name: 'No products listed 😢',owner: '',price: '',stock: ''}}
|
||||||
'x': {
|
|
||||||
desc: '',
|
|
||||||
holder: '',
|
|
||||||
id: 999,
|
|
||||||
img: '',
|
|
||||||
location: '',
|
|
||||||
name: 'No products listed 😢',
|
|
||||||
owner: '',
|
|
||||||
price: '',
|
|
||||||
public: '',
|
|
||||||
stock: ''
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if (snapshot.val()) {data = snapshot.val()}
|
if (snapshot.val()) {data = snapshot.val()}
|
||||||
responce.render('my-products.ejs', {products: data})
|
responce.render('my-products.ejs', {products: data})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
responce.send("<h1>Bad Auth Token</h1><a href='home'>Home</a>")
|
responce.send("<h1>Bad Auth Token</h1><a href='home'>Home</a>")
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
responce.send("<h1>No Auth Token Provided</h1><a href='home'>Home</a>")
|
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) {
|
app.post('/request-api', async function(request, responce){
|
||||||
admin.auth().verifyIdToken(request.body.user)
|
if (request.body.prodID && request.body.authToken && request.body.usrMsg) {
|
||||||
.then(function(decodedToken) {
|
let bMsg = request.body.usrMsg
|
||||||
let uid = decodedToken.uid;
|
let uid = await authCheck(request.body.authToken)
|
||||||
let product = request.body.item
|
if (uid) {
|
||||||
var productRef = database.ref("/products/"+product)
|
let pid = request.body.prodID
|
||||||
productRef.once('value', function(snapshot) {
|
let productRef = database.ref("/products/"+ pid)
|
||||||
var exists = (snapshot.val() !== null)
|
var snapshot = await productRef.once('value')
|
||||||
if (exists){
|
if (snapshot.exists()) {
|
||||||
var productRef = database.ref("/products/"+product)
|
let product = snapshot.val()
|
||||||
productRef.update({owner:uid, status:"sold"})
|
let productName = product.name
|
||||||
.then(function(){
|
let productSeller = product.owner
|
||||||
responce.send({success:true, error:null})
|
let usersRef = database.ref("/users")
|
||||||
})
|
snapshot = await usersRef.orderByChild("UID").equalTo(productSeller).once('value')
|
||||||
.catch(e => {console.log(e)})
|
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})
|
||||||
|
} else {
|
||||||
|
responce.send({success:false, error:'Something very bad has happened..... Item buyer apparantly doesn\'t exist in the database'})
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
responce.send({success:false, error:'Item does not exist'})
|
responce.send({success:false, error:'Something very bad has happened..... Item owner apparantly doesn\'t exist in the database'})
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
.catch(e => {console.log(e)})
|
responce.send({success:false, error:'Item does not exist'})
|
||||||
})
|
}
|
||||||
.catch(function(err) {
|
} else {
|
||||||
responce.send({success:false, error:'invalid auth token'})
|
responce.send({success:false, error:'invalid auth token'})
|
||||||
});
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
responce.send({success:false, error:'invalid data'})
|
responce.send({success:false, error:'invalid data'})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post('/place-on-sale-api', function(request, responce){
|
app.post('/toggle-sale-api', async function(request, responce){
|
||||||
if (request.body.item && request.body.user) {
|
if (request.body.prodID && request.body.authToken && (request.body.targetState != null)) {
|
||||||
admin.auth().verifyIdToken(request.body.user)
|
let uid = await authCheck(request.body.authToken)
|
||||||
.then(function(decodedToken) {
|
if (uid) {
|
||||||
let uid = decodedToken.uid;
|
let pid = request.body.prodID
|
||||||
let productID = request.body.item
|
let targetState = request.body.targetState
|
||||||
var productRef = database.ref("/products/"+productID)
|
let productRef = database.ref("/products/"+ pid)
|
||||||
|
var snapshot = await productRef.once('value')
|
||||||
productRef.once('value',function(snapshot){
|
if (snapshot.exists()) {
|
||||||
let item = snapshot.val()
|
let product = snapshot.val()
|
||||||
if (item){
|
if (product.owner == uid && product.status != "sold") {
|
||||||
let itemOwner = item.owner
|
let status = "x"
|
||||||
if (uid == itemOwner){
|
if (targetState == true) {
|
||||||
productRef.update({status:"on-sale"})
|
status = "on-sale"
|
||||||
.then(function(){
|
} else {
|
||||||
responce.send({success:true, error:null})
|
status = "off-sale"
|
||||||
})
|
|
||||||
.catch(e => {console.log(e)})
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
responce.send({success:false, error:'You do not own this item'})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
productRef.update({status:status})
|
||||||
responce.send({success:false, error:'Item does not exist'})
|
.then(responce.send({success:true, error:null}))
|
||||||
}
|
.catch(e => {responce.send({success:false, error:e})})
|
||||||
})
|
} else {
|
||||||
.catch(e=>{
|
responce.send({success:false, error:'Unauthorized'})
|
||||||
console.log(e)
|
}
|
||||||
responce.send({success:false, error:'other, ' + e})
|
} else {
|
||||||
})
|
responce.send({success:false, error:'Item does not exist'})
|
||||||
})
|
}
|
||||||
.catch(function(error) {
|
} else {
|
||||||
responce.send({success:false, error:'invalid auth token'})
|
responce.send({success:false, error:'invalid auth token'})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
responce.send({success:false, error:'invalid data'})
|
responce.send({success:false, error:'invalid data'})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post('/ship-api', function(request, responce){
|
app.post('/sold-api', async function(request, responce){
|
||||||
if (request.body.item && request.body.user) {
|
if (request.body.prodID && request.body.authToken) {
|
||||||
admin.auth().verifyIdToken(request.body.user)
|
let uid = await authCheck(request.body.authToken)
|
||||||
.then(async function(decodedToken) {
|
if (uid) {
|
||||||
let uid = decodedToken.uid;
|
let pid = request.body.prodID
|
||||||
let pid = request.body.item
|
let productRef = database.ref("/products/"+ pid)
|
||||||
|
var snapshot = await productRef.once('value')
|
||||||
if (await verifyExists(pid)){
|
if (snapshot.exists()) {
|
||||||
if (await verifyOwner(uid, pid)) {
|
let product = snapshot.val()
|
||||||
let productRef = database.ref("/products/"+pid)
|
if (product.owner == uid) {
|
||||||
productRef.update({status:"shipped"})
|
productRef.update({status:"sold"})
|
||||||
.then(function(){
|
.then(responce.send({success:true, error:null}))
|
||||||
processItemShipEmail(pid, uid)
|
.catch(e => {responce.send({success:false, error:e})})
|
||||||
responce.send({success:true, error:null})
|
} else {
|
||||||
})
|
responce.send({success:false, error:'Unauthorized'})
|
||||||
.catch(e => {console.log(e)})
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
responce.send({success:false, error:'You do not own this item'})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
responce.send({success:false, error:'Item does not exist'})
|
responce.send({success:false, error:'Item does not exist'})
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
.catch(function(error) {
|
responce.send({success:false, error:'invalid auth token'})
|
||||||
responce.send({success:false, error:'invalid auth token'})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
responce.send({success:false, error:'invalid data'})
|
responce.send({success:false, error:'invalid data'})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -363,7 +350,7 @@ app.post('/login-user-api', function(request, responce){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
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){
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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
|
||||||
app.post('/demo-api', function(request, responce){
|
return uid
|
||||||
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"})
|
|
||||||
}
|
|
||||||
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 checkNewUser(user){
|
async function checkNewUser(user){
|
||||||
let snapshot = await checkUserExists(user.uid)
|
let snapshot = await checkUserExists(user.uid)
|
||||||
@ -572,47 +539,25 @@ async function verifyOwner(uid, pid) {
|
|||||||
|
|
||||||
function sendEmail(address, content){
|
function sendEmail(address, content){
|
||||||
var mailOptions = {
|
var mailOptions = {
|
||||||
from: 'noreply.projectgg@gmail.com',
|
from: 'Project GG',
|
||||||
to: address,
|
to: address,
|
||||||
subject: 'Your Item has been requested',
|
subject: 'Someone\'s interested!',
|
||||||
text: content
|
text: content
|
||||||
}
|
}
|
||||||
transporter.sendMail(mailOptions, function(error, info){
|
transporter.sendMail(mailOptions, function(error, info){
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log(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){
|
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
|
var port = 5000
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user