From: Magnus Hagander Date: Wed, 7 Jun 2023 19:46:04 +0000 (+0200) Subject: Add new signal auth_user_created_from_upstream to sample X-Git-Url: http://git.postgresql.org/gitweb/delmail?a=commitdiff_plain;h=1b7c1c922b6532573a503484a6b9c66a21444941;p=pgweb.git Add new signal auth_user_created_from_upstream to sample This signal fires when a new user has been created either from the user logging in the first time or from an import. --- diff --git a/tools/communityauth/sample/django/auth.py b/tools/communityauth/sample/django/auth.py index bff5b620..edb87b19 100644 --- a/tools/communityauth/sample/django/auth.py +++ b/tools/communityauth/sample/django/auth.py @@ -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