mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-01 05:26:05 -04:00
Implement logout
This commit is contained in:
parent
c081228439
commit
b13035cc91
3 changed files with 109 additions and 14 deletions
|
@ -195,24 +195,45 @@ class RegistrationStore(SQLBaseStore):
|
|||
})
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def user_delete_access_tokens(self, user_id, except_token_ids):
|
||||
def user_delete_access_tokens(self, user_id, except_token_ids=[]):
|
||||
def f(txn):
|
||||
txn.execute(
|
||||
"SELECT id, token FROM access_tokens "
|
||||
"WHERE user_id = ? AND id NOT IN ? LIMIT 50",
|
||||
(user_id, except_token_ids)
|
||||
"SELECT token FROM access_tokens"
|
||||
" WHERE user_id = ? AND id NOT IN (%s)" % (
|
||||
",".join(["?" for _ in except_token_ids]),
|
||||
),
|
||||
[user_id] + except_token_ids
|
||||
)
|
||||
rows = txn.fetchall()
|
||||
for r in rows:
|
||||
txn.call_after(self.get_user_by_access_token.invalidate, (r[1],))
|
||||
txn.execute(
|
||||
"DELETE FROM access_tokens WHERE id in (%s)" % ",".join(
|
||||
["?" for _ in rows]
|
||||
), [r[0] for r in rows]
|
||||
|
||||
while True:
|
||||
rows = txn.fetchmany(100)
|
||||
if not rows:
|
||||
break
|
||||
|
||||
for row in rows:
|
||||
txn.call_after(self.get_user_by_access_token.invalidate, (row[0],))
|
||||
|
||||
txn.execute(
|
||||
"DELETE FROM access_tokens WHERE token in (%s)" % (
|
||||
",".join(["?" for _ in rows]),
|
||||
), [r[0] for r in rows]
|
||||
)
|
||||
|
||||
yield self.runInteraction("user_delete_access_tokens", f)
|
||||
|
||||
def delete_access_token(self, access_token):
|
||||
def f(txn):
|
||||
self._simple_delete_one_txn(
|
||||
txn,
|
||||
table="access_tokens",
|
||||
keyvalues={
|
||||
"token": access_token
|
||||
},
|
||||
)
|
||||
return len(rows) == 50
|
||||
while (yield self.runInteraction("user_delete_access_tokens", f)):
|
||||
pass
|
||||
|
||||
txn.call_after(self.get_user_by_access_token.invalidate, (access_token,))
|
||||
|
||||
return self.runInteraction("delete_access_token", f)
|
||||
|
||||
@cached()
|
||||
def get_user_by_access_token(self, token):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue