Skip to content

Commit

Permalink
added email base class and updated account user form
Browse files Browse the repository at this point in the history
clean up code code
  • Loading branch information
daniel-gray-tangent committed Jul 30, 2024
1 parent 69b5fb3 commit 226cad4
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 127 deletions.
14 changes: 8 additions & 6 deletions app/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
77 changes: 17 additions & 60 deletions app/templates/accounts/email/activation_email.html
Original file line number Diff line number Diff line change
@@ -1,60 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Activate Your Account</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
width: 100%;
max-width: 600px;
margin: 0 auto;
background-color: #ffffff;
padding: 20px;
border: 1px solid #dddddd;
}
h1 {
color: #333333;
}
p {
color: #666666;
}
a {
color: #1a73e8;
text-decoration: none;
}
.button {
display: inline-block;
padding: 10px 20px;
background-color: #1a73e8;
color: #ffffff;
text-align: center;
border-radius: 5px;
text-decoration: none;
}
.button:hover {
background-color: #1558b0;
}
</style>
</head>
<body>
<div class="container">
<h1>Activate Your Account</h1>
<p>Hi {{ user.username }},</p>
<p>Thank you for signing up for our service. Please click the link below to activate your account:</p>
<p>
<a href="http://{{ domain }}{% url 'accounts:activate' uidb64=uid token=token %}" class="button">
Activate your account
</a>
</p>
<p>If you did not sign up for this account, please ignore this email.</p>
<p>Thank you,</p>
<p>The Team</p>
</div>
</body>
</html>
{% extends "email_base.html" %}

{% block title %}Activate Your Account{% endblock %}

{% block content %}
<h1>Activate Your Account</h1>
<p>Hi {{ user.username }},</p>
<p>Thank you for signing up for our service. Please click the link below to activate your account:</p>
<p>
<a href="http://{{ domain }}{% url 'accounts:activate' uidb64=uid token=token %}" class="button">
Activate your account
</a>
</p>
<p>If you did not sign up for this account, please ignore this email.</p>
<p>Thank you,</p>
<p>The Team</p>
{% endblock %}
11 changes: 3 additions & 8 deletions app/templates/app/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ <h5 class="card-title">{% trans "Search a term" %}</h5>
<br>
<div class="container">
{% for result in search_results %}
<hr>
{{ result }}
<hr>


<div>
<h2><a href="{% url result.view result.id %}">{{ result.heading }}</a></h2>
<p>{{ result.description | truncatewords:10 }}</p>
Expand All @@ -38,7 +33,7 @@ <h2><a href="{% url result.view result.id %}">{{ result.heading }}</a></h2>
{% endif %}
</p>
<p>
<span><i>{{ result.rank }}</i></span>
<span><i>{{ result.rank }}</i></span>
</p>
</div>
{% endfor %}
Expand All @@ -52,8 +47,8 @@ <h2><a href="{% url result.view result.id %}">{{ result.heading }}</a></h2>
<a href="{{ search_params }}&page={{ documents.previous_page_number }}">&lt; previous</a>
{% endif %}
<span class="current">
Page {{ documents.number }} of {{ documents.paginator.num_pages }}.
</span>
Page {{ documents.number }} of {{ documents.paginator.num_pages }}.
</span>
{% if documents.has_next %}
<a href="{{ search_params }}&page={{ documents.next_page_number }}">next &gt;</a>
<a href="{{ search_params }}&page={{ documents.paginator.num_pages }}">last
Expand Down
50 changes: 50 additions & 0 deletions app/templates/email_base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}Email{% endblock %}</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
width: 100%;
max-width: 600px;
margin: 0 auto;
background-color: #ffffff;
padding: 20px;
border: 1px solid #dddddd;
}
h1 {
color: #333333;
}
p {
color: #666666;
}
a {
color: #1a73e8;
text-decoration: none;
}
.button {
display: inline-block;
padding: 10px 20px;
background-color: #1a73e8;
color: #ffffff;
text-align: center;
border-radius: 5px;
text-decoration: none;
}
.button:hover {
background-color: #1558b0;
}
</style>
</head>
<body>
<div class="container">
{% block content %}{% endblock %}
</div>
</body>
</html>
57 changes: 4 additions & 53 deletions app/templates/registration/password_reset_email.html
Original file line number Diff line number Diff line change
@@ -1,55 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Password Reset</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
{% extends "email_base.html" %}

.container {
width: 100%;
max-width: 600px;
margin: 0 auto;
background-color: #ffffff;
padding: 20px;
border: 1px solid #dddddd;
}
{% block title %}Activate Your Account{% endblock %}

h1 {
color: #333333;
}

p {
color: #666666;
}

a {
color: #1a73e8;
text-decoration: none;
}

.button {
display: inline-block;
padding: 10px 20px;
background-color: #1a73e8;
color: #ffffff;
text-align: center;
border-radius: 5px;
text-decoration: none;
}

.button:hover {
background-color: #1558b0;
}
</style>
</head>
<body>
<div class="container">
{% block content %}
<h1>Password Reset</h1>

<p>Hello {{ user.get_username }},</p>
Expand All @@ -63,6 +16,4 @@ <h1>Password Reset</h1>
<p>If you didn't request this, please ignore this email.</p>
<p>Thanks,</p>
<p>Your website team</p>
</div>
</body>
</html>
{% endblock %}

0 comments on commit 226cad4

Please sign in to comment.