|
| 1 | +# symfexit/root/views.py |
| 2 | +from django.contrib.auth.forms import PasswordResetForm |
| 3 | +from django.contrib.auth.tokens import default_token_generator |
| 4 | +from django.contrib.auth.views import PasswordResetView |
| 5 | +from django.urls import reverse |
| 6 | +from django.utils.encoding import force_bytes |
| 7 | +from django.utils.http import urlsafe_base64_encode |
| 8 | + |
| 9 | +from symfexit.emails._templates.emails.password_request import PasswordResetEmail |
| 10 | +from symfexit.emails._templates.render import send_email |
| 11 | +from symfexit.members.admin import Member |
| 12 | + |
| 13 | + |
| 14 | +class MyPasswordResetForm(PasswordResetForm): |
| 15 | + def send_mail( |
| 16 | + self, |
| 17 | + subject_template_name, |
| 18 | + email_template_name, |
| 19 | + context, |
| 20 | + from_email, |
| 21 | + to_email, |
| 22 | + html_email_template_name=None, |
| 23 | + ): |
| 24 | + # context = { |
| 25 | + # "email": user_email, |
| 26 | + # "domain": domain, |
| 27 | + # "site_name": site_name, |
| 28 | + # "uid": urlsafe_base64_encode(user_pk_bytes), |
| 29 | + # "user": user, |
| 30 | + # "token": token_generator.make_token(user), |
| 31 | + # "protocol": "https" if use_https else "http", |
| 32 | + # **(extra_email_context or {}), |
| 33 | + # } |
| 34 | + user: Member = context["user"] |
| 35 | + reset_path = reverse( |
| 36 | + "password_reset_confirm", # your URL‑conf name |
| 37 | + kwargs={ |
| 38 | + "uidb64": urlsafe_base64_encode(force_bytes(user.pk)), |
| 39 | + "token": default_token_generator.make_token(user), |
| 40 | + }, |
| 41 | + ) |
| 42 | + |
| 43 | + # # Prepend scheme+host to make a full absolute URL |
| 44 | + reset_url = f"{context['protocol']}://{context['domain']}{reset_path}" |
| 45 | + send_email( |
| 46 | + PasswordResetEmail( |
| 47 | + { |
| 48 | + "firstname": user.first_name, |
| 49 | + "url": reset_url, |
| 50 | + "email": user.email, |
| 51 | + } |
| 52 | + ), |
| 53 | + recipient_list=[to_email], |
| 54 | + ) |
| 55 | + |
| 56 | + |
| 57 | +class CustomPasswordResetView(PasswordResetView): |
| 58 | + form_class = MyPasswordResetForm |
0 commit comments