about summary refs log tree commit diff
path: root/app/models/user.rb
diff options
context:
space:
mode:
authorFrancis Murillo <evacuee.overlap.vs3op@aleeas.com>2022-12-15 14:47:06 +0000
committerGitHub <noreply@github.com>2022-12-15 15:47:06 +0100
commit5fb1c3e934a1a782972ac2732ce7f0208c341ac2 (patch)
tree334d257639188b485a9e1b2eaebd611e99e5c4e0 /app/models/user.rb
parentfe9eab51d140ee0e0343eb07982f0a7ce825398c (diff)
Revoke all authorized applications on password reset (#21325)
* Clear sessions on password change

* Rename User::clear_sessions to revoke_access for a clearer meaning

* Add reset paassword controller test

* Use User.find instead of User.find_for_authentication for reset password test

* Use redirect and render for better test meaning in reset password

Co-authored-by: Effy Elden <effy@effy.space>
Diffstat (limited to 'app/models/user.rb')
-rw-r--r--app/models/user.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 5530a9070..ca98a0afa 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -377,6 +377,15 @@ class User < ApplicationRecord
     super
   end
 
+  def revoke_access!
+    Doorkeeper::AccessGrant.by_resource_owner(self).update_all(revoked_at: Time.now.utc)
+
+    Doorkeeper::AccessToken.by_resource_owner(self).in_batches do |batch|
+      batch.update_all(revoked_at: Time.now.utc)
+      Web::PushSubscription.where(access_token_id: batch).delete_all
+    end
+  end
+
   def reset_password!
     # First, change password to something random and deactivate all sessions
     transaction do
@@ -385,12 +394,7 @@ class User < ApplicationRecord
     end
 
     # Then, remove all authorized applications and connected push subscriptions
-    Doorkeeper::AccessGrant.by_resource_owner(self).in_batches.update_all(revoked_at: Time.now.utc)
-
-    Doorkeeper::AccessToken.by_resource_owner(self).in_batches do |batch|
-      batch.update_all(revoked_at: Time.now.utc)
-      Web::PushSubscription.where(access_token_id: batch).delete_all
-    end
+    revoke_access!
 
     # Finally, send a reset password prompt to the user
     send_reset_password_instructions