From deff8d85dbb12b4ec171a62885a541ff04ef72b2 Mon Sep 17 00:00:00 2001 From: Hailey Clark Date: Sat, 26 Dec 2020 23:17:33 -0800 Subject: [PATCH] SQL and Logic changes Added the change in SQL and re-ordered the logic in the /subscribe/ handler. --- database.sql | 4 +++- smsproj.py | 5 ++--- static/main.js | 1 - 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/database.sql b/database.sql index 62f4ba1..a359f2b 100644 --- a/database.sql +++ b/database.sql @@ -103,7 +103,7 @@ CREATE TABLE `phonebase` ( INDEX `pb_phonebaseID` (`contact_id`), INDEX `index_archivedNumbers` (`archived`), CONSTRAINT `pb_accountassoc` - FOREIGN KEY (`contact_id`) REFERENCES account (id) + FOREIGN KEY (`contact_id`) REFERENCES account (id) ) COLLATE='utf8_bin' ENGINE=InnoDB; @@ -129,3 +129,5 @@ ALTER TABLE contacts CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ALTER TABLE dids CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE phonebase CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE destination CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +ALTER TABLE `account` ADD COLUMN `subscription_token` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8_bin' AFTER `picture_url`; diff --git a/smsproj.py b/smsproj.py index b44fdec..049f8c9 100644 --- a/smsproj.py +++ b/smsproj.py @@ -202,13 +202,12 @@ def subscription(): ''' POST creates a subscription GET returns vapid public key which clients uses to send around push notification''' + subscription_token = request.get_json("subscription_token") + appdb.updateSubscriptionToken(flask.session['account_id'], subscription_token) if request.method == "GET": return Response(response=json.dumps({"public_key": VAPID_PUBLIC_KEY}), headers={"Access-Control-Allow-Origin": "*"}, content_type="application/json") - - subscription_token = request.get_json("subscription_token") - appdb.updateSubscriptionToken(flask.session['account_id'], subscription_token) return Response(status=201, mimetype="application/json") diff --git a/static/main.js b/static/main.js index 243d2c3..6d61455 100644 --- a/static/main.js +++ b/static/main.js @@ -58,7 +58,6 @@ function updateSubscriptionOnServer(subscription) { function subscribeUser() { const applicationServerPublicKey = localStorage.getItem('applicationServerPublicKey'); const applicationServerKey = urlB64ToUint8Array(applicationServerPublicKey); - alert("TEST"); swRegistration.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: applicationServerKey