From f3151c25ce2494355641f67b350462c7f91f6339 Mon Sep 17 00:00:00 2001 From: Daniel Gray Date: Tue, 30 Jul 2024 15:32:25 +0200 Subject: [PATCH] added email base class and updated account user form --- app/accounts/forms.py | 14 ++-- .../accounts/email/activation_email.html | 77 ++++--------------- app/templates/email_base.html | 50 ++++++++++++ .../registration/password_reset_email.html | 57 +------------- 4 files changed, 79 insertions(+), 119 deletions(-) create mode 100644 app/templates/email_base.html diff --git a/app/accounts/forms.py b/app/accounts/forms.py index 7c84f221..2a4a966e 100644 --- a/app/accounts/forms.py +++ b/app/accounts/forms.py @@ -69,14 +69,16 @@ def clean_email(self): The "clean_email" method is overridden to ensure that only active staff members can reset their passwords. This is done to prevent unauthorized users from resetting their passwords and gaining access to the system. and prevent users getting an email to reset their password if they are not active or staff members. """ + User = get_user_model() email = self.cleaned_data["email"] - users = User.objects.filter(email=email) - if not users.exists(): - raise forms.ValidationError("There is a error please contact the administrator.") - for user in users: - if not user.is_active or not user.is_staff: - raise forms.ValidationError("There is a error please contact the administrator.") + try: + user = User.objects.get(email=email) + except User.DoesNotExist: + raise forms.ValidationError("There is an error please contact the administrator.") + + if not user.is_active or not user.is_staff: + raise forms.ValidationError("There is an error please contact the administrator.") return email diff --git a/app/templates/accounts/email/activation_email.html b/app/templates/accounts/email/activation_email.html index afa50e9b..3c567091 100644 --- a/app/templates/accounts/email/activation_email.html +++ b/app/templates/accounts/email/activation_email.html @@ -1,60 +1,17 @@ - - - - - Activate Your Account - - - -
-

Activate Your Account

-

Hi {{ user.username }},

-

Thank you for signing up for our service. Please click the link below to activate your account:

-

- - Activate your account - -

-

If you did not sign up for this account, please ignore this email.

-

Thank you,

-

The Team

-
- - +{% extends "email_base.html" %} + +{% block title %}Activate Your Account{% endblock %} + +{% block content %} +

Activate Your Account

+

Hi {{ user.username }},

+

Thank you for signing up for our service. Please click the link below to activate your account:

+

+ + Activate your account + +

+

If you did not sign up for this account, please ignore this email.

+

Thank you,

+

The Team

+{% endblock %} diff --git a/app/templates/email_base.html b/app/templates/email_base.html new file mode 100644 index 00000000..49532587 --- /dev/null +++ b/app/templates/email_base.html @@ -0,0 +1,50 @@ + + + + + {% block title %}Email{% endblock %} + + + +
+ {% block content %}{% endblock %} +
+ + diff --git a/app/templates/registration/password_reset_email.html b/app/templates/registration/password_reset_email.html index 88bafad8..c17023d1 100644 --- a/app/templates/registration/password_reset_email.html +++ b/app/templates/registration/password_reset_email.html @@ -1,55 +1,8 @@ - - - - - Password Reset - - - -
+{% block content %}

Password Reset

Hello {{ user.get_username }},

@@ -63,6 +16,4 @@

Password Reset

If you didn't request this, please ignore this email.

Thanks,

Your website team

-
- - +{% endblock %}