mirror of
https://github.com/wassname/flask-security.git
synced 2026-07-05 17:30:14 +08:00
sending signals fixed
This commit is contained in:
@@ -44,7 +44,7 @@ def send_confirmation_instructions(user):
|
||||
'confirmation_instructions', user=user,
|
||||
confirmation_link=confirmation_link)
|
||||
|
||||
confirm_instructions_sent.send(user, app=app._get_current_object())
|
||||
confirm_instructions_sent.send(app._get_current_object(), user=user)
|
||||
return token
|
||||
|
||||
|
||||
@@ -80,4 +80,4 @@ def confirm_user(user):
|
||||
"""
|
||||
user.confirmed_at = datetime.utcnow()
|
||||
_datastore.put(user)
|
||||
user_confirmed.send(user, app=app._get_current_object())
|
||||
user_confirmed.send(app._get_current_object(), user=user)
|
||||
|
||||
@@ -36,8 +36,8 @@ 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(dict(user=user, login_token=token),
|
||||
app=app._get_current_object())
|
||||
login_instructions_sent.send(app._get_current_object(),
|
||||
user=user, login_token=token)
|
||||
|
||||
|
||||
def generate_login_token(user):
|
||||
|
||||
@@ -36,8 +36,8 @@ def send_reset_password_instructions(user):
|
||||
'reset_instructions',
|
||||
user=user, reset_link=reset_link)
|
||||
|
||||
reset_password_instructions_sent.send(dict(user=user, token=token),
|
||||
app=app._get_current_object())
|
||||
reset_password_instructions_sent.send(app._get_current_object(),
|
||||
user=user, token=token)
|
||||
|
||||
|
||||
def send_password_reset_notice(user):
|
||||
@@ -77,4 +77,4 @@ def update_password(user, password):
|
||||
user.password = encrypt_password(password)
|
||||
_datastore.put(user)
|
||||
send_password_reset_notice(user)
|
||||
password_reset.send(user, app=app._get_current_object())
|
||||
password_reset.send(app._get_current_object(), user=user)
|
||||
|
||||
@@ -33,8 +33,8 @@ def register_user(**kwargs):
|
||||
confirmation_link, token = generate_confirmation_link(user)
|
||||
do_flash(*get_message('CONFIRM_REGISTRATION', email=user.email))
|
||||
|
||||
user_registered.send(dict(user=user, confirm_token=token),
|
||||
app=app._get_current_object())
|
||||
user_registered.send(app._get_current_object(),
|
||||
user=user, confirm_token=token)
|
||||
|
||||
if config_value('SEND_REGISTER_EMAIL'):
|
||||
send_mail(config_value('EMAIL_SUBJECT_REGISTER'), user.email, 'welcome',
|
||||
|
||||
@@ -273,7 +273,7 @@ def get_token_status(token, serializer, max_age=None):
|
||||
def capture_passwordless_login_requests():
|
||||
login_requests = []
|
||||
|
||||
def _on(data, app):
|
||||
def _on(app, **data):
|
||||
login_requests.append(data)
|
||||
|
||||
login_instructions_sent.connect(_on)
|
||||
@@ -293,7 +293,7 @@ def capture_registrations():
|
||||
"""
|
||||
registrations = []
|
||||
|
||||
def _on(data, app):
|
||||
def _on(app, **data):
|
||||
registrations.append(data)
|
||||
|
||||
user_registered.connect(_on)
|
||||
@@ -313,8 +313,8 @@ def capture_reset_password_requests(reset_password_sent_at=None):
|
||||
"""
|
||||
reset_requests = []
|
||||
|
||||
def _on(request, app):
|
||||
reset_requests.append(request)
|
||||
def _on(app, **data):
|
||||
reset_requests.append(data)
|
||||
|
||||
reset_password_instructions_sent.connect(_on)
|
||||
|
||||
|
||||
+15
-15
@@ -31,9 +31,9 @@ class RegisterableSignalsTests(SecurityTest):
|
||||
calls = mocks[user_registered]
|
||||
self.assertEqual(len(calls), 1)
|
||||
args, kwargs = calls[0]
|
||||
self.assertTrue(compare_user(args[0]['user'], user))
|
||||
self.assertIn('confirm_token', args[0])
|
||||
self.assertEqual(kwargs['app'], self.app)
|
||||
self.assertTrue(compare_user(kwargs['user'], user))
|
||||
self.assertIn('confirm_token', kwargs)
|
||||
self.assertEqual(args[0], self.app)
|
||||
|
||||
def test_register_without_password(self):
|
||||
e = 'dude@lp.com'
|
||||
@@ -61,8 +61,8 @@ class ConfirmableSignalsTests(SecurityTest):
|
||||
calls = mocks[user_confirmed]
|
||||
self.assertEqual(len(calls), 1)
|
||||
args, kwargs = calls[0]
|
||||
self.assertEqual(args[0].id, user.id)
|
||||
self.assertEqual(kwargs['app'], self.app)
|
||||
self.assertEqual(args[0], self.app)
|
||||
self.assertTrue(compare_user(kwargs['user'], user))
|
||||
|
||||
def test_confirm_bad_token(self):
|
||||
e = 'dude@lp.com'
|
||||
@@ -94,8 +94,8 @@ class ConfirmableSignalsTests(SecurityTest):
|
||||
calls = mocks[confirm_instructions_sent]
|
||||
self.assertEqual(len(calls), 1)
|
||||
args, kwargs = calls[0]
|
||||
self.assertTrue(compare_user(args[0], user))
|
||||
self.assertEqual(kwargs['app'], self.app)
|
||||
self.assertTrue(compare_user(kwargs['user'], user))
|
||||
self.assertEqual(args[0], self.app)
|
||||
|
||||
def test_send_confirmation_bad_email(self):
|
||||
with capture_signals() as mocks:
|
||||
@@ -120,9 +120,9 @@ class RecoverableSignalsTests(SecurityTest):
|
||||
calls = mocks[reset_password_instructions_sent]
|
||||
self.assertEqual(len(calls), 1)
|
||||
args, kwargs = calls[0]
|
||||
self.assertTrue(compare_user(args[0]['user'], user))
|
||||
self.assertIn('token', args[0])
|
||||
self.assertEqual(kwargs['app'], self.app)
|
||||
self.assertTrue(compare_user(kwargs['user'], user))
|
||||
self.assertIn('token', kwargs)
|
||||
self.assertEqual(args[0], self.app)
|
||||
|
||||
def test_reset_password(self):
|
||||
with capture_reset_password_requests() as requests:
|
||||
@@ -137,8 +137,8 @@ class RecoverableSignalsTests(SecurityTest):
|
||||
calls = mocks[password_reset]
|
||||
self.assertEqual(len(calls), 1)
|
||||
args, kwargs = calls[0]
|
||||
self.assertTrue(compare_user(args[0], user))
|
||||
self.assertEqual(kwargs['app'], self.app)
|
||||
self.assertTrue(compare_user(kwargs['user'], user))
|
||||
self.assertEqual(args[0], self.app)
|
||||
|
||||
def test_reset_password_invalid_emails(self):
|
||||
with capture_signals() as mocks:
|
||||
@@ -233,6 +233,6 @@ class PasswordlessTests(SecurityTest):
|
||||
calls = mocks[login_instructions_sent]
|
||||
self.assertEqual(len(calls), 1)
|
||||
args, kwargs = calls[0]
|
||||
self.assertTrue(compare_user(args[0]['user'], user))
|
||||
self.assertIn('login_token', args[0])
|
||||
self.assertEqual(kwargs['app'], self.app)
|
||||
self.assertTrue(compare_user(kwargs['user'], user))
|
||||
self.assertIn('login_token', kwargs)
|
||||
self.assertEqual(args[0], self.app)
|
||||
|
||||
Reference in New Issue
Block a user