Event Notification¶
Flask Applications that want to be kept informed about certain actions that took place in underlying Flask extensions can do so by registering to receive event notification.
Flask-User defines the following events:
# Signal # Sent when ...
user_changed_password # a user changed their password
user_changed_username # a user changed their username
user_confirmed_email # a user confirmed their email
user_forgot_password # a user submitted a reset password request
user_logged_in # a user logged in
user_logged_out # a user logged out
user_registered # a user registered for a new account
user_reset_password # a user reset their password (forgot password)
See the http://flask.pocoo.org/docs/signals/
REQUIRED: Installing Blinker¶
NB: Flask-User relies on Flask signals, which relies on the ‘blinker’ package. Event notification WILL NOT WORK without first installing the ‘blinker’ package.
pip install blinker
Subscribing to Signals¶
AFTER BLINKER HAS BEEN INSTALLED, An application can receive event notifications
by using the event signal’s connect_via()
decorator:
from flask.ext.user.signals import user_logged_in
@user_logged_in.connect_via(app)
def track_login(sender, user, **extra):
sender.logger.info('user logged in')
sender
points to the app, anduser
points to the user that is associated with this event.Troubleshooting¶
If the code looks right, but the tracking functions are not called, make sure to check
to see if the ‘blinker’ package has been installed (try using pip freeze
).