Compare commits
3 Commits
aef2a1ae60
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
1982a45392
|
|||
|
3cfe42023b
|
|||
|
e043f475da
|
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import copy
|
||||||
from slugify import slugify
|
from slugify import slugify
|
||||||
from threading import Thread, Event
|
from threading import Thread, Event
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
@ -33,7 +34,7 @@ class Notifier(Thread):
|
|||||||
|
|
||||||
ps = ps[0]
|
ps = ps[0]
|
||||||
|
|
||||||
print("Sending notification", arrival, ps)
|
print("Sending notification", arrival, ps, self.vapid_creds)
|
||||||
|
|
||||||
subscription = ps['sub']
|
subscription = ps['sub']
|
||||||
notification = {
|
notification = {
|
||||||
@ -41,13 +42,15 @@ class Notifier(Thread):
|
|||||||
'body': "You didn't sign out of ftracker yet",
|
'body': "You didn't sign out of ftracker yet",
|
||||||
'arr': arrival
|
'arr': arrival
|
||||||
}
|
}
|
||||||
|
privkey = self.vapid_creds['private_key']
|
||||||
|
claims = copy.copy(self.vapid_creds['claims'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
webpush(
|
webpush(
|
||||||
subscription,
|
subscription,
|
||||||
json.dumps(notification),
|
json.dumps(notification),
|
||||||
vapid_private_key = self.vapid_creds['private_key'],
|
vapid_private_key = privkey,
|
||||||
vapid_claims = self.vapid_creds['claims']
|
vapid_claims = claims
|
||||||
)
|
)
|
||||||
print("Notification sent")
|
print("Notification sent")
|
||||||
return None
|
return None
|
||||||
|
|||||||
@ -46,12 +46,13 @@
|
|||||||
<a href="/view">View Data</a>,
|
<a href="/view">View Data</a>,
|
||||||
<a href="/QRgen">Door Sign Generator</a>,
|
<a href="/QRgen">Door Sign Generator</a>,
|
||||||
<a href="/?arrival=42">Test Arrival</a>,
|
<a href="/?arrival=42">Test Arrival</a>,
|
||||||
<a href="/?departure=42">Test Departure</a><br><br>
|
<a href="/?departure=42">Test Departure</a>,
|
||||||
|
<a href="javascript:localStorage.removeItem('pushsub')">Reset Push Subscription</a><br><br>
|
||||||
© 2020 made by <a target="_blank" href="mailto:o.winkels@fasttube.de">Oskar</a>
|
© 2020 made by <a target="_blank" href="mailto:o.winkels@fasttube.de">Oskar</a>
|
||||||
for <a target="_blank" href="//fasttube.de">FaSTTUBe</a>.<br>
|
for <a target="_blank" href="//fasttube.de">FaSTTUBe</a>.<br>
|
||||||
For source code & licensing see <a href="//git.fasttube.de/FaSTTUBe/ftracker">git repo</a>
|
For source code & licensing see <a href="//git.fasttube.de/FaSTTUBe/ftracker">git repo</a>
|
||||||
</div>
|
</div>
|
||||||
<form id="mainform" style="display: none">
|
<form id="mainform" action="javascript:void(0);" style="display: none">
|
||||||
<label>
|
<label>
|
||||||
Full Name:<br>
|
Full Name:<br>
|
||||||
<input type="text" name="name" id="name" placeholder="John Doe" required>
|
<input type="text" name="name" id="name" placeholder="John Doe" required>
|
||||||
|
|||||||
12
web/main.js
12
web/main.js
@ -268,16 +268,18 @@ function registerPush(name, pushServerPublicKey) {
|
|||||||
}).then(function(subscription) {
|
}).then(function(subscription) {
|
||||||
console.log("User is subscribed:", subscription);
|
console.log("User is subscribed:", subscription);
|
||||||
|
|
||||||
|
var jsonSub = JSON.stringify({
|
||||||
|
name: name,
|
||||||
|
sub: subscription
|
||||||
|
});
|
||||||
|
|
||||||
fetch('/pushsubscribe', {
|
fetch('/pushsubscribe', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {"Content-Type": "application/json"},
|
headers: {"Content-Type": "application/json"},
|
||||||
body: JSON.stringify({
|
body: jsonSub
|
||||||
name: name,
|
|
||||||
sub: subscription
|
|
||||||
})
|
|
||||||
}).then(function(res) {
|
}).then(function(res) {
|
||||||
if (res.ok)
|
if (res.ok)
|
||||||
localStorage.setItem('pushsub', subscription);
|
localStorage.setItem('pushsub', jsonSub);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user