Email Login
This commit is contained in:
@ -6,128 +6,144 @@ var config = {
|
||||
projectId: "test-667ca",
|
||||
storageBucket: "test-667ca.appspot.com",
|
||||
messagingSenderId: "221332577314"
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
firebase.initializeApp(config);
|
||||
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
firebase.auth().onAuthStateChanged(async function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) {
|
||||
console.log("/shoppinglistx idtoken:", idtoken);
|
||||
var url = "/dash/" + idtoken
|
||||
console.log("URL: ", url)
|
||||
$('#dashurl').attr("href", url);
|
||||
$(document).ready(function () {
|
||||
firebase.auth().onAuthStateChanged(async function (user) {
|
||||
if (user) {
|
||||
firebase.auth().currentUser.getIdToken( /* forceRefresh */ true).then(function (idtoken) {
|
||||
console.log("/shoppinglistx idtoken:", idtoken);
|
||||
var url = "/dash/" + idtoken
|
||||
console.log("URL: ", url)
|
||||
$('#dashurl').attr("href", url);
|
||||
|
||||
}).catch((error) => console.error("/shoppinglist Get id token client error: ", error));
|
||||
} else {
|
||||
console.log("Check Auth error", user)
|
||||
}
|
||||
});
|
||||
|
||||
}).catch((error) => console.error("/shoppinglist Get id token client error: ", error));}else{console.log("Check Auth error", user)}});
|
||||
|
||||
eigeneEinkaufslisten();
|
||||
geteilteEinkaufslisten();
|
||||
|
||||
$(".detailcardausgabe").hide();
|
||||
|
||||
$(".logout").click(function(){
|
||||
$(".logout").click(function () {
|
||||
console.log("click logout")
|
||||
firebase.auth().signOut().then(function() {
|
||||
firebase.auth().signOut().then(function () {
|
||||
document.location.replace('/');
|
||||
}).catch(function(error) {
|
||||
}).catch(function (error) {
|
||||
console.error("Logout Error: ", error)
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('.add').click(function(){
|
||||
$('.add').click(function () {
|
||||
console.log("click add");
|
||||
// let name = $("#einkaufslistenname").val();
|
||||
|
||||
firebase.auth().onAuthStateChanged(async function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) {
|
||||
console.log("/shoppinglistx idtoken:", idtoken);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/shoppinglist",
|
||||
data: {
|
||||
name: $("#einkaufslistenname").val(),
|
||||
description: $("#einkaufslistenbeschreibung").val(),
|
||||
color: $( "input:checked" ).val(),
|
||||
idtoken: idtoken
|
||||
},
|
||||
success(res){
|
||||
console.log("add funktioniert");
|
||||
$(".listen-ausgabe").html("");
|
||||
eigeneEinkaufslisten();
|
||||
geteilteEinkaufslisten();
|
||||
$("#EigeneListeAdd").modal("hide");
|
||||
},
|
||||
error(err){
|
||||
console.log("/shoppinglist error", err);
|
||||
}
|
||||
});
|
||||
}).catch((error) => console.error("/shoppinglist Get id token client error: ", error));}else{console.log("Check Auth error", user)}});
|
||||
firebase.auth().onAuthStateChanged(async function (user) {
|
||||
if (user) {
|
||||
firebase.auth().currentUser.getIdToken( /* forceRefresh */ true).then(function (idtoken) {
|
||||
console.log("/shoppinglistx idtoken:", idtoken);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/shoppinglist",
|
||||
data: {
|
||||
name: $("#einkaufslistenname").val(),
|
||||
description: $("#einkaufslistenbeschreibung").val(),
|
||||
color: $("input:checked").val(),
|
||||
idtoken: idtoken
|
||||
},
|
||||
success(res) {
|
||||
console.log("add funktioniert");
|
||||
$(".listen-ausgabe").html("");
|
||||
eigeneEinkaufslisten();
|
||||
geteilteEinkaufslisten();
|
||||
$("#EigeneListeAdd").modal("hide");
|
||||
},
|
||||
error(err) {
|
||||
console.log("/shoppinglist error", err);
|
||||
}
|
||||
});
|
||||
}).catch((error) => console.error("/shoppinglist Get id token client error: ", error));
|
||||
} else {
|
||||
console.log("Check Auth error", user)
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$(".gruppenadd").click(function(){
|
||||
$(".gruppenadd").click(function () {
|
||||
|
||||
// let name = $("#groupname").val();
|
||||
// let color = $("#groupfarbe").val();
|
||||
$("#ListenDetailAdd").modal("hide");
|
||||
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/group",
|
||||
data: {
|
||||
sl_id: globaleAddZwischenID,
|
||||
name: $("#groupname").val(),
|
||||
color: $( "input:checked" ).val()
|
||||
color: $("input:checked").val()
|
||||
},
|
||||
success(res){
|
||||
success(res) {
|
||||
console.log("groupadd funktioniert");
|
||||
|
||||
|
||||
},
|
||||
error(err){
|
||||
error(err) {
|
||||
console.log("error");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(".sl_add").click(function(){
|
||||
$(".sl_add").click(function () {
|
||||
$('#EigeneListeAdd').modal('show');
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
var globaleAddZwischenID = "";
|
||||
// var globaleGetZwischenID = "";
|
||||
|
||||
function eigeneEinkaufslisten(){
|
||||
firebase.auth().onAuthStateChanged(async function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) {
|
||||
console.log("/myshoppinglists idtoke: ", idtoken);
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/myshoppinglists",
|
||||
data:{
|
||||
idtoken: idtoken
|
||||
},
|
||||
success(res){
|
||||
firebase.auth().onAuthStateChanged(async function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) {
|
||||
console.log("/userinfo_json idtoken: ",idtoken)
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/userinfo_json",
|
||||
data: {
|
||||
idtoken: idtoken
|
||||
},
|
||||
success(data){
|
||||
const userinfo = data.name;
|
||||
const picture = data.picture;
|
||||
console.log(data)
|
||||
for(let i = 0; i < res.length; i++){
|
||||
const el = res[i];
|
||||
|
||||
$(".listen-ausgabe").append(`<div class="col-md-12 karten">
|
||||
function eigeneEinkaufslisten() {
|
||||
firebase.auth().onAuthStateChanged(async function (user) {
|
||||
if (user) {
|
||||
firebase.auth().currentUser.getIdToken( /* forceRefresh */ true).then(function (idtoken) {
|
||||
console.log("/myshoppinglists idtoke: ", idtoken);
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/myshoppinglists",
|
||||
data: {
|
||||
idtoken: idtoken
|
||||
},
|
||||
success(res) {
|
||||
firebase.auth().onAuthStateChanged(async function (user) {
|
||||
if (user) {
|
||||
firebase.auth().currentUser.getIdToken( /* forceRefresh */ true).then(function (idtoken) {
|
||||
console.log("/userinfo_json idtoken: ", idtoken)
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/userinfo_json",
|
||||
data: {
|
||||
idtoken: idtoken
|
||||
},
|
||||
success(data) {
|
||||
const userinfo = data.name;
|
||||
const picture = data.picture;
|
||||
console.log(data)
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
const el = res[i];
|
||||
|
||||
$(".listen-ausgabe").append(`<div class="col-md-12 karten">
|
||||
<div class="card border-light mb-3 shadow-sm" style="max-width: 18rem;" id="${el.sl_id}">
|
||||
<div class="card-header" style="background-color: #${el.color};">
|
||||
<span>
|
||||
@ -142,49 +158,62 @@ function eigeneEinkaufslisten(){
|
||||
<h5 class="card-title">${el.name}</h5>
|
||||
<p class="card-text">${el.description}</p>
|
||||
</div>
|
||||
</div></div>`
|
||||
)
|
||||
</div></div>`)
|
||||
}
|
||||
console.log("Eigene Einkaufslisten");
|
||||
loeschen();
|
||||
lala();
|
||||
Detail();
|
||||
// groupHinzufügen()
|
||||
},
|
||||
error(err) {
|
||||
console.error("userinfo_json error: ", err)
|
||||
}
|
||||
})
|
||||
}).catch((error) => console.error("Get id token client error: ", error));
|
||||
} else {
|
||||
console.log("Check Auth error", user)
|
||||
}
|
||||
console.log("Eigene Einkaufslisten");
|
||||
loeschen();
|
||||
lala();
|
||||
Detail();
|
||||
// groupHinzufügen()
|
||||
},
|
||||
error(err){
|
||||
console.error("userinfo_json error: ", err)
|
||||
}
|
||||
})
|
||||
}).catch((error) => console.error("Get id token client error: ", error));}else{console.log("Check Auth error", user)}});
|
||||
},
|
||||
error(err){
|
||||
console.error("/myshoppinglists ajax error: ", err);
|
||||
}
|
||||
});
|
||||
}).catch((error) => console.error("Get id token client error: ", error));}else{console.log("Check Auth error", user)}});
|
||||
});
|
||||
},
|
||||
error(err) {
|
||||
console.error("/myshoppinglists ajax error: ", err);
|
||||
}
|
||||
});
|
||||
}).catch((error) => console.error("Get id token client error: ", error));
|
||||
} else {
|
||||
console.log("Check Auth error", user)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function geteilteEinkaufslisten(){
|
||||
firebase.auth().onAuthStateChanged(async function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) {
|
||||
console.log("/sharedshoppinglists idtoke: ", idtoken)
|
||||
$.ajax({
|
||||
data: "GET",
|
||||
url: "/sharedshoppinglists",
|
||||
data: {
|
||||
idtoken: idtoken
|
||||
},
|
||||
success(res){
|
||||
console.log("Geteilte Einkaufslisten");
|
||||
},
|
||||
error(err){
|
||||
console.error("/sharedshoppinglists error:", err);
|
||||
}
|
||||
});
|
||||
}).catch((error) => console.error("Get id token client error: ", error));}else{console.log("Check Auth error", user)}});
|
||||
function geteilteEinkaufslisten() {
|
||||
firebase.auth().onAuthStateChanged(async function (user) {
|
||||
if (user) {
|
||||
firebase.auth().currentUser.getIdToken( /* forceRefresh */ true).then(function (idtoken) {
|
||||
console.log("/sharedshoppinglists idtoke: ", idtoken)
|
||||
$.ajax({
|
||||
data: "GET",
|
||||
url: "/sharedshoppinglists",
|
||||
data: {
|
||||
idtoken: idtoken
|
||||
},
|
||||
success(res) {
|
||||
console.log("Geteilte Einkaufslisten");
|
||||
},
|
||||
error(err) {
|
||||
console.error("/sharedshoppinglists error:", err);
|
||||
}
|
||||
});
|
||||
}).catch((error) => console.error("Get id token client error: ", error));
|
||||
} else {
|
||||
console.log("Check Auth error", user)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function loeschen(){
|
||||
$(".trash").click(function(){
|
||||
function loeschen() {
|
||||
$(".trash").click(function () {
|
||||
|
||||
let card = $(this).closest(".card");
|
||||
let id = card.attr("id");
|
||||
@ -195,12 +224,13 @@ function loeschen(){
|
||||
type: "DELETE",
|
||||
url: "/shoppinglist",
|
||||
data: {
|
||||
sl_id: id},
|
||||
success(res){
|
||||
sl_id: id
|
||||
},
|
||||
success(res) {
|
||||
console.log("card gelöscht");
|
||||
card.remove();
|
||||
},
|
||||
error(err){
|
||||
error(err) {
|
||||
console.log("error");
|
||||
}
|
||||
});
|
||||
@ -208,8 +238,8 @@ function loeschen(){
|
||||
});
|
||||
};
|
||||
|
||||
function lala(){
|
||||
$(".groupadd").click(function(){
|
||||
function lala() {
|
||||
$(".groupadd").click(function () {
|
||||
let card = $(this).closest(".card");
|
||||
let id = card.attr("id");
|
||||
globaleAddZwischenID = id;
|
||||
@ -217,51 +247,53 @@ function lala(){
|
||||
});
|
||||
}
|
||||
|
||||
function Detail(){
|
||||
$(".edit").click(function(){
|
||||
function Detail() {
|
||||
$(".edit").click(function () {
|
||||
|
||||
$(".cardausgabe").hide();
|
||||
$(".detailcardausgabe").show();
|
||||
|
||||
let card = $(this).closest(".card");
|
||||
let id = card.attr("id");
|
||||
firebase.auth().onAuthStateChanged(async function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/shoppinglist_json/" + id,
|
||||
data: {
|
||||
idtoken: idtoken
|
||||
},
|
||||
success(res){
|
||||
console.log(res)
|
||||
console.log("/myshoppinglists inside idtoken: ", idtoken)
|
||||
firebase.auth().onAuthStateChanged(async function (user) {
|
||||
if (user) {
|
||||
firebase.auth().currentUser.getIdToken( /* forceRefresh */ true).then(function (idtoken) {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/myshoppinglists",
|
||||
url: "/shoppinglist_json/" + id,
|
||||
data: {
|
||||
idtoken: idtoken
|
||||
},
|
||||
success(result){
|
||||
// var idtoken = getIdTokenGoogle()
|
||||
success(res) {
|
||||
console.log(res)
|
||||
console.log("/myshoppinglists inside idtoken: ", idtoken)
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/userinfo_json",
|
||||
data:{
|
||||
url: "/myshoppinglists",
|
||||
data: {
|
||||
idtoken: idtoken
|
||||
},
|
||||
success(data){
|
||||
let userinfo = "some info"
|
||||
console.log(userinfo);
|
||||
|
||||
const neu = result.filter(obj => obj.sl_id === id);
|
||||
success(result) {
|
||||
// var idtoken = getIdTokenGoogle()
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/userinfo_json",
|
||||
data: {
|
||||
idtoken: idtoken
|
||||
},
|
||||
success(data) {
|
||||
let userinfo = "some info"
|
||||
console.log(userinfo);
|
||||
|
||||
var link = "/dash/"+idtoken;
|
||||
const neu = result.filter(obj => obj.sl_id === id);
|
||||
|
||||
$(".kopf").attr("style",`background-color:#${neu[0].color}`);
|
||||
var link = "/dash/" + idtoken;
|
||||
|
||||
console.log(neu[0].color);
|
||||
$(".kopf").attr("style", `background-color:#${neu[0].color}`);
|
||||
|
||||
$(".card-header").append(`<div class="shoplistid" id="${id}">
|
||||
console.log(neu[0].color);
|
||||
|
||||
$(".card-header").append(`<div class="shoplistid" id="${id}">
|
||||
<a href="${link}" style="left: 5px; margin-top: -50px;color: black;">
|
||||
<i class="fas fa-caret-left"></i>
|
||||
</a>
|
||||
@ -272,9 +304,9 @@ function Detail(){
|
||||
${neu[0].name}
|
||||
</h1></div>
|
||||
`);
|
||||
for (let i = 0; i < res.groups.length; i++) {
|
||||
const el = res.groups[i];
|
||||
$(".gruppeninhalt").append(`<div class="col-md-6 col-lg-4 shoplisteid" id="${res.sl_id}">
|
||||
for (let i = 0; i < res.groups.length; i++) {
|
||||
const el = res.groups[i];
|
||||
$(".gruppeninhalt").append(`<div class="col-md-6 col-lg-4 shoplisteid" id="${res.sl_id}">
|
||||
<div class="card mb-3 groupid ${el.group_id}" id="${el.group_id}" style="max-width: 18rem;background-color:#${el.color};">
|
||||
|
||||
<div class="card-header"><h5 class="card-title">${el.name}</h5><button class="btn trashgroup"><i class="far fa-trash-alt"></i></button><button class="btn seemore" type="button" data-toggle="collapse" data-target="#${el.name}" aria-expanded="false" aria-controls="${el.name}"><i class="fas fa-caret-down"></i></button>
|
||||
@ -284,71 +316,81 @@ function Detail(){
|
||||
|
||||
</div></div>
|
||||
`);
|
||||
for(let x = 0; x < el.content.length; x++){
|
||||
const el2 = el.content[x]
|
||||
$(`.${el.name}`).append(`<div class="collapse" id="${el.name}"><ul><li>${el2.count}x ${el2.name}</li></ul></div>`);
|
||||
}
|
||||
}
|
||||
ItemAdden();
|
||||
groupdelete();
|
||||
for (let x = 0; x < el.content.length; x++) {
|
||||
const el2 = el.content[x]
|
||||
$(`.${el.name}`).append(`<div class="collapse" id="${el.name}"><ul><li>${el2.count}x ${el2.name}</li></ul></div>`);
|
||||
}
|
||||
}
|
||||
ItemAdden();
|
||||
groupdelete();
|
||||
},
|
||||
error(err) {
|
||||
console.log("Detail error userinfo_json: ", err);
|
||||
}
|
||||
})
|
||||
},
|
||||
error(err){
|
||||
console.log("Detail error userinfo_json: ", err);
|
||||
error(err) {
|
||||
console.log("Detail error myshoppinglists: ", err);
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
error(err){
|
||||
console.log("Detail error myshoppinglists: ", err);
|
||||
error(err) {
|
||||
console.log("Detail error shoppinglist_json: ", err);
|
||||
}
|
||||
});
|
||||
},
|
||||
error(err){
|
||||
console.log("Detail error shoppinglist_json: " , err);
|
||||
}
|
||||
});
|
||||
}).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)
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function ItemAdden(){
|
||||
$(".itemadd").click(function(){
|
||||
function ItemAdden() {
|
||||
$(".itemadd").click(function () {
|
||||
|
||||
let getid = $(this).closest('.shoplistid');
|
||||
let id = getid.attr('id');
|
||||
let id = getid.attr('id');
|
||||
globaleAddZwischenID = id;
|
||||
console.log(id);
|
||||
$('.select').remove();
|
||||
|
||||
$('.GroupItemAdd').modal('show');
|
||||
|
||||
firebase.auth().onAuthStateChanged(async function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/shoppinglist_json/" + id,
|
||||
data: {
|
||||
idtoken: idtoken
|
||||
},
|
||||
success(result){
|
||||
firebase.auth().onAuthStateChanged(async function (user) {
|
||||
if (user) {
|
||||
firebase.auth().currentUser.getIdToken( /* forceRefresh */ true).then(function (idtoken) {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/shoppinglist_json/" + id,
|
||||
data: {
|
||||
idtoken: idtoken
|
||||
},
|
||||
success(result) {
|
||||
|
||||
console.log(result.groups);
|
||||
console.log(result.groups);
|
||||
|
||||
for (let i = 0; i < result.groups.length; i++) {
|
||||
const el = result.groups[i];
|
||||
$(".custom-select-groups").append(`
|
||||
for (let i = 0; i < result.groups.length; i++) {
|
||||
const el = result.groups[i];
|
||||
$(".custom-select-groups").append(`
|
||||
<option class="select" value="${el.group_id}">${el.name}</option>
|
||||
`);
|
||||
}
|
||||
|
||||
},
|
||||
error(err){
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
}).catch((error) => console.error("Get id token client error: ", error));}else{console.log("Check Auth error", user)}});
|
||||
}
|
||||
|
||||
},
|
||||
error(err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
}).catch((error) => console.error("Get id token client error: ", error));
|
||||
} else {
|
||||
console.log("Check Auth error", user)
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$(".itemhinzu").click(function(){
|
||||
$(".itemhinzu").click(function () {
|
||||
|
||||
var name = $('#itemname').val();
|
||||
var zahl = $('#inputGroupSelect01').val();
|
||||
@ -361,14 +403,15 @@ $(".itemhinzu").click(function(){
|
||||
type: "POST",
|
||||
url: "/item",
|
||||
data: {
|
||||
group_id: $('#inputGroupSelect02').val(),
|
||||
group_id: $('#inputGroupSelect02').val(),
|
||||
sl_id: globaleAddZwischenID,
|
||||
name: $('#itemname').val(),
|
||||
count: $('#inputGroupSelect01').val()
|
||||
},
|
||||
success(result){
|
||||
success(result) {
|
||||
console.log("post item");
|
||||
},error(err){
|
||||
},
|
||||
error(err) {
|
||||
|
||||
}
|
||||
});
|
||||
@ -377,9 +420,9 @@ $(".itemhinzu").click(function(){
|
||||
|
||||
});
|
||||
|
||||
function groupdelete(){
|
||||
$('.trashgroup').click(function(){
|
||||
|
||||
function groupdelete() {
|
||||
$('.trashgroup').click(function () {
|
||||
|
||||
let getid = $(this).closest('.shoplisteid');
|
||||
let shoplistid = getid.attr('id');
|
||||
let getid2 = $(this).closest('.groupid');
|
||||
@ -393,15 +436,16 @@ function groupdelete(){
|
||||
url: "/group",
|
||||
data: {
|
||||
sl_id: shoplistid,
|
||||
group_id: groupid},
|
||||
success(res){
|
||||
group_id: groupid
|
||||
},
|
||||
success(res) {
|
||||
console.log("card gelöscht");
|
||||
$(`.${groupid}`).remove();
|
||||
},
|
||||
error(err){
|
||||
error(err) {
|
||||
console.log("error");
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
};
|
File diff suppressed because it is too large
Load Diff
@ -1,50 +1,47 @@
|
||||
|
||||
|
||||
// var admin = require("firebase-admin");
|
||||
|
||||
// var serviceAccount = require("firebaseAdminKey.json");
|
||||
|
||||
// admin.initializeApp({
|
||||
// credential: admin.credential.cert(serviceAccount),
|
||||
// databaseURL: "https://test-667ca.firebaseio.com"
|
||||
// });
|
||||
|
||||
var msg = firebase.messaging();
|
||||
msg.requestPermission()
|
||||
.then(function(){
|
||||
|
||||
return msg.getToken();
|
||||
})
|
||||
.then(token => {
|
||||
console.log("Zugriff auf msg", token);
|
||||
updateUser(token);
|
||||
|
||||
})
|
||||
.catch(err => {
|
||||
console.error("Msg Error: ", err);
|
||||
})
|
||||
.then(function () {
|
||||
|
||||
return msg.getToken();
|
||||
})
|
||||
.then(token => {
|
||||
console.log("Zugriff auf msg", token);
|
||||
updateUser(token);
|
||||
|
||||
})
|
||||
.catch(err => {
|
||||
console.error("Msg Error: ", err);
|
||||
})
|
||||
|
||||
|
||||
function updateUser(token) {
|
||||
firebase.auth().onAuthStateChanged(function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/user",
|
||||
data:{
|
||||
idtoken: idtoken,
|
||||
message_id: token
|
||||
},
|
||||
success(){
|
||||
console.log("User updated");
|
||||
},
|
||||
error(err){
|
||||
console.error("Error: " + err);
|
||||
}
|
||||
});
|
||||
}).catch((error) => console.error("Get id token client error: ", error));}else{console.log("Check Auth error", user)}});
|
||||
firebase.auth().onAuthStateChanged(function (user) {
|
||||
if (user) {
|
||||
firebase.auth().currentUser.getIdToken( /* forceRefresh */ true).then(function (idtoken) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/user",
|
||||
data: {
|
||||
idtoken: idtoken,
|
||||
message_id: token
|
||||
},
|
||||
success() {
|
||||
console.log("User updated");
|
||||
},
|
||||
error(err) {
|
||||
console.error("Error: " + err);
|
||||
}
|
||||
});
|
||||
}).catch((error) => console.error("Get id token client error: ", error));
|
||||
} else {
|
||||
console.log("Check Auth error", user)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
msg.onMessage(payload => {
|
||||
const title = payload.data.title
|
||||
new Notification(title, { body: payload.data.body});
|
||||
})
|
||||
new Notification(title, {
|
||||
body: payload.data.body
|
||||
});
|
||||
})
|
@ -1,101 +1,110 @@
|
||||
|
||||
|
||||
// Initialize Firebase
|
||||
var config = {
|
||||
apiKey: "AIzaSyCuvwf78cmSDoZ2yS4XxHZhnjUn7yIHYfw",
|
||||
authDomain: "test-667ca.firebaseapp.com",
|
||||
databaseURL: "https://test-667ca.firebaseio.com",
|
||||
projectId: "test-667ca",
|
||||
storageBucket: "test-667ca.appspot.com",
|
||||
messagingSenderId: "221332577314"
|
||||
apiKey: "AIzaSyCuvwf78cmSDoZ2yS4XxHZhnjUn7yIHYfw",
|
||||
authDomain: "test-667ca.firebaseapp.com",
|
||||
databaseURL: "https://test-667ca.firebaseio.com",
|
||||
projectId: "test-667ca",
|
||||
storageBucket: "test-667ca.appspot.com",
|
||||
messagingSenderId: "221332577314"
|
||||
};
|
||||
firebase.initializeApp(config);
|
||||
|
||||
|
||||
function checkAuth(){
|
||||
firebase.auth().onAuthStateChanged(async function(user){
|
||||
if(user){
|
||||
try{
|
||||
firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idToken) {
|
||||
console.log("Vor Replace");
|
||||
function checkAuth() {
|
||||
firebase.auth().onAuthStateChanged(async function (user) {
|
||||
if (user) {
|
||||
try {
|
||||
firebase.auth().currentUser.getIdToken( /* forceRefresh */ true).then(function (idToken) {
|
||||
console.log("Vor Replace");
|
||||
|
||||
window.location.replace("/dash/" + idToken);
|
||||
}).catch(function(error) {
|
||||
console.error("Get id token client error: ", error)
|
||||
});
|
||||
}catch{
|
||||
console.error("checkAuth error: ")
|
||||
}
|
||||
|
||||
// document.getElementById("loginbutton").style.display = "none";
|
||||
//
|
||||
}else{
|
||||
// document.getElementById("loginbutton").style.display = "block";
|
||||
console.log("Check Auth error", user)
|
||||
}
|
||||
})
|
||||
var user = firebase.auth().currentUser;
|
||||
window.location.replace("/dash/" + idToken);
|
||||
}).catch(function (error) {
|
||||
console.error("Get id token client error: ", error)
|
||||
});
|
||||
} catch {
|
||||
console.error("checkAuth error: ")
|
||||
}
|
||||
|
||||
// document.getElementById("loginbutton").style.display = "none";
|
||||
//
|
||||
} else {
|
||||
// document.getElementById("loginbutton").style.display = "block";
|
||||
console.log("Check Auth error", user)
|
||||
}
|
||||
})
|
||||
var user = firebase.auth().currentUser;
|
||||
}
|
||||
window.onload = function(){
|
||||
checkAuth();
|
||||
window.onload = function () {
|
||||
checkAuth();
|
||||
}
|
||||
|
||||
|
||||
|
||||
var vue = new Vue({
|
||||
el: '#vue-app',
|
||||
data:{
|
||||
el: '#vue-app',
|
||||
data: {
|
||||
email: "",
|
||||
password: ""
|
||||
},
|
||||
methods: {
|
||||
login() {
|
||||
var provider = new firebase.auth.GoogleAuthProvider();
|
||||
provider.addScope('profile');
|
||||
provider.addScope('email');
|
||||
firebase.auth().signInWithPopup(provider).then(function (result) {
|
||||
// This gives you a Google Access Token. You can use it to access the Google API.
|
||||
var token = result.credential.accessToken;
|
||||
var idToken = result.credential.idToken;
|
||||
// The signed-in user info.
|
||||
var user = result.user;
|
||||
console.log("Eingelogt");
|
||||
checkAuth();
|
||||
}).catch(function (error) {
|
||||
// Handle Errors here.
|
||||
var errorCode = error.code;
|
||||
var errorMessage = error.message;
|
||||
// The email of the user's account used.
|
||||
var email = error.email;
|
||||
// The firebase.auth.AuthCredential type that was used.
|
||||
var credential = error.credential;
|
||||
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
login(){
|
||||
var provider = new firebase.auth.GoogleAuthProvider();
|
||||
provider.addScope('profile');
|
||||
provider.addScope('email');
|
||||
firebase.auth().signInWithPopup(provider).then(function(result) {
|
||||
// This gives you a Google Access Token. You can use it to access the Google API.
|
||||
var token = result.credential.accessToken;
|
||||
var idToken = result.credential.idToken;
|
||||
// The signed-in user info.
|
||||
var user = result.user;
|
||||
console.log("Eingelogt");
|
||||
checkAuth();
|
||||
}).catch(function(error) {
|
||||
// Handle Errors here.
|
||||
var errorCode = error.code;
|
||||
var errorMessage = error.message;
|
||||
// The email of the user's account used.
|
||||
var email = error.email;
|
||||
// The firebase.auth.AuthCredential type that was used.
|
||||
var credential = error.credential;
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
mounted() {
|
||||
/*axios.post('/user', {
|
||||
message_id: 'test',
|
||||
})
|
||||
.then(function (response) {
|
||||
console.log(response);
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
});*/
|
||||
loginemail(){
|
||||
firebase.auth().signInWithEmailAndPassword(this.email, this.password).then(result =>{
|
||||
checkAuth();
|
||||
}).catch(function(error) {
|
||||
// Handle Errors here.
|
||||
var errorCode = error.code;
|
||||
var errorMessage = error.message;
|
||||
// ...
|
||||
});
|
||||
}
|
||||
|
||||
// mounted() {
|
||||
// axios.post('/user', {
|
||||
// message_id: 'test',
|
||||
// })
|
||||
// .then(function (response) {
|
||||
// console.log(response);
|
||||
// })
|
||||
// .catch(function (error) {
|
||||
// console.log(error);
|
||||
// });
|
||||
// }
|
||||
},
|
||||
|
||||
mounted() {
|
||||
/*axios.post('/user', {
|
||||
message_id: 'test',
|
||||
})
|
||||
.then(function (response) {
|
||||
console.log(response);
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
});*/
|
||||
}
|
||||
|
||||
// mounted() {
|
||||
// axios.post('/user', {
|
||||
// message_id: 'test',
|
||||
// })
|
||||
// .then(function (response) {
|
||||
// console.log(response);
|
||||
// })
|
||||
// .catch(function (error) {
|
||||
// console.log(error);
|
||||
// });
|
||||
// }
|
||||
|
||||
});
|
@ -1,4 +1,4 @@
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function () {
|
||||
refresh();
|
||||
|
||||
userinfo();
|
||||
@ -13,8 +13,8 @@ $(document).ready(function() {
|
||||
hidden: false
|
||||
}
|
||||
});
|
||||
|
||||
$(".btn_invite").click(function() {
|
||||
|
||||
$(".btn_invite").click(function () {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/invite",
|
||||
@ -25,11 +25,11 @@ $(document).ready(function() {
|
||||
});
|
||||
|
||||
|
||||
$(document).on("click", ".btn_detail", function() {
|
||||
$(document).on("click", ".btn_detail", function () {
|
||||
window.location.replace("/shoppinglist_json/" + $(this).closest("tr").attr("id"));
|
||||
});
|
||||
|
||||
$(".btn_add").click(function() {
|
||||
$(".btn_add").click(function () {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/shoppinglist",
|
||||
@ -37,19 +37,21 @@ $(document).ready(function() {
|
||||
name: $(".name").val(),
|
||||
description: $(".description").val(),
|
||||
color: "red"
|
||||
}, success(result) {
|
||||
},
|
||||
success(result) {
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on("click", ".btn_delete", function() {
|
||||
$(document).on("click", ".btn_delete", function () {
|
||||
$.ajax({
|
||||
type: "DELETE",
|
||||
url: "/shoppinglist",
|
||||
data: {
|
||||
sl_id: $(this).closest("tr").attr("id")
|
||||
}, success(result) {
|
||||
},
|
||||
success(result) {
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
@ -64,10 +66,10 @@ function refresh() {
|
||||
type: "GET",
|
||||
url: "/myshoppinglists",
|
||||
success(data) {
|
||||
for(let item of data) {
|
||||
$(".tb_myshoppinglists").append("<tr id='" + item.sl_id +"'><td>" + item.name + "</td><td>" + item.description +
|
||||
"</td><td> <a class='btn-floating btn-large waves-effect waves-light red btn_detail'><i class='material-icons'>forward</i></a></td>"
|
||||
+ "<td><a class='btn-floating btn-large waves-effect waves-light red btn_delete'><i class='material-icons'>clear</i></a></td></tr>");
|
||||
for (let item of data) {
|
||||
$(".tb_myshoppinglists").append("<tr id='" + item.sl_id + "'><td>" + item.name + "</td><td>" + item.description +
|
||||
"</td><td> <a class='btn-floating btn-large waves-effect waves-light red btn_detail'><i class='material-icons'>forward</i></a></td>" +
|
||||
"<td><a class='btn-floating btn-large waves-effect waves-light red btn_delete'><i class='material-icons'>clear</i></a></td></tr>");
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -76,9 +78,9 @@ function refresh() {
|
||||
type: "GET",
|
||||
url: "/sharedshoppinglists",
|
||||
success(data) {
|
||||
for(let item of data) {
|
||||
$(".tb_sharedshoppinglists").append("<tr id='" + item.sl_id +"'><td>" + item.name + "</td><td>" + item.description +
|
||||
"</td><td> <a class='btn-floating btn-large waves-effect waves-light red btn_detail'><i class='material-icons'>forward</i></a></td></tr>");
|
||||
for (let item of data) {
|
||||
$(".tb_sharedshoppinglists").append("<tr id='" + item.sl_id + "'><td>" + item.name + "</td><td>" + item.description +
|
||||
"</td><td> <a class='btn-floating btn-large waves-effect waves-light red btn_detail'><i class='material-icons'>forward</i></a></td></tr>");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user