1
0
Fork 0
mirror of https://github.com/Lynnesbian/FediBooks/ synced 2024-11-25 16:48:58 +00:00

request and store web push credentials

This commit is contained in:
Lynne Megido 2019-09-03 14:17:20 +10:00
parent be0a843c1a
commit 802120540a
2 changed files with 12 additions and 4 deletions

View file

@ -18,9 +18,9 @@ CREATE TABLE IF NOT EXISTS `bots` (
`handle` VARCHAR(128) PRIMARY KEY, `handle` VARCHAR(128) PRIMARY KEY,
`user_id` INT NOT NULL, `user_id` INT NOT NULL,
`credentials_id` INT NOT NULL, `credentials_id` INT NOT NULL,
`push_private_key` VARCHAR(256) NOT NULL, `push_private_key` BINARY(128) NOT NULL,
`push_public_key` VARCHAR(256) NOT NULL, `push_public_key` BINARY(128) NOT NULL,
`push_secret` VARCHAR(256), `push_secret` BINARY(16)),
`enabled` BOOLEAN DEFAULT 1, `enabled` BOOLEAN DEFAULT 1,
`replies_enabled` BOOLEAN DEFAULT 1, `replies_enabled` BOOLEAN DEFAULT 1,
`post_frequency` SMALLINT UNSIGNED DEFAULT 30, `post_frequency` SMALLINT UNSIGNED DEFAULT 30,

View file

@ -304,7 +304,15 @@ def bot_create():
credentials_id = c.lastrowid credentials_id = c.lastrowid
mysql.connection.commit() 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() mysql.connection.commit()
c.close() c.close()