/
forms.py
54 lines (42 loc) · 1.52 KB
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from django import forms
from django.contrib.auth.forms import PasswordResetForm, UserCreationForm
from django.contrib.auth.models import User
from twobuntu.accounts.models import Profile
from twobuntu.captcha.fields import CaptchaField
class RegistrationForm(UserCreationForm):
"""
Form for new user registrations.
"""
email = forms.EmailField(help_text="Used for account verification and password resets.")
captcha = CaptchaField()
class ResetForm(PasswordResetForm):
"""
Form for resetting a user's password.
"""
email = forms.EmailField(help_text="Email address used when registering.")
def clean_email(self):
"""
Verify that the email address is valid.
"""
try:
self.user = User.objects.get(email=self.cleaned_data['email'], is_active=True)
except User.DoesNotExist:
raise forms.ValidationError("The email address provided does not match an active account.")
class ProfileForm(forms.ModelForm):
"""
Form for editing a user's profile.
"""
first_name = forms.CharField(
max_length=30,
required=False,
help_text="First name [optional].",
)
last_name = forms.CharField(
max_length=30,
required=False,
help_text="Last name [optional].",
)
email = forms.EmailField(help_text="Used for account verification and password resets.")
class Meta:
model = Profile
fields = ('first_name', 'last_name', 'email', 'birthday', 'location', 'website', 'bio')