Invite bug fix
This commit is contained in:
@ -54,12 +54,24 @@ async function getShoppinglistsAdmin(username) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SELECT own shopping lists
|
||||||
|
async function getShoppinglistsByLink(link) {
|
||||||
|
try {
|
||||||
|
console.log("PPPPP LIIINK:", link)
|
||||||
|
let result = await query('SELECT row_to_json("Shoppinglist") AS obj FROM "Shoppinglist" WHERE invitelink = $1', [link]);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//SELECT shared shopping lists
|
//SELECT shared shopping lists
|
||||||
|
|
||||||
async function getShoppinglistsShared(username) {
|
async function getShoppinglistsShared(username) {
|
||||||
try {
|
try {
|
||||||
let result = await query('SELECT row_to_json("Shoppinglist") AS obj FROM "Shoppinglist" JOIN "Shoppinglist_member" USING (sl_id) WHERE \
|
let result = await query('SELECT row_to_json("Shoppinglist") AS obj FROM "Shoppinglist" JOIN "Shoppinglist_member" USING (sl_id) WHERE username = $1;', [username]);
|
||||||
username = $1', [username]);
|
|
||||||
console.log(result);
|
console.log(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -530,5 +542,5 @@ function probability(cur_item, data) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist, deleteShoppinglist, addGroup,
|
getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist, deleteShoppinglist, addGroup,
|
||||||
addItem, verifyInvite, createInvite, editShoppinglist, editGroup, editItem, deleteGroup, deleteItem, manInvite, updateUser,
|
addItem, verifyInvite, createInvite, editShoppinglist, editGroup, editItem, deleteGroup, deleteItem, manInvite, updateUser,
|
||||||
moveDoneItems, getDonePurchases
|
moveDoneItems, getDonePurchases, getShoppinglistsByLink
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,12 @@ var config = {
|
|||||||
var segment_array = segment_str.split( '/' );
|
var segment_array = segment_str.split( '/' );
|
||||||
var last_segment = segment_array.pop();
|
var last_segment = segment_array.pop();
|
||||||
|
|
||||||
verifyInvite(last_segment);
|
//verifyInvite(last_segment);
|
||||||
|
getList(last_segment);
|
||||||
|
|
||||||
|
|
||||||
function verifyInvite(link) {
|
function verifyInvite(link) {
|
||||||
alert("Ore Link", link)
|
//alert("Ore Link", link)
|
||||||
firebase.auth().onAuthStateChanged(function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) {
|
firebase.auth().onAuthStateChanged(function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
@ -33,7 +34,31 @@ var config = {
|
|||||||
link: link
|
link: link
|
||||||
},
|
},
|
||||||
success(){
|
success(){
|
||||||
window.location.href = "/dash/" + idtoken
|
// window.location.href = "/dash/" + idtoken
|
||||||
|
alert("Success");
|
||||||
|
},
|
||||||
|
error(err){
|
||||||
|
console.error("Error: " + err);
|
||||||
|
alert("Error");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).catch((error) => console.error("Get id token client error: ", error));}else{console.log("Check Auth error", user)}});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getList(link) {
|
||||||
|
firebase.auth().onAuthStateChanged(function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) {
|
||||||
|
$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
url: "/shoppinglistsbylink?link=" + link,
|
||||||
|
data: {
|
||||||
|
idtoken: idtoken
|
||||||
|
},
|
||||||
|
success(data){
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
$(".s_name").append(data.find(function(obj) {return obj.invitelink == link}).name);
|
||||||
|
$(".s_desc").append(data.find(function(obj) {return obj.invitelink == link}).description);
|
||||||
|
$(".s_link").append(data.find(function(obj) {return obj.invitelink == link}).invitelink);
|
||||||
},
|
},
|
||||||
error(err){
|
error(err){
|
||||||
console.error("Error: " + err);
|
console.error("Error: " + err);
|
||||||
@ -42,6 +67,13 @@ var config = {
|
|||||||
}).catch((error) => console.error("Get id token client error: ", error));}else{console.log("Check Auth error", user)}});
|
}).catch((error) => console.error("Get id token client error: ", error));}else{console.log("Check Auth error", user)}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$(".btn_verify").click(function() {
|
||||||
|
var segment_str = window.location.pathname;
|
||||||
|
var segment_array = segment_str.split( '/' );
|
||||||
|
var last_segment = segment_array.pop();
|
||||||
|
verifyInvite(last_segment);
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -148,6 +148,30 @@ router.get("/sharedshoppinglists", async function(req, res, next) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
//GET ALL SHOPPINGLISTS
|
||||||
|
|
||||||
|
router.get("/shoppinglistsbylink", async function(req, res, next) {
|
||||||
|
var token = req.query.idtoken;
|
||||||
|
firebaseAdmin.auth().verifyIdToken(token)
|
||||||
|
.then(async function(decodedToken) {
|
||||||
|
uid = decodedToken.uid;
|
||||||
|
console.log("uid", uid)
|
||||||
|
try {
|
||||||
|
//Get user id: req.session.passport.user.profile.id
|
||||||
|
res.status(200).send(await postgres.getShoppinglistsByLink(req.query.link));
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(err) {
|
||||||
|
res.status(400).send(await err);
|
||||||
|
}
|
||||||
|
|
||||||
|
}).catch(function(error) {
|
||||||
|
console.log(error)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//POST new shoppinglist
|
//POST new shoppinglist
|
||||||
@ -197,6 +221,8 @@ router.get("/shoppinglist_json/:sl_id", async (req, res) => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
postgres.displayShoppinglist("4tezJYMK");
|
postgres.displayShoppinglist("4tezJYMK");
|
||||||
|
|
||||||
//DELETE Shoppinglist
|
//DELETE Shoppinglist
|
||||||
|
@ -12,6 +12,10 @@
|
|||||||
<script src="/invite/inv.js"></script>
|
<script src="/invite/inv.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<p class="s_name">Name: </p>
|
||||||
|
<p class="s_desc">Description: </p>
|
||||||
|
<p class="s_link">Invite Link: </p>
|
||||||
|
|
||||||
|
<button class="btn_verify">Join to this Shoppinglist</button>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Reference in New Issue
Block a user