Skip to content

Commit d424808

Browse files
Merge branch 'main' into my-branch
2 parents 6f289b5 + ef01ce7 commit d424808

17 files changed

Lines changed: 89 additions & 16 deletions

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Features & Improvements
1919
- (:issue:`1237`) Add support for CSRF on logout
2020
- (:pr:`1241`) Convert all _WITHIN configuration variable to use timedelta
2121
- (:issue:`1153`) Enable localization of %(within)s variables using humanize
22+
- (:pr:`xx`) Add link expiration to confirmation and reset password email templates
2223

2324
Fixes
2425
+++++

docs/configuration.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,13 @@ Confirmable
10791079
Sets the subject for the email confirmation message.
10801080

10811081
Default: ``_("Please confirm your email")``.
1082+
.. py:data:: SECURITY_EMAIL_TEMPLATE_CONFIRM
1083+
1084+
Specifies the path to the template for the email send confirmation instructions.
1085+
1086+
Default: ``"confirmation_instructions"``.
1087+
1088+
.. versionadded:: 5.9.0
10821089
.. py:data:: SECURITY_CONFIRM_ERROR_VIEW
10831090
10841091
Specifies the view to redirect to if a confirmation error occurs.
@@ -1253,6 +1260,14 @@ Recoverable
12531260

12541261
Default: ``_("Password reset instructions")``.
12551262

1263+
.. py:data:: SECURITY_EMAIL_TEMPLATE_PASSWORD_RESET
1264+
1265+
Specifies the path to the template for the email send password reset instructions.
1266+
1267+
Default: ``"reset_instructions"``.
1268+
1269+
.. versionadded:: 5.9.0
1270+
12561271
.. py:data:: SECURITY_EMAIL_SUBJECT_PASSWORD_NOTICE
12571272
12581273
Sets subject for the password notice.
@@ -1273,6 +1288,13 @@ Change-Email
12731288
Sets the subject for the change email confirmation email.
12741289

12751290
Default: ``_("Confirm your new email address")``.
1291+
.. py:data:: SECURITY_CHANGE_EMAIL_EMAIL_TEMPLATE
1292+
1293+
Specifies the path to the template for the change email email instructions.
1294+
1295+
Default: ``"change_email_instructions"``.
1296+
1297+
.. versionadded:: 5.9.0
12761298
.. py:data:: SECURITY_CHANGE_EMAIL_TEMPLATE
12771299
12781300
Specifies the path to the template for the change email page.

flask_security/change_email.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def _send_instructions(user, new_email):
183183
send_mail(
184184
cv("CHANGE_EMAIL_SUBJECT"),
185185
new_email,
186-
"change_email_instructions",
186+
cv("CHANGE_EMAIL_EMAIL_TEMPLATE"),
187187
user=user,
188188
link=link,
189189
token=token,

flask_security/confirmable.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
url_for_security,
2222
check_and_get_token_status,
2323
verify_hash,
24+
td_format,
2425
)
2526

2627

@@ -40,10 +41,11 @@ def send_confirmation_instructions(user):
4041
send_mail(
4142
cv("EMAIL_SUBJECT_CONFIRM"),
4243
user.email,
43-
"confirmation_instructions",
44+
cv("EMAIL_TEMPLATE_CONFIRM"),
4445
user=user,
4546
confirmation_link=confirmation_link,
4647
confirmation_token=token,
48+
within=td_format(cv("CONFIRM_EMAIL_WITHIN")),
4749
)
4850

4951
confirm_instructions_sent.send(

flask_security/core.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@
251251
"POST_CHANGE_EMAIL_VIEW": None, # spa
252252
"CHANGE_EMAIL_SALT": "change-email-salt",
253253
"CHANGE_EMAIL_SUBJECT": _("Confirm your new email address"),
254+
"CHANGE_EMAIL_EMAIL_TEMPLATE": "change_email_instructions",
254255
"CHANGE_USERNAME": False,
255256
"CHANGE_USERNAME_TEMPLATE": "security/change_username.html",
256257
"CHANGE_USERNAME_URL": "/change-username",
@@ -330,6 +331,8 @@
330331
"EMAIL_HTML": True,
331332
"EMAIL_SUBJECT_TWO_FACTOR": _("Two-Factor Login"),
332333
"EMAIL_SUBJECT_TWO_FACTOR_RESCUE": _("Two-Factor Rescue"),
334+
"EMAIL_TEMPLATE_CONFIRM": "confirmation_instructions",
335+
"EMAIL_TEMPLATE_PASSWORD_RESET": "reset_instructions",
333336
"USER_IDENTITY_ATTRIBUTES": [
334337
{"email": {"mapper": uia_email_mapper, "case_insensitive": True}}
335338
],

flask_security/recoverable.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
hash_password,
2424
send_mail,
2525
url_for_security,
26+
td_format,
2627
)
2728

2829

@@ -42,10 +43,11 @@ def send_reset_password_instructions(user):
4243
send_mail(
4344
cv("EMAIL_SUBJECT_PASSWORD_RESET"),
4445
user.email,
45-
"reset_instructions",
46+
cv("EMAIL_TEMPLATE_PASSWORD_RESET"),
4647
user=user,
4748
reset_link=reset_link,
4849
reset_token=token,
50+
within=td_format(cv("RESET_PASSWORD_WITHIN")),
4951
)
5052

5153
reset_password_instructions_sent.send(

flask_security/templates/security/email/confirmation_instructions.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
confirmation_token - this token is part of confirmation link - but can be used to
44
construct arbitrary URLs for redirecting.
55
user - the entire user model object
6+
within - formatted expiration of link
67
security - the Flask-Security configuration
78
#}
89
<p>{{ _fsdomain('Use <a href="%(confirmation_link)s">this link</a> to confirm your email address.', confirmation_link=confirmation_link)|safe }}</p>
10+
<p>{{ _fsdomain('This link will expire in %(within)s.', within=within) }}</p>

flask_security/templates/security/email/confirmation_instructions.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
confirmation_token - this token is part of confirmation link - but can be used to
44
construct arbitrary URLs for redirecting.
55
user - the entire user model object
6+
within - formatted expiration of link
67
security - the Flask-Security configuration
78
#}
89
{{ _fsdomain('Use %(confirmation_link)s to confirm your email address.', confirmation_link=confirmation_link)|safe }}
10+
{{ _fsdomain('This link will expire in %(within)s.', within=within) }}

flask_security/templates/security/email/reset_instructions.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
reset_token - this token is part of reset link - but can be used to
44
construct arbitrary URLs for redirecting.
55
user - the entire user model object
6+
within - formatted expiration of link
67
security - the Flask-Security configuration
78
#}
8-
<p>
9-
<a href="{{ reset_link }}">{{ _fsdomain('Click here to reset your password') }}</a>
10-
</p>
9+
<p>{{ _fsdomain('Use <a href="%(reset_link)s">this link</a> to reset your password.', reset_link=reset_link)|safe }}</p>
10+
<p>{{ _fsdomain('This link will expire in %(within)s.', within=within) }}</p>

flask_security/templates/security/email/reset_instructions.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
reset_token - this token is part of reset link - but can be used to
44
construct arbitrary URLs for redirecting.
55
user - the entire user model object
6+
within - formatted expiration of link
67
security - the Flask-Security configuration
78
#}
8-
{{ _fsdomain('Click the link below to reset your password:') }}
9-
10-
{{ reset_link }}
9+
{{ _fsdomain('Use %(reset_link)s to reset your password.', reset_link=reset_link)|safe }}
10+
{{ _fsdomain('This link will expire in %(within)s.', within=within) }}

0 commit comments

Comments
 (0)