Update
This commit is contained in:
parent
faa4ab30be
commit
5a806b08c2
@ -23,6 +23,14 @@ app.use(express.static('views'))
|
|||||||
app.set('view engine', 'ejs')
|
app.set('view engine', 'ejs')
|
||||||
app.set('views', __dirname + '/views')
|
app.set('views', __dirname + '/views')
|
||||||
|
|
||||||
|
let nodemailer = require('nodemailer')
|
||||||
|
let transporter = nodemailer.createTransport({
|
||||||
|
service: 'gmail',
|
||||||
|
auth: {
|
||||||
|
user: 'noreply.projectgg@gmail.com',
|
||||||
|
pass: 'kynpef-5paqha-xaVxip'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
app.get("/", function(request, responce) {
|
app.get("/", function(request, responce) {
|
||||||
@ -205,6 +213,7 @@ app.post('/ship-api', function(request, responce){
|
|||||||
var productRef = database.ref("/products/"+product)
|
var productRef = database.ref("/products/"+product)
|
||||||
productRef.update({status:"shipped"})
|
productRef.update({status:"shipped"})
|
||||||
.then(function(){
|
.then(function(){
|
||||||
|
processItemShipEmail(product, uid)
|
||||||
responce.send({success:true, error:null})
|
responce.send({success:true, error:null})
|
||||||
})
|
})
|
||||||
.catch(e => {console.log(e)})
|
.catch(e => {console.log(e)})
|
||||||
@ -218,6 +227,47 @@ app.post('/ship-api', function(request, responce){
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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',
|
||||||
|
to: address,
|
||||||
|
subject: 'Your Item has been requested',
|
||||||
|
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){
|
app.get('*', function(request, responce){
|
||||||
responce.render('404.ejs')
|
responce.render('404.ejs')
|
||||||
})
|
})
|
||||||
|
|||||||
@ -615,3 +615,45 @@ footer a {
|
|||||||
.e404 svg {
|
.e404 svg {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ship-adress {
|
||||||
|
height: 50px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ship-adress button {
|
||||||
|
position: relative;
|
||||||
|
border: 0;
|
||||||
|
height: 40px;
|
||||||
|
width: 350px;
|
||||||
|
background-color: salmon;
|
||||||
|
font-family: osl;
|
||||||
|
font-size: 20px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, 0);
|
||||||
|
transition: 0.3s;
|
||||||
|
color: white;
|
||||||
|
box-shadow: 0px 2px 3px #A5A5A5;
|
||||||
|
}
|
||||||
|
.ship-adress button:hover {
|
||||||
|
background-color: pink;
|
||||||
|
color: black;
|
||||||
|
transition: 0.1s;
|
||||||
|
}
|
||||||
|
.ship-adress button:active {
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
.ship-adress input {
|
||||||
|
position: relative;
|
||||||
|
border: 0;
|
||||||
|
height: 40px;
|
||||||
|
width: 600px;
|
||||||
|
background-color: #EEEEEE;
|
||||||
|
font-family: osl;
|
||||||
|
font-size: 20px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, 0);
|
||||||
|
color: black;
|
||||||
|
box-shadow: 0px 2px 3px #A5A5A5;
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
@ -1,9 +1,20 @@
|
|||||||
function checkAuth(){
|
function checkAuth(){
|
||||||
firebase.auth().onAuthStateChanged(function(user){
|
firebase.auth().onAuthStateChanged(function(user){
|
||||||
if (user) {
|
if (user) {
|
||||||
|
document.getElementById('uname-dom').innerHTML = "Loading..."
|
||||||
|
let database = firebase.database()
|
||||||
|
var uid = user.uid
|
||||||
|
var dbRef = database.ref("/users")
|
||||||
|
dbRef.orderByChild("UID").equalTo(uid).once('value', function(snapshot){
|
||||||
|
vals = snapshot.val()
|
||||||
|
var keys = Object.keys(vals)
|
||||||
|
uData = vals[keys[0]]
|
||||||
|
document.getElementById('uname-dom').innerHTML = "Hello, " + uData.fName
|
||||||
|
})
|
||||||
|
|
||||||
document.getElementById('uname-field').setAttribute("style", "display: block;")
|
document.getElementById('uname-field').setAttribute("style", "display: block;")
|
||||||
document.getElementById('login-field').setAttribute("style", "display: none;")
|
document.getElementById('login-field').setAttribute("style", "display: none;")
|
||||||
document.getElementById('uname-dom').innerHTML = "Hello, " + user.displayName
|
|
||||||
document.getElementById('uname-field').setAttribute("style", "display: block;")
|
document.getElementById('uname-field').setAttribute("style", "display: block;")
|
||||||
document.getElementById('login-field').setAttribute("style", "display: none;")
|
document.getElementById('login-field').setAttribute("style", "display: none;")
|
||||||
try {document.getElementById('uAuthMsg').setAttribute("style", "display: none;")}
|
try {document.getElementById('uAuthMsg').setAttribute("style", "display: none;")}
|
||||||
@ -23,14 +34,14 @@ function checkAuth(){
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onload = function(){
|
|
||||||
checkAuth()
|
checkAuth()
|
||||||
}
|
|
||||||
|
|
||||||
function signinwithgoogle(){
|
function signinwithgoogle(){
|
||||||
var googleAuthProvider = new firebase.auth.GoogleAuthProvider()
|
var googleAuthProvider = new firebase.auth.GoogleAuthProvider()
|
||||||
firebase.auth().signInWithPopup(googleAuthProvider)
|
firebase.auth().signInWithPopup(googleAuthProvider)
|
||||||
.then(function(data){
|
.then(function(data){
|
||||||
|
checkNewUser(data)
|
||||||
console.log('User signed in...')
|
console.log('User signed in...')
|
||||||
})
|
})
|
||||||
.catch(function(error){
|
.catch(function(error){
|
||||||
@ -38,10 +49,38 @@ function signinwithgoogle(){
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkNewUser(credential){
|
||||||
|
let database = firebase.database()
|
||||||
|
var uid = credential.user.uid
|
||||||
|
var dbRef = database.ref("/users")
|
||||||
|
dbRef.orderByChild("UID").equalTo(uid).once('value', function(snapshot){
|
||||||
|
if (snapshot.exists()){
|
||||||
|
let uData = snapshot.val()
|
||||||
|
console.log(uData)
|
||||||
|
console.log("Logged in User: " + uData.fName + " " + uData.lName)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("Creating new user")
|
||||||
|
let uData = {
|
||||||
|
fName:credential.user.displayName,
|
||||||
|
lName:"",
|
||||||
|
UID:credential.user.uid,
|
||||||
|
email:credential.user.email,
|
||||||
|
address:""
|
||||||
|
}
|
||||||
|
let itemRef = database.ref('/users')
|
||||||
|
itemRef.push(uData)
|
||||||
|
.then(function(){console.log("Added "+credential.displayName+" to user database")})
|
||||||
|
.catch(function(error){console.log(error)})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function signinwithfb(){
|
function signinwithfb(){
|
||||||
var fbAuthProvider = new firebase.auth.FacebookAuthProvider()
|
var fbAuthProvider = new firebase.auth.FacebookAuthProvider()
|
||||||
firebase.auth().signInWithPopup(fbAuthProvider)
|
firebase.auth().signInWithPopup(fbAuthProvider)
|
||||||
.then(function(data){
|
.then(function(data){
|
||||||
|
checkNewUser(data)
|
||||||
console.log('User signed in...')
|
console.log('User signed in...')
|
||||||
})
|
})
|
||||||
.catch(function(error){
|
.catch(function(error){
|
||||||
@ -59,7 +98,8 @@ function signinwithemail(){
|
|||||||
|
|
||||||
auth.signInWithEmailAndPassword(email, pass)
|
auth.signInWithEmailAndPassword(email, pass)
|
||||||
.catch(e => console.log(e.message))
|
.catch(e => console.log(e.message))
|
||||||
.then(function(){
|
.then(function(data){
|
||||||
|
checkNewUser(data)
|
||||||
txtPassword.value = ''
|
txtPassword.value = ''
|
||||||
txtEmail.value = ''
|
txtEmail.value = ''
|
||||||
})
|
})
|
||||||
|
|||||||
@ -283,3 +283,30 @@ function my_products() {
|
|||||||
})
|
})
|
||||||
.catch(e => {console.log(e)})
|
.catch(e => {console.log(e)})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showShipField(){
|
||||||
|
document.getElementById('shippingaddressbutton').setAttribute("style", "display:none;")
|
||||||
|
document.getElementById('shippingaddressinput').setAttribute("style", "display:block;")
|
||||||
|
}
|
||||||
|
|
||||||
|
function addShippingAddress(){
|
||||||
|
let database = firebase.database()
|
||||||
|
var usersRef = database.ref("/users")
|
||||||
|
usersRef.orderByChild("UID").equalTo(firebase.auth().currentUser.uid).once('value', function(snapshot){
|
||||||
|
vals = snapshot.val()
|
||||||
|
var keys = Object.keys(vals)
|
||||||
|
userKey = keys[0]
|
||||||
|
userRef = database.ref("/users/"+userKey)
|
||||||
|
userRef.update({address:document.getElementById('shippingaddressinput').value})
|
||||||
|
.then(document.getElementById("shippingaddressinput").value = "Success!")
|
||||||
|
.catch(e => {console.log(e)})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var addressField = document.getElementById("shippingaddressinput")
|
||||||
|
addressField.addEventListener("keyup", function(event) {
|
||||||
|
if (event.keyCode === 13) {
|
||||||
|
event.preventDefault()
|
||||||
|
addShippingAddress()
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -60,6 +60,13 @@
|
|||||||
|
|
||||||
<div class="space"></div>
|
<div class="space"></div>
|
||||||
|
|
||||||
|
<div class="ship-adress">
|
||||||
|
<button id="shippingaddressbutton" style="display: block" onclick={showShipField()}>Edit Your Shipping Address</button>
|
||||||
|
<input style="display: none" type="text" placeholder="Type address, enter to submit" id="shippingaddressinput">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space"></div>
|
||||||
|
|
||||||
<div class="products">
|
<div class="products">
|
||||||
<p>My products:</p>
|
<p>My products:</p>
|
||||||
<div class="my-products-container">
|
<div class="my-products-container">
|
||||||
|
|||||||
31
server.js
31
server.js
@ -219,7 +219,7 @@ app.post('/ship-api', function(request, responce){
|
|||||||
var productRef = database.ref("/products/"+product)
|
var productRef = database.ref("/products/"+product)
|
||||||
productRef.update({status:"shipped"})
|
productRef.update({status:"shipped"})
|
||||||
.then(function(){
|
.then(function(){
|
||||||
sendEmail("maxdebaoli@gmail.com", "Please ship item "+product)
|
processItemShipEmail(product, uid)
|
||||||
responce.send({success:true, error:null})
|
responce.send({success:true, error:null})
|
||||||
})
|
})
|
||||||
.catch(e => {console.log(e)})
|
.catch(e => {console.log(e)})
|
||||||
@ -233,6 +233,31 @@ app.post('/ship-api', function(request, responce){
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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: 'noreply.projectgg@gmail.com',
|
||||||
@ -246,11 +271,9 @@ function sendEmail(address, content){
|
|||||||
} else {
|
} else {
|
||||||
console.log('Email sent: ' + info.response);
|
console.log('Email sent: ' + info.response);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
app.get('*', function(request, responce){
|
app.get('*', function(request, responce){
|
||||||
responce.render('404.ejs')
|
responce.render('404.ejs')
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user