summary refs log tree commit diff
path: root/synapse/handlers/set_password.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2017-11-29 15:44:59 +0000
committerRichard van der Hoff <richard@matrix.org>2017-11-29 16:44:35 +0000
commitad7e570d07e498e7a9395800650aeef0f9fbc914 (patch)
treef8d8f53bdf064d0033be76bc3c4ce8bc1582540f /synapse/handlers/set_password.py
parentMove set_password into its own handler (diff)
downloadsynapse-ad7e570d07e498e7a9395800650aeef0f9fbc914.tar.xz
Delete devices in various logout situations
Make sure that we delete devices whenever a user is logged out due to any of
the following situations:

 * /logout
 * /logout_all
 * change password
 * deactivate account (by the user or by an admin)
 * invalidate access token from a dynamic module

Fixes #2672.
Diffstat (limited to 'synapse/handlers/set_password.py')
-rw-r--r--synapse/handlers/set_password.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/synapse/handlers/set_password.py b/synapse/handlers/set_password.py
index c0d83f229c..44414e1dc1 100644
--- a/synapse/handlers/set_password.py
+++ b/synapse/handlers/set_password.py
@@ -27,11 +27,13 @@ class SetPasswordHandler(BaseHandler):
     def __init__(self, hs):
         super(SetPasswordHandler, self).__init__(hs)
         self._auth_handler = hs.get_auth_handler()
+        self._device_handler = hs.get_device_handler()
 
     @defer.inlineCallbacks
     def set_password(self, user_id, newpassword, requester=None):
         password_hash = self._auth_handler.hash(newpassword)
 
+        except_device_id = requester.device_id if requester else None
         except_access_token_id = requester.access_token_id if requester else None
 
         try:
@@ -40,6 +42,15 @@ class SetPasswordHandler(BaseHandler):
             if e.code == 404:
                 raise SynapseError(404, "Unknown user", Codes.NOT_FOUND)
             raise e
+
+        # we want to log out all of the user's other sessions. First delete
+        # all his other devices.
+        yield self._device_handler.delete_all_devices_for_user(
+            user_id, except_device_id=except_device_id,
+        )
+
+        # and now delete any access tokens which weren't associated with
+        # devices (or were associated with this device).
         yield self._auth_handler.delete_access_tokens_for_user(
             user_id, except_token_id=except_access_token_id,
         )