Ticket #11300: 11300.diff

File 11300.diff, 3.7 KB (added by cassidy, 15 years ago)

Added from_email parameter to SetPasswordForm() and password_reset view. Wrote new test case for from_email.

  • django/contrib/auth/forms.py

     
    111111        return email
    112112
    113113    def save(self, domain_override=None, email_template_name='registration/password_reset_email.html',
    114              use_https=False, token_generator=default_token_generator):
     114             use_https=False, token_generator=default_token_generator, from_email=None):
    115115        """
    116116        Generates a one-use only link for resetting password and sends to the user
    117117        """
     
    134134                'protocol': use_https and 'https' or 'http',
    135135            }
    136136            send_mail(_("Password reset on %s") % site_name,
    137                 t.render(Context(c)), None, [user.email])
     137                t.render(Context(c)), from_email, [user.email])
    138138
    139139class SetPasswordForm(forms.Form):
    140140    """
  • django/contrib/auth/views.py

     
    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":
     
    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:
  • django/contrib/auth/tests/urls.py

     
    1414    (r'^logout/custom_query/$', 'django.contrib.auth.views.logout', dict(redirect_field_name='follow')),
    1515    (r'^logout/next_page/$', 'django.contrib.auth.views.logout', dict(next_page='/somewhere/')),
    1616    (r'^remote_user/$', remote_user_auth_view),
     17    (r'^password_reset_from_email/$', 'django.contrib.auth.views.password_reset', dict(from_email='staffmember@example.com')),
    1718)
    1819
  • django/contrib/auth/tests/views.py

     
    5252        self.assertEquals(response.status_code, 302)
    5353        self.assertEquals(len(mail.outbox), 1)
    5454        self.assert_("http://" in mail.outbox[0].body)
     55        self.assertEquals(settings.DEFAULT_FROM_EMAIL, mail.outbox[0].from_email)
    5556
     57    def test_email_found_custom_from(self):
     58        "Email is sent if a valid email address is provided for password reset when a custom from_email is provided."
     59        response = self.client.post('/password_reset_from_email/', {'email': 'staffmember@example.com'})
     60        self.assertEquals(response.status_code, 302)
     61        self.assertEquals(len(mail.outbox), 1)
     62        self.assertEquals("staffmember@example.com", mail.outbox[0].from_email)
     63
    5664    def _test_confirm_start(self):
    5765        # Start by creating the email
    5866        response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})
Back to Top