Files
edx-platform/common/djangoapps/student/forms.py
Jason Bau 83062c0b7d Tests + Now subclass PasswordResetForm instead of copy
Changed to subclassing django's PasswordResetForm and
overriding clean_password() instead of copy/paste.
Less lines to worry about for diff-cover this way =)
2013-06-24 11:54:31 -07:00

22 lines
992 B
Python

from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import PasswordResetForm
from django.contrib.auth.hashers import UNUSABLE_PASSWORD
class PasswordResetFormNoActive(PasswordResetForm):
def clean_email(self):
"""
This is a literal copy from Django 1.4.5's django.contrib.auth.forms.PasswordResetForm
Except removing the requirement of active users
Validates that a user exists with the given email address.
"""
email = self.cleaned_data["email"]
#The line below contains the only change, removing is_active=True
self.users_cache = User.objects.filter(email__iexact=email)
if not len(self.users_cache):
raise forms.ValidationError(self.error_messages['unknown'])
if any((user.password == UNUSABLE_PASSWORD)
for user in self.users_cache):
raise forms.ValidationError(self.error_messages['unusable'])
return email