Skip to content

Commit

Permalink
updates password reset email with expiry time variable
Browse files Browse the repository at this point in the history
  • Loading branch information
reecehill committed Apr 3, 2024
1 parent 8a70c64 commit 2ad9f3a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions envs/env-template
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ EMAIL_HOST_SERVER= # hostname of SMTP service
EMAIL_HOST_USER= # username for SMTP service
# To output emails to console, set SMTP_EMAIL_ENABLED=False
SMTP_EMAIL_ENABLED=True # To output emails to console, set SMTP_EMAIL_ENABLED=False
# Password reset link expires after (in seconds)
PASSWORD_RESET_TIMEOUT=259200


# HERMES (SNOMED CT)
RCPCH_HERMES_SERVER_URL= # SNOMED server API URL
Expand Down
3 changes: 3 additions & 0 deletions epilepsy12/views/user_management_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# Other dependencies
from two_factor.views import LoginView as TwoFactorLoginView
import pandas as pd
from datetime import datetime, timedelta

# epilepsy12
from ..models import Epilepsy12User, Organisation, VisitActivity, Site
Expand Down Expand Up @@ -563,6 +564,8 @@ class ResetPasswordView(SuccessMessageMixin, PasswordResetView):
" If you don't receive an email, "
"please make sure you've entered the address you registered with, and check your spam folder."
)
extra_email_context= {
"reset_password_link_expires_at": datetime.now() + timedelta(seconds=settings.PASSWORD_RESET_TIMEOUT) }
success_url = reverse_lazy("index")

# extend form_valid to set user.password_last_set
Expand Down
3 changes: 2 additions & 1 deletion rcpch-audit-engine/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.admindocs",
"django.contrib.humanize",
"rest_framework",
"whitenoise.runserver_nostatic",
"django.contrib.staticfiles",
Expand Down Expand Up @@ -239,7 +240,7 @@
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
logger.info("EMAIL_BACKEND: %s", EMAIL_BACKEND)

PASSWORD_RESET_TIMEOUT = 259200 # Default: 259200 (3 days, in seconds)
PASSWORD_RESET_TIMEOUT = os.environ.get("PASSWORD_RESET_TIMEOUT", 259200) # Default: 259200 (3 days, in seconds)

SITE_CONTACT_EMAIL = os.environ.get("SITE_CONTACT_EMAIL")

Expand Down
3 changes: 2 additions & 1 deletion templates/registration/password_reset_email.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% load epilepsy12_template_tags %}
{% load static %}
{% load humanize %}
{% autoescape on %}
<div class="indent" style="display: relative; width: 80%; margin: auto;">
<div class="centered" style="width: 50%; margin: auto;">
Expand All @@ -19,7 +20,7 @@
<p style="font-family: 'Montserrat', sans-serif;">If you did not make this request, please
<a href="mailto:{% site_contact_email %}">contact the RCPCH Epilepsy12 team.</a>
</p>
<p style="font-family: 'Montserrat', sans-serif;">Please note that this link will expire in 72 hours</p>
<p style="font-family: 'Montserrat', sans-serif;">Please note that this link will expire in <b>{{ reset_password_link_expires_at|naturaltime }}</b></p>
<p>
To request a new link, go to
<a href="{{ protocol }}://{{ domain }}{% url 'password_reset'%}">
Expand Down

0 comments on commit 2ad9f3a

Please sign in to comment.