diff options
author | Erik Johnston <erik@matrix.org> | 2020-08-05 21:38:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-05 21:38:57 +0100 |
commit | a7bdf98d01d2225a479753a85ba81adf02b16a32 (patch) | |
tree | 11443d9f4d89d9cd33d34d4146fd62e6393a87c6 /synapse/storage/databases/main/openid.py | |
parent | Stop the parent process flushing the logs on exit (#8012) (diff) | |
download | synapse-a7bdf98d01d2225a479753a85ba81adf02b16a32.tar.xz |
Rename database classes to make some sense (#8033)
Diffstat (limited to 'synapse/storage/databases/main/openid.py')
-rw-r--r-- | synapse/storage/databases/main/openid.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/synapse/storage/databases/main/openid.py b/synapse/storage/databases/main/openid.py new file mode 100644 index 0000000000..dcd1ff911a --- /dev/null +++ b/synapse/storage/databases/main/openid.py @@ -0,0 +1,33 @@ +from synapse.storage._base import SQLBaseStore + + +class OpenIdStore(SQLBaseStore): + def insert_open_id_token(self, token, ts_valid_until_ms, user_id): + return self.db_pool.simple_insert( + table="open_id_tokens", + values={ + "token": token, + "ts_valid_until_ms": ts_valid_until_ms, + "user_id": user_id, + }, + desc="insert_open_id_token", + ) + + def get_user_id_for_open_id_token(self, token, ts_now_ms): + def get_user_id_for_token_txn(txn): + sql = ( + "SELECT user_id FROM open_id_tokens" + " WHERE token = ? AND ? <= ts_valid_until_ms" + ) + + txn.execute(sql, (token, ts_now_ms)) + + rows = txn.fetchall() + if not rows: + return None + else: + return rows[0][0] + + return self.db_pool.runInteraction( + "get_user_id_for_token", get_user_id_for_token_txn + ) |