Fixed behaviour of contrib.auth.forms.PasswordResetForm when more than

one User have the same e-mail address.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5493 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Luke Plant 2007-06-19 20:04:54 +00:00
parent b6b1ab22b5
commit 18619a11ee
1 changed files with 21 additions and 21 deletions

View File

@ -79,32 +79,32 @@ class PasswordResetForm(oldforms.Manipulator):
def isValidUserEmail(self, new_data, all_data): def isValidUserEmail(self, new_data, all_data):
"Validates that a user exists with the given e-mail address" "Validates that a user exists with the given e-mail address"
try: self.users_cache = list(User.objects.filter(email__iexact=new_data))
self.user_cache = User.objects.get(email__iexact=new_data) if len(self.users_cache) == 0:
except User.DoesNotExist:
raise validators.ValidationError, _("That e-mail address doesn't have an associated user account. Are you sure you've registered?") raise validators.ValidationError, _("That e-mail address doesn't have an associated user account. Are you sure you've registered?")
def save(self, domain_override=None, email_template_name='registration/password_reset_email.html'): def save(self, domain_override=None, email_template_name='registration/password_reset_email.html'):
"Calculates a new password randomly and sends it to the user" "Calculates a new password randomly and sends it to the user"
from django.core.mail import send_mail from django.core.mail import send_mail
new_pass = User.objects.make_random_password() for user in self.users_cache:
self.user_cache.set_password(new_pass) new_pass = User.objects.make_random_password()
self.user_cache.save() user.set_password(new_pass)
if not domain_override: user.save()
current_site = Site.objects.get_current() if not domain_override:
site_name = current_site.name current_site = Site.objects.get_current()
domain = current_site.domain site_name = current_site.name
else: domain = current_site.domain
site_name = domain = domain_override else:
t = loader.get_template(email_template_name) site_name = domain = domain_override
c = { t = loader.get_template(email_template_name)
'new_password': new_pass, c = {
'email': self.user_cache.email, 'new_password': new_pass,
'domain': domain, 'email': user.email,
'site_name': site_name, 'domain': domain,
'user': self.user_cache, 'site_name': site_name,
} 'user': user,
send_mail('Password reset on %s' % site_name, t.render(Context(c)), None, [self.user_cache.email]) }
send_mail('Password reset on %s' % site_name, t.render(Context(c)), None, [user.email])
class PasswordChangeForm(oldforms.Manipulator): class PasswordChangeForm(oldforms.Manipulator):
"A form that lets a user change his password." "A form that lets a user change his password."