Skip to content

Commit

Permalink
backup of code
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-gray-tangent committed Jul 30, 2024
1 parent d40364a commit c3bc5af
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 38 deletions.
25 changes: 1 addition & 24 deletions app/accounts/service/active_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ def send_activation_email(request, user):
current_site = get_current_site(request)
mail_subject = "Activate your account."
message = render_to_string(
"accounts/email/activation_reset_email.html",
"accounts/email/activation_email.html",
{
"user": user,
"domain": current_site.domain,
"uid": urlsafe_base64_encode(force_bytes(user.pk)),
"token": account_activation_token.make_token(user),
"email_type": "activation",
},
)
text_content = (
Expand All @@ -33,25 +32,3 @@ def send_activation_email(request, user):
)
email.attach_alternative(message, "text/html")
email.send()

# def send_password_reset_email(user):
# if user:
# # current_site = get_current_site(request)
# mail_subject = "Activate your account."
# message = render_to_string(
# "accounts/email/activation_email.html",
# {
# "user": user,
# "domain": "",
# "uid": urlsafe_base64_encode(force_bytes(user.pk)),
# "token": account_activation_token.make_token(user),
# },
# )
# text_content = (
# "Please activate your account by clicking the link provided in the email."
# )
# email = EmailMultiAlternatives(
# mail_subject, text_content, os.environ.get("DEFAULT_FROM_EMAIL"), [user.email]
# )
# email.attach_alternative(message, "text/html")
# email.send()
6 changes: 1 addition & 5 deletions app/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
urlpatterns = [
path("register/", views.register, name="accounts_register"),
path("login/", auth_views.LoginView.as_view(template_name="accounts/login.html"), name="login"),
path(
"password_reset/",
CustomPasswordResetView.as_view(),
name="password_reset",
),
path("password_reset/", CustomPasswordResetView.as_view(), name="password_reset"),
path(
"password_reset/done/",
auth_views.PasswordResetDoneView.as_view(template_name="accounts/password_reset_done.html"),
Expand Down
18 changes: 15 additions & 3 deletions app/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.contrib.auth import login as auth_login
from django.contrib.auth.views import PasswordResetView
from django.shortcuts import redirect, render
from django.urls import reverse_lazy
from django.utils.encoding import force_str
from django.utils.http import urlsafe_base64_decode

Expand Down Expand Up @@ -88,8 +89,19 @@ def resend_activation(request):


class CustomPasswordResetView(PasswordResetView):
"""
This class represents a custom password reset view for user accounts.
Attributes:
form_class (CustomPasswordResetForm): The form class for the password reset form.
template_name (str): The name of the template for rendering the password reset form.
success_url (reverse_lazy): The URL to redirect to after a successful password reset.
html_email_template_name (str): The name of the template for sending the password reset email.
"""

form_class = CustomPasswordResetForm
template_name = "accounts/password_reset_form.html"
success_url = "/accounts/password_reset/done/"
# html_email_template_name = "registration/password_reset_email.html"
html_email_template_name = "accounts/email/activation_reset_email.html"
success_url = reverse_lazy("accounts:password_reset_done")
html_email_template_name = "registration/password_reset_email.html"
10 changes: 5 additions & 5 deletions app/templates/accounts/email/activation_reset_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<body>
{% if email_type == 'activation' %}
<div class="container">
<h1>Activate Your Account - Single Email</h1>
<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>
Expand All @@ -65,14 +65,14 @@ <h1>Activate Your Account - Single Email</h1>
</div>
{% else %}
<div class="container">
<h1>Password Reset</h1>
<h1>Password Reset - new email</h1>
<p>Hello {{ user.get_username }},</p>
<p>You requested a password reset. Click the button below to reset your password:</p>
<p>
<a href="{{ protocol }}://{{ domain }}{% url 'accounts:password_reset_confirm' uidb64=uid token=token %}"
class="button">
Reset my password
</a>
class="button">
Reset my password
</a>
</p>
<p>If you didn't request this, please ignore this email.</p>
<p>Thanks,</p>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/registration/password_reset_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ <h1>Password Reset</h1>
<p>Your website team</p>
</div>
</body>
</html>
</html>

0 comments on commit c3bc5af

Please sign in to comment.