Ticket #11300: 11300.2.diff

File 11300.2.diff, 5.1 KB (added by Rob Hudson, 14 years ago)

Updated patch, added docs

  • django/contrib/auth/forms.py

    diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
    index d20c472..cc0f707 100644
    a b class PasswordResetForm(forms.Form):  
    117117        return email
    118118
    119119    def save(self, domain_override=None, email_template_name='registration/password_reset_email.html',
    120              use_https=False, token_generator=default_token_generator):
     120             use_https=False, token_generator=default_token_generator, from_email=None):
    121121        """
    122122        Generates a one-use only link for resetting password and sends to the user
    123123        """
    class PasswordResetForm(forms.Form):  
    140140                'protocol': use_https and 'https' or 'http',
    141141            }
    142142            send_mail(_("Password reset on %s") % site_name,
    143                 t.render(Context(c)), None, [user.email])
     143                t.render(Context(c)), from_email, [user.email])
    144144
    145145class SetPasswordForm(forms.Form):
    146146    """
  • django/contrib/auth/tests/urls.py

    diff --git a/django/contrib/auth/tests/urls.py b/django/contrib/auth/tests/urls.py
    index c6252ed..bc2f7e7 100644
    a b urlpatterns += patterns('',  
    1616    (r'^logout/custom_query/$', 'django.contrib.auth.views.logout', dict(redirect_field_name='follow')),
    1717    (r'^logout/next_page/$', 'django.contrib.auth.views.logout', dict(next_page='/somewhere/')),
    1818    (r'^remote_user/$', remote_user_auth_view),
     19    (r'^password_reset_from_email/$', 'django.contrib.auth.views.password_reset', dict(from_email='staffmember@example.com')),
    1920    (r'^login_required/$', login_required(password_reset)),
    2021    (r'^login_required_login_url/$', login_required(password_reset, login_url='/somewhere/')),
    2122)
  • django/contrib/auth/tests/views.py

    diff --git a/django/contrib/auth/tests/views.py b/django/contrib/auth/tests/views.py
    index 6b8efad..e20afbc 100644
    a b class PasswordResetTest(AuthViewsTestCase):  
    6262        self.assertEquals(response.status_code, 302)
    6363        self.assertEquals(len(mail.outbox), 1)
    6464        self.assert_("http://" in mail.outbox[0].body)
     65        self.assertEquals(settings.DEFAULT_FROM_EMAIL, mail.outbox[0].from_email)
     66
     67    def test_email_found_custom_from(self):
     68        "Email is sent if a valid email address is provided for password reset when a custom from_email is provided."
     69        response = self.client.post('/password_reset_from_email/', {'email': 'staffmember@example.com'})
     70        self.assertEquals(response.status_code, 302)
     71        self.assertEquals(len(mail.outbox), 1)
     72        self.assertEquals("staffmember@example.com", mail.outbox[0].from_email)
    6573
    6674    def _test_confirm_start(self):
    6775        # Start by creating the email
  • django/contrib/auth/views.py

    diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
    index b2e875a..eaa0dbe 100644
    a b def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_N  
    105105def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html',
    106106        email_template_name='registration/password_reset_email.html',
    107107        password_reset_form=PasswordResetForm, token_generator=default_token_generator,
    108         post_reset_redirect=None):
     108        post_reset_redirect=None, from_email=None):
    109109    if post_reset_redirect is None:
    110110        post_reset_redirect = reverse('django.contrib.auth.views.password_reset_done')
    111111    if request.method == "POST":
    def password_reset(request, is_admin_site=False, template_name='registration/pas  
    114114            opts = {}
    115115            opts['use_https'] = request.is_secure()
    116116            opts['token_generator'] = token_generator
     117            opts['from_email'] = from_email
    117118            if is_admin_site:
    118119                opts['domain_override'] = request.META['HTTP_HOST']
    119120            else:
  • docs/topics/auth.txt

    diff --git a/docs/topics/auth.txt b/docs/topics/auth.txt
    index 00b95ba..22f498a 100644
    a b includes a few other useful built-in views located in  
    906906          default to :file:`registration/password_change_done.html` if not
    907907          supplied.
    908908
    909 .. function:: views.password_reset(request[, is_admin_site, template_name, email_template_name, password_reset_form, token_generator, post_reset_redirect])
     909.. function:: views.password_reset(request[, is_admin_site, template_name, email_template_name, password_reset_form, token_generator, post_reset_redirect, from_email])
    910910
    911911    Allows a user to reset their password by generating a one-time use link
    912912    that can be used to reset the password, and sending that link to the
    includes a few other useful built-in views located in  
    932932        * ``post_reset_redirect``: The URL to redirect to after a successful
    933933          password change.
    934934
     935        * ``from_email``: A valid e-mail address. By default Django uses
     936          the :setting:`DEFAULT_FROM_EMAIL`.
     937
    935938    **Template context:**
    936939
    937940        * ``form``: The form for resetting the user's password.
Back to Top