1 from __future__
import unicode_literals
2 from cgi
import FieldStorage
3 from timezones
import zones
10 from wtforms
import validators
11 from wtforms.fields
import (
12 BooleanField, DateField, DecimalField, FieldList, FileField,
13 PasswordField, SelectField, SubmitField, TextField)
20 return [(
'',
'Select Gender'), (
'F',
'Female'), (
'M',
'Male')]
24 timezones = [(
'',
'Select Timezone')]
25 for _, name, formatted_name
in zones.get_timezones(only_us=
True):
26 timezones.append([name, formatted_name])
32 username = TextField(
'Username', [
33 validators.Required(message=
'Username cannot be blank'),
34 validators.Length(min=5, max=10, message=
'Limit username to between %(min)d and %(max)d characters'),
35 Unique(User, User.username, message=
'Username is already in use')])
37 validators.Required(message=
'Email cannot be blank'),
38 validators.Email(message=
'Valid email address is required'),
39 Unique(User, User.email, message=
'Email is already in use')])
40 gender = SelectField(
'Gender', [
41 validators.Required(message=
'Must select a gender')],
43 dob = DateField(
'Date of Birth', [
44 validators.Required(
'Date of Birth cannot be blank')],
45 format=
'%m/%d/%y', description=
'mm/dd/yy')
46 weight = DecimalField(
'Weight (kg)', [
47 validators.Required(message=
'Weight must be a positive number'),
48 validators.NumberRange(min=0, message=
'Weight must be at least %(min)d kilograms')])
49 height = DecimalField(
'Height (m)', [
50 validators.Required(message=
'Height must be a positive number'),
51 validators.NumberRange(min=0, message=
'Height must be at least %(min)d meters')])
55 raise validators.ValidationError(
'You must be %d or older to join' % MIN_AGE)
60 password = PasswordField(
'Password', [
61 validators.Required(
'Password cannot be blank'),
62 validators.Length(min=6, max=15, message=
'Password must be between %(min)d and %(max)d characters')])
70 self.username.data, self.email.data, self.password.data, self.gender.data,
71 self.dob.data, self.weight.data, self.height.data)
72 return Auth.register(user, login=
True)
78 avatar = FileField(
'Profile image', [
79 FileType([
'gif',
'jpg',
'jpeg',
'png'], message=
'Profile image must be a %(allowed)s')])
83 self.username.data, self.email.data, self.gender.data, self.dob.data,
84 self.weight.data, self.height.data, self.timezone.data)
85 if isinstance(self.avatar.data, FieldStorage):
86 user.update_avatar(self.avatar.data)
92 validators.Required(
'Email cannot be blank'),
93 ValidLogin(message=
'Invalid email/password combo')])
94 password = PasswordField(
'Password', [
95 validators.Required(
'Password cannot be blank')])
96 remember_me = BooleanField(
'Remember me', default=
True)
103 user = User.get_by_email(self.email.data)
104 return Auth.login(user, self.remember_me.data)
109 current_password = PasswordField(
'Current password', [
110 validators.Required(message=
'Current password cannot be blank')])
111 new_password = PasswordField(
'New password', [
112 validators.Required(message=
'New password cannot be blank'),
113 validators.Length(min=6, max=15, message=
'New password must be between %(min)d and %(max)d characters')])
114 confirm_new_password = PasswordField(
'Verify password', [
115 validators.EqualTo(
'new_password', message=
'Passwords must match')])
122 if self.state.password != Auth.hash_password(field.data, self.state.password):
123 raise validators.ValidationError(
'Invalid current password')
130 if field.data == self.current_password.data:
131 raise validators.ValidationError(
'New password must be different from current password')
134 user.update_password(self.new_password.data)
139 change_status = SubmitField(
'Add Buddy')
142 user.add_buddy(other_user)
147 change_status = SubmitField(
'Remove Buddy')
150 user.remove_buddy(other_user)
155 add = SubmitField(
'Add Buddy')
156 remove = SubmitField(
'Remove Buddy')
159 user.add_buddy(other_user)
162 user.remove_buddy(other_user)
168 validators.Required(message=
'Email cannot be blank')])
175 if not User.get_by_email(field.data):
176 raise validators.ValidationError(
'Email could not be found')
183 Auth.request_reset_password(self.email.data)
189 user.confirm_all_notifications()
196 validators.Email(message=
'Valid email address is required')]),
197 min_entries=1, max_entries=10)
204 Auth.send_invite(self.emails.data, user)