[Django] #17431: Allow PasswordResetForm subclasses full control over email message to send

35 views
Skip to first unread message

Django

unread,
Dec 17, 2011, 3:39:05 PM12/17/11
to django-...@googlegroups.com
#17431: Allow PasswordResetForm subclasses full control over email message to send
------------------------------+--------------------
Reporter: ejucovy | Owner: nobody
Type: New feature | Status: new
Component: contrib.auth | Version: SVN
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------
The `django.contrib.auth.forms.PasswordResetForm` has logic to:

1. Validate that an active user exists with the email address provided
1. Generate an unguessable URL for the given user to reset his password
using a timestamped token
1. Construct an email with a link to that URL
1. Send that email to the given user's email address

The `.save()` method of the form class is responsible for three of these
four tasks. The `.save()` method includes parameters for overriding the
subject, body, and `From:` address of the email to be sent. However, it's
sometimes necessary to have more control over the email that will be sent.
These use cases could include:

1. BCC'ing a site administrator with a copy of the email sent
1. Setting a custom `Reply-To` like "password-...@example.com" that
is distinct from the message's `From:` address
1. Setting a `text/html` MIME type for the message, or using an
`EmailMultiAlternatives` object to attach both text and HTML versions of
the message

For all of these use cases, the knobs currently provided are insufficient,
and require copying over all the logic in the `.save()` method.

The attached patch satisfies these use cases by allowing the user to
subclass PasswordResetForm and override a `.construct_email()` method,
whose job is to construct and return an `EmailMessage` to be sent by the
`.save()` method. The changes are fully backwards-compatible, and a test
demonstrating the subclassing approach is provided.

--
Ticket URL: <https://code.djangoproject.com/ticket/17431>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 24, 2011, 9:50:22 AM12/24/11
to django-...@googlegroups.com
#17431: Allow PasswordResetForm subclasses full control over email message to send
------------------------------+------------------------------------
Reporter: ejucovy | Owner: nobody
Type: New feature | Status: new
Component: contrib.auth | Version: SVN
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by aaugustin):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/17431#comment:1>

Django

unread,
Feb 7, 2012, 12:58:35 PM2/7/12
to django-...@googlegroups.com
#17431: Allow PasswordResetForm subclasses full control over email message to send
------------------------------+------------------------------------
Reporter: ejucovy | Owner: nobody
Type: New feature | Status: new
Component: contrib.auth | Version: SVN
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------

Comment (by anonymous):

My need is to include an additional variable in the context that is used
to render the email template. I don't see that the patch provided supports
that use case?

--
Ticket URL: <https://code.djangoproject.com/ticket/17431#comment:2>

Django

unread,
Feb 7, 2012, 1:17:56 PM2/7/12
to django-...@googlegroups.com
#17431: Allow PasswordResetForm subclasses full control over email message to send
------------------------------+------------------------------------
Reporter: ejucovy | Owner: nobody
Type: New feature | Status: new
Component: contrib.auth | Version: SVN
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------

Comment (by ejucovy):

Replying to [comment:2 anonymous]:

> My need is to include an additional variable in the context that is used
to render the email template. I don't see that the patch provided supports
that use case?

Where will your extra context variable be coming from?

If it's something that you can derive without access to a request, then
you can just inject it into the context in your overridden
`construct_email` method. Likewise if it's something derived from
`request.POST` then `self.data` will contain the full POSTed form, and you
can inject your needed variable in `construct_email`.

--
Ticket URL: <https://code.djangoproject.com/ticket/17431#comment:3>

Django

unread,
May 9, 2012, 4:33:45 PM5/9/12
to django-...@googlegroups.com
#17431: Allow PasswordResetForm subclasses full control over email message to send
------------------------------+------------------------------------
Reporter: ejucovy | Owner: nobody
Type: New feature | Status: new
Component: contrib.auth | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------

Comment (by aaugustin):

#12684 was a duplicate.

--
Ticket URL: <https://code.djangoproject.com/ticket/17431#comment:4>

Django

unread,
Dec 13, 2012, 9:05:03 AM12/13/12
to django-...@googlegroups.com
#17431: Allow PasswordResetForm subclasses full control over email message to send
------------------------------+------------------------------------

Reporter: ejucovy | Owner: nobody
Type: New feature | Status: new
Component: contrib.auth | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------

Comment (by revolunet):

Thanks ejucovy

+1 on this;

we definitely need to have full control on the sent email template and
context.

--
Ticket URL: <https://code.djangoproject.com/ticket/17431#comment:5>

Django

unread,
Aug 5, 2013, 12:50:35 PM8/5/13
to django-...@googlegroups.com
#17431: Allow PasswordResetForm subclasses full control over email message to send
------------------------------+------------------------------------

Reporter: ejucovy | Owner: nobody
Type: New feature | Status: new
Component: contrib.auth | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by timo):

* cc: timograham@… (added)
* needs_better_patch: 0 => 1


Comment:

Patch needs to be updated to apply cleanly.

--
Ticket URL: <https://code.djangoproject.com/ticket/17431#comment:6>

Django

unread,
May 8, 2014, 6:00:41 PM5/8/14
to django-...@googlegroups.com
#17431: Allow PasswordResetForm subclasses full control over email message to send
------------------------------+------------------------------------------
Reporter: ejucovy | Owner: jorgecarleitao
Type: New feature | Status: assigned

Component: contrib.auth | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------------
Changes (by jorgecarleitao):

* owner: nobody => jorgecarleitao
* cc: jorgecarleitao (added)
* status: new => assigned


Comment:

Pull request https://github.com/django/django/pull/2642

--
Ticket URL: <https://code.djangoproject.com/ticket/17431#comment:7>

Django

unread,
May 9, 2014, 3:23:22 AM5/9/14
to django-...@googlegroups.com
#17431: Allow PasswordResetForm subclasses full control over email message to send
------------------------------+------------------------------------------
Reporter: ejucovy | Owner: jorgecarleitao
Type: New feature | Status: assigned
Component: contrib.auth | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------------
Changes (by claudep):

* needs_docs: 0 => 1
* needs_better_patch: 1 => 0


Comment:

The patch is promising. It still needs more docs however (release notes
and also the `construct_email` method documentation).

--
Ticket URL: <https://code.djangoproject.com/ticket/17431#comment:8>

Django

unread,
Jun 10, 2014, 2:31:05 PM6/10/14
to django-...@googlegroups.com
#17431: Allow PasswordResetForm subclasses full control over email message to send
------------------------------+------------------------------------------
Reporter: ejucovy | Owner: jorgecarleitao
Type: New feature | Status: closed
Component: contrib.auth | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"a00b78b1e2ac9bf271d55c1799138a27f5e0d03e"]:
{{{
#!CommitTicketReference repository=""
revision="a00b78b1e2ac9bf271d55c1799138a27f5e0d03e"
Fixed #17431 -- Added send_mail() method to PasswordResetForm.

Credits for the initial patch go to ejucovy;
big thanks to Tim Graham for the review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/17431#comment:9>

Reply all
Reply to author
Forward
0 new messages