From 802120540afa3c751da8be18f62fcdb800921508 Mon Sep 17 00:00:00 2001 From: Lynne Date: Tue, 3 Sep 2019 14:17:20 +1000 Subject: [PATCH] request and store web push credentials --- setup.sql | 6 +++--- webui.py | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/setup.sql b/setup.sql index 7e159ef..0b05bd5 100644 --- a/setup.sql +++ b/setup.sql @@ -18,9 +18,9 @@ CREATE TABLE IF NOT EXISTS `bots` ( `handle` VARCHAR(128) PRIMARY KEY, `user_id` INT NOT NULL, `credentials_id` INT NOT NULL, - `push_private_key` VARCHAR(256) NOT NULL, - `push_public_key` VARCHAR(256) NOT NULL, - `push_secret` VARCHAR(256), + `push_private_key` BINARY(128) NOT NULL, + `push_public_key` BINARY(128) NOT NULL, + `push_secret` BINARY(16)), `enabled` BOOLEAN DEFAULT 1, `replies_enabled` BOOLEAN DEFAULT 1, `post_frequency` SMALLINT UNSIGNED DEFAULT 30, diff --git a/webui.py b/webui.py index c045c6d..815e5b1 100644 --- a/webui.py +++ b/webui.py @@ -304,7 +304,15 @@ def bot_create(): credentials_id = c.lastrowid mysql.connection.commit() - c.execute("INSERT INTO `bots` (handle, user_id, credentials_id) VALUES (%s, %s, %s)", (handle, session['user_id'], credentials_id)) + # get webpush url + privated, publicd = client.push_subscription_generate_keys() + private = privated['privkey'] + public = publicd['pubkey'] + secret = privated['auth'] + # replace fedibooks.com with cfg['base_uri'] on release + client.push_subscription_set("https://fedibooks.com/push/{}".format(handle), publicd, mention_events = True) + + c.execute("INSERT INTO `bots` (handle, user_id, credentials_id, push_public_key, push_private_key, push_secret) VALUES (%s, %s, %s, %s, %s, %s)", (handle, session['user_id'], credentials_id, public, private, secret)) mysql.connection.commit() c.close()