diff --git a/docs/api.rst b/docs/api.rst index 53dcd68..902f8a0 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -87,43 +87,38 @@ sends the following signals. .. data:: user_registered - Sent when a user registers on the site. It is passed a dict with - the `user` and `confirm_token`, the user being logged in and the - (if so configured) the confirmation token issued. + Sent when a user registers on the site. In addition to the app (which is the + sender), it is passed `user` and `confirm_token` arguments. .. data:: user_confirmed - Sent when a user is confirmed. It is passed `user`, which is the - user being confirmed. + Sent when a user is confirmed. In addition to the app (which is the + sender), it is passed a `user` argument. .. data:: confirm_instructions_sent - Sent when a user requests confirmation instructions. It is passed - the `user`. + Sent when a user requests confirmation instructions. In addition to the app + (which is the sender), it is passed a `user` argument. .. data:: login_instructions_sent - Sent when passwordless login is used and user logs in. It is passed - a dict with the `user` and `login_token`, the user being logged in - and the (if so configured) the login token issued. + Sent when passwordless login is used and user logs in. In addition to the app + (which is the sender), it is passed `user` and `login_token` arguments. .. data:: password_reset - Sent when a user completes a password reset. It is passed the - `user`. + Sent when a user completes a password reset. In addition to the app (which is + the sender), it is passed a `user` argument. .. data:: password_changed - Sent when a user completes a password change. It is passed the - `user`. + Sent when a user completes a password change. In addition to the app (which is + the sender), it is passed a `user` argument. .. data:: reset_password_instructions_sent - Sent when a user requests a password reset. It is passed a dict - with the `user` and `token`, the user being logged in and - the (if so configured) the reset token issued. + Sent when a user requests a password reset. In addition to the app (which is + the sender), it is passed `user` and `token` arguments. -All signals are also passed a `app` keyword argument, which is the -current application. .. _Flask documentation on signals: http://flask.pocoo.org/docs/signals/ diff --git a/flask_security/changeable.py b/flask_security/changeable.py index 6918cc0..c79f84e 100644 --- a/flask_security/changeable.py +++ b/flask_security/changeable.py @@ -42,4 +42,5 @@ def change_user_password(user, password): user.password = encrypt_password(password) _datastore.put(user) send_password_changed_notice(user) - password_changed.send(app._get_current_object(), user=user) + password_changed.send(app._get_current_object(), + user=user._get_current_object()) diff --git a/flask_security/passwordless.py b/flask_security/passwordless.py index dd6465c..387b7f2 100644 --- a/flask_security/passwordless.py +++ b/flask_security/passwordless.py @@ -35,8 +35,7 @@ def send_login_instructions(user): send_mail(config_value('EMAIL_SUBJECT_PASSWORDLESS'), user.email, 'login_instructions', user=user, login_link=login_link) - login_instructions_sent.send(app._get_current_object(), - user=user, login_token=token) + login_instructions_sent.send(app._get_current_object(), user=user, login_token=token) def generate_login_token(user): diff --git a/flask_security/recoverable.py b/flask_security/recoverable.py index eca5030..1bb6878 100644 --- a/flask_security/recoverable.py +++ b/flask_security/recoverable.py @@ -35,8 +35,7 @@ def send_reset_password_instructions(user): 'reset_instructions', user=user, reset_link=reset_link) - reset_password_instructions_sent.send(app._get_current_object(), - user=user, token=token) + reset_password_instructions_sent.send(app._get_current_object(), user=user, token=token) def send_password_reset_notice(user): diff --git a/tests/test_changeable.py b/tests/test_changeable.py index e63d2b2..4020226 100644 --- a/tests/test_changeable.py +++ b/tests/test_changeable.py @@ -8,6 +8,8 @@ import pytest +from flask import Flask +from flask_security.core import UserMixin from flask_security.signals import password_changed from utils import authenticate @@ -20,6 +22,8 @@ def test_recoverable_flag(app, client, get_message): @password_changed.connect_via(app) def on_password_changed(app, user): + assert isinstance(app, Flask) + assert isinstance(user, UserMixin) recorded.append(user) authenticate(client) diff --git a/tests/test_confirmable.py b/tests/test_confirmable.py index 1a06919..51116c4 100644 --- a/tests/test_confirmable.py +++ b/tests/test_confirmable.py @@ -10,6 +10,8 @@ import time import pytest +from flask import Flask +from flask_security.core import UserMixin from flask_security.signals import user_confirmed, confirm_instructions_sent from flask_security.utils import capture_registrations @@ -25,10 +27,14 @@ def test_confirmable_flag(app, client, sqlalchemy_datastore, get_message): @user_confirmed.connect_via(app) def on_confirmed(app, user): + assert isinstance(app, Flask) + assert isinstance(user, UserMixin) recorded_confirms.append(user) @confirm_instructions_sent.connect_via(app) def on_instructions_sent(app, user): + assert isinstance(app, Flask) + assert isinstance(user, UserMixin) recorded_instructions_sent.append(user) # Test login before confirmation diff --git a/tests/test_passwordless.py b/tests/test_passwordless.py index eddf479..1021412 100644 --- a/tests/test_passwordless.py +++ b/tests/test_passwordless.py @@ -10,8 +10,10 @@ import time import pytest +from flask import Flask +from flask_security.core import UserMixin from flask_security.signals import login_instructions_sent -from flask_security.utils import capture_passwordless_login_requests +from flask_security.utils import capture_passwordless_login_requests, string_types from utils import logout @@ -23,6 +25,9 @@ def test_trackable_flag(app, client, get_message): @login_instructions_sent.connect_via(app) def on_instructions_sent(app, user, login_token): + assert isinstance(app, Flask) + assert isinstance(user, UserMixin) + assert isinstance(login_token, string_types) recorded.append(user) # Test disabled account diff --git a/tests/test_recoverable.py b/tests/test_recoverable.py index de278e1..8b91ece 100644 --- a/tests/test_recoverable.py +++ b/tests/test_recoverable.py @@ -10,8 +10,10 @@ import time import pytest +from flask import Flask +from flask_security.core import UserMixin from flask_security.signals import reset_password_instructions_sent, password_reset -from flask_security.utils import capture_reset_password_requests +from flask_security.utils import capture_reset_password_requests, string_types from utils import authenticate, logout @@ -28,6 +30,9 @@ def test_recoverable_flag(app, client, get_message): @reset_password_instructions_sent.connect_via(app) def on_instructions_sent(app, user, token): + assert isinstance(app, Flask) + assert isinstance(user, UserMixin) + assert isinstance(token, string_types) recorded_instructions_sent.append(user) # Test the reset view diff --git a/tests/test_registerable.py b/tests/test_registerable.py index 9510c5b..6f7d476 100644 --- a/tests/test_registerable.py +++ b/tests/test_registerable.py @@ -8,6 +8,8 @@ import pytest +from flask import Flask +from flask_security.core import UserMixin from flask_security.signals import user_registered from utils import authenticate, logout @@ -26,6 +28,9 @@ def test_registerable_flag(client, app, get_message): # Test registering is successful, sends email, and fires signal @user_registered.connect_via(app) def on_user_registerd(app, user, confirm_token): + assert isinstance(app, Flask) + assert isinstance(user, UserMixin) + assert confirm_token is None recorded.append(user) data = dict(