From 389d944aaff32f4e5342a018eb3c3c951addeeee Mon Sep 17 00:00:00 2001 From: Joe Hand Date: Sun, 15 Sep 2013 18:38:36 -0600 Subject: [PATCH 1/3] Add option to disable password change email. --- docs/configuration.rst | 2 ++ flask_security/changeable.py | 3 ++- flask_security/core.py | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index dc39153..1641503 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -207,6 +207,8 @@ Miscellaneous ======================================= ======================================== ``SECURITY_SEND_REGISTER_EMAIL`` Specifies whether registration email is sent. Defaults to ``True``. +``SECURITY_SEND_PASSWORD_CHANGE_EMAIL`` Specifies whether password change email is + sent. Defaults to ``True``. ``SECURITY_CONFIRM_EMAIL_WITHIN`` Specifies the amount of time a user has before their confirmation link expires. Always pluralized the time unit for this diff --git a/flask_security/changeable.py b/flask_security/changeable.py index 26f186d..2c9cf5c 100644 --- a/flask_security/changeable.py +++ b/flask_security/changeable.py @@ -28,7 +28,8 @@ def send_password_changed_notice(user): :param user: The user to send the notice to """ - send_mail(config_value('EMAIL_SUBJECT_PASSWORD_CHANGE_NOTICE'), user.email, + if config_value('SEND_PASSWORD_CHANGE_EMAIL'): + send_mail(config_value('EMAIL_SUBJECT_PASSWORD_CHANGE_NOTICE'), user.email, 'change_notice', user=user) diff --git a/flask_security/core.py b/flask_security/core.py index 692e9bf..dfb49ac 100644 --- a/flask_security/core.py +++ b/flask_security/core.py @@ -64,6 +64,7 @@ _default_config = { 'PASSWORDLESS': False, 'CHANGEABLE': False, 'SEND_REGISTER_EMAIL': True, + 'SEND_PASSWORD_CHANGE_EMAIL': True, 'LOGIN_WITHIN': '1 days', 'CONFIRM_EMAIL_WITHIN': '5 days', 'RESET_PASSWORD_WITHIN': '5 days', From 20c16107e8c6f7984eb803d461843ebf753b806a Mon Sep 17 00:00:00 2001 From: Joe Hand Date: Sun, 22 Sep 2013 09:55:07 -0600 Subject: [PATCH 2/3] Add test for 'SECURITY_SEND_PASSWORD_CHANGE_EMAIL' configuration --- tests/configured_tests.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/configured_tests.py b/tests/configured_tests.py index e2220a4..7ab132b 100644 --- a/tests/configured_tests.py +++ b/tests/configured_tests.py @@ -493,6 +493,28 @@ class ChangePasswordTest(SecurityTest): self.assertIn("/reset", outbox[0].html) +class SendEmailTest(SecurityTest): + + AUTH_CONFIG = { + 'SECURITY_SEND_REGISTER_EMAIL': False, + 'SECURITY_SEND_PASSWORD_CHANGE_EMAIL': False, + } + + + def test_change_password_success(self): + data = { + 'password': 'password', + 'new_password': 'newpassword', + 'new_password_confirm': 'newpassword' + } + + self.authenticate() + with self.app.extensions['mail'].record_messages() as outbox: + r = self._post('/change', data=data, follow_redirects=True) + + self.assertEqual(len(outbox), 0) + + class ChangePasswordPostViewTest(SecurityTest): AUTH_CONFIG = { From 55ffe2563e35cf8413d92ac65d2a19cecc8f1972 Mon Sep 17 00:00:00 2001 From: Joe Hand Date: Wed, 2 Oct 2013 08:24:27 -0600 Subject: [PATCH 3/3] Update test names and add docstring. --- tests/configured_tests.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/configured_tests.py b/tests/configured_tests.py index 7ab132b..a1213d8 100644 --- a/tests/configured_tests.py +++ b/tests/configured_tests.py @@ -493,15 +493,16 @@ class ChangePasswordTest(SecurityTest): self.assertIn("/reset", outbox[0].html) -class SendEmailTest(SecurityTest): +class EmailConfigTest(SecurityTest): AUTH_CONFIG = { 'SECURITY_SEND_REGISTER_EMAIL': False, 'SECURITY_SEND_PASSWORD_CHANGE_EMAIL': False, } + def test_change_password_success_email_option(self): + """Test the change password email can be turned off w/ configuration.""" - def test_change_password_success(self): data = { 'password': 'password', 'new_password': 'newpassword',