diff -r e2699e042129 -r e29ecb7819e7 reg/forms.py --- a/reg/forms.py Fri Apr 09 16:51:56 2010 +0530 +++ b/reg/forms.py Mon Apr 12 02:57:25 2010 +0530 @@ -105,3 +105,55 @@ if start_date > stop_date: raise forms.ValidationError('The event stops even before it starts. I am starting to wonder what kind of event is this.') return stop_date + +class PasswordResetForm(forms.Form): + """ check for the existance of user for the email. + Reset the password irrespective of active status. + """ + + email = forms.EmailField() + + def clean_email(self): + + email = self.cleaned_data['email'] + try: + user = User.objects.get(email__iexact=email) + return email + except User.DoesNotExist: + raise forms.ValidationError("This not a registered email. Please enter a valid email.") + +class PasswordChangeForm(forms.Form): + + old_password = forms.CharField(widget=forms.PasswordInput) + new_password = forms.CharField(widget=forms.PasswordInput) + confirm_password = forms.CharField(widget=forms.PasswordInput) + + def clean_old_password(self): + """ authenticate the given password against username. + """ + + username = self.data['username'] + old_password = self.cleaned_data['old_password'] + user = authenticate(username=username, password=old_password) + if not user: + raise forms.ValidationError("Incorrect password") + return old_password + + + def clean_new_password(self): + """ check if the password contains only alphabets or digits or punctuation. + then check if the size of the password is optimal. + then check if both the given passwords match. + """ + + new_password = self.cleaned_data['new_password'] + + if new_password.strip(string.ascii_letters+string.punctuation+string.digits): + raise forms.ValidationError("Only alphabets, digits and punctuation symbols are allowed in password") + + if not 8 <= len(new_password) <= 30: + raise forms.ValidationError("Password must be atleast 8 characters and at most 30 characters") + + if not new_password == self.data['confirm_password']: + raise forms.ValidationError("Passwords do not match") +