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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# vim:fileencoding=utf8:et:ts=4:sts=4:sw=4:ft=python
from django import forms
from okupy.accounts.models import OpenID_Attributes
from okupy.crypto.ciphers import sessionrefcipher
import pytz
class LoginForm(forms.Form):
username = forms.CharField(max_length=100, label='Username:')
password = forms.CharField(max_length=30, widget=forms.PasswordInput(),
label='Password:')
class StrongAuthForm(forms.Form):
password = forms.CharField(max_length=30, widget=forms.PasswordInput(),
label='Password:')
class OpenIDLoginForm(LoginForm):
auto_logout = forms.BooleanField(
required=False,
label='Log out after answering the OpenID request')
class SSLCertLoginForm(forms.Form):
session = forms.CharField(max_length=200, widget=forms.HiddenInput())
next = forms.CharField(max_length=254, widget=forms.HiddenInput())
login_uri = forms.CharField(max_length=254, widget=forms.HiddenInput())
def clean_session(self):
try:
return sessionrefcipher.decrypt(
self.cleaned_data['session'])
except ValueError:
raise forms.ValidationError('Invalid session id')
class OTPForm(forms.Form):
otp_token = forms.CharField(max_length=10, label='OTP token:')
class SignupForm(forms.Form):
first_name = forms.CharField(max_length=100, label='First Name:')
last_name = forms.CharField(max_length=100, label='Last Name:')
email = forms.EmailField(max_length=254, label='Email: ')
username = forms.CharField(max_length=100, label='Username:')
password_origin = forms.CharField(
max_length=30, widget=forms.PasswordInput(), label='Password:')
password_verify = forms.CharField(
max_length=30, widget=forms.PasswordInput(), label='Verify Password:')
def clean_password_verify(self):
cleaned_data = super(SignupForm, self).clean()
password_origin = cleaned_data.get('password_origin')
password_verify = cleaned_data.get('password_verify')
if password_origin != password_verify:
raise forms.ValidationError("Passwords don't match")
return password_verify
#Settings
class ProfileSettingsForm(forms.Form):
first_name = forms.CharField(
max_length=100, label='First Name', required=False)
last_name = forms.CharField(
max_length=100, label='Last Name', required=False)
birthday = forms.DateField(
input_formats='%m/%d/%Y', label='Birthday', required=False)
timezone = forms.ChoiceField(
choices=[(x, x) for x in pytz.common_timezones])
class PasswordSettingsForm(forms.Form):
old_password = forms.CharField(max_length=30, widget=forms.PasswordInput(
), label='Old Password', required=False)
new_password = forms.CharField(max_length=30, widget=forms.PasswordInput(
), label='New Password', required=False)
new_password_verify = forms.CharField(max_length=30,
widget=forms.PasswordInput(),
label='Repeat New Password',
required=False)
def clean(self):
cleaned_data = super(PasswordSettingsForm, self).clean()
new_password = cleaned_data.get('new_password')
new_password_verify = cleaned_data.get('new_password_verify')
old_password = cleaned_data.get('old_password')
if (new_password or new_password_verify) and (not old_password):
raise forms.ValidationError(
'Please enter your current password to change the password.')
elif new_password != new_password_verify:
raise forms.ValidationError(
"Paswords don't match. Please enter passwords again.")
elif (old_password and new_password) and (not new_password_verify):
raise forms.ValidationError(
'Password verification failed. Please repeat your passwords.')
return cleaned_data
class EmailSettingsForm(forms.Form):
email = forms.EmailField(max_length=254, label='Add Email',
help_text='A valid email address, please.',
required=False)
class ContactSettingsForm(forms.Form):
website = forms.URLField(label='Website', required=False)
im = forms.CharField(max_length=100, label='IM', required=False)
location = forms.CharField(label='Location', required=False)
longitude = forms.FloatField(label='Longitude', required=False)
latitude = forms.FloatField(label='Latitude', required=False)
phone = forms.CharField(label='Home Phone', required=False)
gpg_fingerprint = forms.CharField(label='GPG Fingerprint', required=False)
class GentooAccountSettingsForm(forms.Form):
gentoo_join_date = forms.CharField(
label='Gentoo Join Date', required=False)
gentoo_retire_date = forms.CharField(
label='Gentoo Retire Date', required=False)
developer_bug = forms.CharField(
label='Developer Bugs (Bug Number)', required=False)
mentor = forms.CharField(max_length=100, label='Mentor', required=False)
ssh_key = forms.CharField(widget=forms.Textarea(
attrs={'cols': 50, 'rows': 8}), label='SSH Key', required=False)
# OpenID forms.
class SiteAuthForm(forms.ModelForm):
class Meta:
model = OpenID_Attributes
exclude = ('trust_root', 'uid')
widgets = {
'nickname': forms.CheckboxInput,
'email': forms.CheckboxInput,
'fullname': forms.CheckboxInput,
'dob': forms.CheckboxInput,
'gender': forms.CheckboxInput,
'postcode': forms.CheckboxInput,
'country': forms.CheckboxInput,
'language': forms.CheckboxInput,
'timezone': forms.CheckboxInput,
'which_email': forms.Select,
}
|