Add new signal auth_user_created_from_upstream to sample
authorMagnus Hagander <magnus@hagander.net>
Wed, 7 Jun 2023 19:46:04 +0000 (21:46 +0200)
committerMagnus Hagander <magnus@hagander.net>
Wed, 7 Jun 2023 19:46:04 +0000 (21:46 +0200)
This signal fires when a new user has been created either from the user
logging in the first time or from an import.

tools/communityauth/sample/django/auth.py

index bff5b620aa1da749328709044f8b1db240587613..edb87b1960e0d41a1b4a4e0e058f9cd7f835d80e 100644 (file)
@@ -8,6 +8,8 @@
 # * Make sure the view "login" from this module is used for login
 # * Map an url somwehere (typically /auth_receive/) to the auth_receive
 #   view.
+# * To get notified when a user is created from upstream, connect to the signal
+#   auth_user_created_from_upstream.
 # * To receive live updates (not just during login), map an url somewhere
 #   (typically /auth_api/) to the auth_api view.
 # * To receive live updates, also connect to the signal auth_user_data_received.
@@ -44,6 +46,9 @@ from Cryptodome import Random
 import time
 
 
+# This signal fires when a user is created based on data from upstream.
+auth_user_created_from_upstream = Signal(providing_args=['user', ])
+
 # This signal fires whenever new user data has been received. Note that this
 # happens *after* first_name, last_name and email has been updated on the user
 # record, so those are not included in the userdata struct.
@@ -174,6 +179,8 @@ We apologize for the inconvenience.
                     )
         user.save()
 
+        auth_user_created_from_upstream.send(user)
+
     # Ok, we have a proper user record. Now tell django that
     # we're authenticated so it persists it in the session. Before
     # we do that, we have to annotate it with the backend information.
@@ -359,4 +366,6 @@ def user_import(uid):
     )
     u.save()
 
+    auth_user_created_from_upstream.send(user)
+
     return u