/
password_reset_form.py
61 lines (51 loc) · 1.8 KB
/
password_reset_form.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from __future__ import annotations
import logging
from typing import TYPE_CHECKING
from django import forms
from django.conf import settings
from django.contrib.auth.forms import PasswordResetForm
from django.utils.translation import gettext_lazy as _
from ...utils.email_utils import send_mail
if TYPE_CHECKING:
from typing import Any
logger = logging.getLogger(__name__)
class CustomPasswordResetForm(PasswordResetForm):
"""
A custom form to attach the logo to the password reset email
"""
email = forms.EmailField(
label=_("Email"),
max_length=254,
widget=forms.EmailInput(attrs={"autocomplete": "email"}),
)
# pylint: disable=signature-differs
def send_mail(
self,
subject_template_name: str,
email_template_name: str,
context: dict[str, Any],
from_email: Any | None,
to_email: str,
html_email_template_name: str,
) -> None:
"""
Send a django.core.mail.EmailMultiAlternatives to `to_email`.
:param subject_template_name: The template to be used to render the subject of the email
:param email_template_name: The template to be used to render the text email
:param context: The template context variables
:param from_email: The email address of the sender
:param to_email: The email address of the recipient
:param html_email_template_name: The template to be used to render the HTML email
"""
subject = f"{settings.BRANDING_TITLE} - {_('Reset password')}"
send_mail(
subject,
email_template_name,
html_email_template_name,
context,
to_email,
)
logger.info(
"A password reset link was sent to email %r.",
to_email,
)