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,
`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,

View File

@ -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()