From 514d27fd667ad6dfd7b8de9ae3a4548a6b1dd6cb Mon Sep 17 00:00:00 2001 From: Anthony Plunkett Date: Mon, 19 Nov 2012 21:13:52 -0500 Subject: [PATCH] Ability to manage email subjects from configuration. --- docs/configuration.rst | 21 +++++++++++++++++++++ flask_security/confirmable.py | 5 +++-- flask_security/core.py | 7 ++++++- flask_security/passwordless.py | 5 +++-- flask_security/recoverable.py | 6 +++--- flask_security/registerable.py | 5 +++-- 6 files changed, 39 insertions(+), 10 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index ab28904..5b00c91 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -129,6 +129,27 @@ Feature Flags to ``False``. ========================= ====================================================== +Email +---------- + +.. tabularcolumns:: |p{6.5cm}|p{8.5cm}| + +=========================================== ==================================== +``SECURITY_EMAIL_SUBJECT_REGISTER`` Sets the subject for the + confirmation email. Defaults to + ``Welcome`` +``SECURITY_EMAIL_SUBJECT_PASSWORDLESS`` Sets the subject for the + passwordless feature. Defaults to + ``Login instructions`` +``SECURITY_EMAIL_SUBJECT_PASSWORD_NOTICE`` Sets subject for the password + notice. Defaults to + ``Your password has been reset`` +``SECURITY_EMAIL_SUBJECT_PASSWORD_RESET`` Sets the subject for the password + reset. Defaults to + ``Password reset instructions`` +``SECURITY_EMAIL_SUBJECT_CONFIRM`` Sets the subject for the email + confirmation message. Defaults to + ``Please confirm your email`` Miscellaneous ------------- diff --git a/flask_security/confirmable.py b/flask_security/confirmable.py index d53c0a3..65842e7 100644 --- a/flask_security/confirmable.py +++ b/flask_security/confirmable.py @@ -14,7 +14,8 @@ from datetime import datetime from flask import current_app as app, request from werkzeug.local import LocalProxy -from .utils import send_mail, md5, url_for_security, get_token_status +from .utils import send_mail, md5, url_for_security, get_token_status,\ + config_value from .signals import user_confirmed, confirm_instructions_sent @@ -39,7 +40,7 @@ def send_confirmation_instructions(user): confirmation_link, token = generate_confirmation_link(user) - send_mail('Please confirm your email', user.email, + send_mail(config_value('EMAIL_SUBJECT_CONFIRM'), user.email, 'confirmation_instructions', user=user, confirmation_link=confirmation_link) diff --git a/flask_security/core.py b/flask_security/core.py index 8d449cd..94d60c8 100644 --- a/flask_security/core.py +++ b/flask_security/core.py @@ -61,7 +61,12 @@ _default_config = { 'RESET_SALT': 'reset-salt', 'LOGIN_SALT': 'login-salt', 'REMEMBER_SALT': 'remember-salt', - 'DEFAULT_HTTP_AUTH_REALM': 'Login Required' + 'DEFAULT_HTTP_AUTH_REALM': 'Login Required', + 'EMAIL_SUBJECT_REGISTER': 'Welcome', + 'EMAIL_SUBJECT_CONFIRM': 'Please confirm your email', + 'EMAIL_SUBJECT_PASSWORDLESS': 'Login instructions', + 'EMAIL_SUBJECT_PASSWORD_NOTICE': 'Your password has been reset', + 'EMAIL_SUBJECT_PASSWORD_RESET': 'Password reset instructions' } #: Default Flask-Security messages diff --git a/flask_security/passwordless.py b/flask_security/passwordless.py index 7a9e001..d6cd518 100644 --- a/flask_security/passwordless.py +++ b/flask_security/passwordless.py @@ -13,7 +13,8 @@ from flask import request, current_app as app from werkzeug.local import LocalProxy from .signals import login_instructions_sent -from .utils import send_mail, url_for_security, get_token_status +from .utils import send_mail, url_for_security, get_token_status, \ + config_value # Convenient references @@ -32,7 +33,7 @@ def send_login_instructions(user): url = url_for_security('token_login', token=token) login_link = request.url_root[:-1] + url - send_mail('Login Instructions', user.email, + 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), diff --git a/flask_security/recoverable.py b/flask_security/recoverable.py index 5138680..deacf23 100644 --- a/flask_security/recoverable.py +++ b/flask_security/recoverable.py @@ -14,7 +14,7 @@ from werkzeug.local import LocalProxy from .signals import password_reset, reset_password_instructions_sent from .utils import send_mail, md5, encrypt_password, url_for_security, \ - get_token_status + get_token_status, config_value # Convenient references @@ -32,7 +32,7 @@ def send_reset_password_instructions(user): url = url_for_security('reset_password', token=token) reset_link = request.url_root[:-1] + url - send_mail('Password reset instructions', user.email, + send_mail(config_value('EMAIL_SUBJECT_PASSWORD_RESET'), user.email, 'reset_instructions', user=user, reset_link=reset_link) @@ -45,7 +45,7 @@ def send_password_reset_notice(user): :param user: The user to send the notice to """ - send_mail('Your password has been reset', user.email, + send_mail(config_value('EMAIL_SUBJECT_PASSWORD_NOTICE'), user.email, 'reset_notice', user=user) diff --git a/flask_security/registerable.py b/flask_security/registerable.py index 2e29af1..fc07574 100644 --- a/flask_security/registerable.py +++ b/flask_security/registerable.py @@ -14,7 +14,8 @@ from werkzeug.local import LocalProxy from .confirmable import generate_confirmation_link from .signals import user_registered -from .utils import do_flash, get_message, send_mail, encrypt_password +from .utils import do_flash, get_message, send_mail, encrypt_password, \ + config_value # Convenient references _security = LocalProxy(lambda: app.extensions['security']) @@ -35,7 +36,7 @@ def register_user(**kwargs): user_registered.send(dict(user=user, confirm_token=token), app=app._get_current_object()) - send_mail('Welcome', user.email, 'welcome', + send_mail(config_value('EMAIL_SUBJECT_REGISTER'), user.email, 'welcome', user=user, confirmation_link=confirmation_link) return user