1 from general import NextUrlField, UserNameField, UserEmailField, UserRealNameField, SetPasswordForm
2 from forum.models import Question, User
3 from django.contrib.contenttypes.models import ContentType
4 from django.utils.translation import ugettext as _
5 from django.utils.safestring import mark_safe
6 from django import forms
9 class SimpleRegistrationForm(forms.Form):
11 username = UserNameField()
12 email = UserEmailField()
13 real_name = UserRealNameField()
15 class TemporaryLoginRequestForm(forms.Form):
16 def __init__(self, data=None):
17 super(TemporaryLoginRequestForm, self).__init__(data)
18 self.user_cache = None
20 email = forms.EmailField(
22 label=_("Your account email"),
24 'required': _("You cannot leave this field blank"),
25 'invalid': _('please enter a valid email address'),
29 def clean_email(self):
30 users = list(User.objects.filter(email=self.cleaned_data['email']))
33 raise forms.ValidationError(_("Sorry, but this email is not on our database."))
35 self.user_cache = users
36 return self.cleaned_data['email']
38 class ChangePasswordForm(SetPasswordForm):
39 """ change password form """
40 oldpw = forms.CharField(widget=forms.PasswordInput(attrs={'class':'required'}),
41 label=mark_safe(_('Current password')))
43 def __init__(self, data=None, user=None, *args, **kwargs):
45 raise TypeError("Keyword argument 'user' must be supplied")
46 super(ChangePasswordForm, self).__init__(data, *args, **kwargs)
49 def clean_oldpw(self):
50 """ test old password """
51 if not self.user.check_password(self.cleaned_data['oldpw']):
52 raise forms.ValidationError(_("Old password is incorrect. \
53 Please enter the correct password."))
54 return self.cleaned_data['oldpw']