Skip to content

Commit b30ce8c

Browse files
authored
Merge pull request hack4impact#54 from hack4impact/auto-format
Reformat with yapf
2 parents 795df91 + bf81ddb commit b30ce8c

14 files changed

Lines changed: 224 additions & 231 deletions

File tree

app/account/forms.py

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,42 @@
11
from flask import url_for
22
from flask.ext.wtf import Form
3-
from wtforms.fields import (
4-
StringField,
5-
PasswordField,
6-
BooleanField,
7-
SubmitField
8-
)
9-
from wtforms.fields.html5 import EmailField
10-
from wtforms.validators import InputRequired, Length, Email, EqualTo
113
from wtforms import ValidationError
4+
from wtforms.fields import (BooleanField, PasswordField, StringField,
5+
SubmitField)
6+
from wtforms.fields.html5 import EmailField
7+
from wtforms.validators import Email, EqualTo, InputRequired, Length
8+
129
from ..models import User
1310

1411

1512
class LoginForm(Form):
16-
email = EmailField('Email', validators=[
17-
InputRequired(),
18-
Length(1, 64),
19-
Email()
20-
])
13+
email = EmailField(
14+
'Email', validators=[
15+
InputRequired(), Length(1, 64), Email()
16+
])
2117
password = PasswordField('Password', validators=[InputRequired()])
2218
remember_me = BooleanField('Keep me logged in')
2319
submit = SubmitField('Log in')
2420

2521

2622
class RegistrationForm(Form):
27-
first_name = StringField('First name', validators=[
28-
InputRequired(),
29-
Length(1, 64)
30-
])
31-
last_name = StringField('Last name', validators=[
32-
InputRequired(),
33-
Length(1, 64)
34-
])
35-
email = EmailField('Email', validators=[
36-
InputRequired(),
37-
Length(1, 64),
38-
Email()
39-
])
40-
password = PasswordField('Password', validators=[
41-
InputRequired(),
42-
EqualTo('password2', 'Passwords must match')
43-
])
23+
first_name = StringField(
24+
'First name', validators=[
25+
InputRequired(), Length(1, 64)
26+
])
27+
last_name = StringField(
28+
'Last name', validators=[
29+
InputRequired(), Length(1, 64)
30+
])
31+
email = EmailField(
32+
'Email', validators=[
33+
InputRequired(), Length(1, 64), Email()
34+
])
35+
password = PasswordField(
36+
'Password',
37+
validators=[
38+
InputRequired(), EqualTo('password2', 'Passwords must match')
39+
])
4440
password2 = PasswordField('Confirm password', validators=[InputRequired()])
4541
submit = SubmitField('Register')
4642

@@ -52,27 +48,28 @@ def validate_email(self, field):
5248

5349

5450
class RequestResetPasswordForm(Form):
55-
email = EmailField('Email', validators=[
56-
InputRequired(),
57-
Length(1, 64),
58-
Email()])
51+
email = EmailField(
52+
'Email', validators=[
53+
InputRequired(), Length(1, 64), Email()
54+
])
5955
submit = SubmitField('Reset password')
6056

6157
# We don't validate the email address so we don't confirm to attackers
6258
# that an account with the given email exists.
6359

6460

6561
class ResetPasswordForm(Form):
66-
email = EmailField('Email', validators=[
67-
InputRequired(),
68-
Length(1, 64),
69-
Email()])
70-
new_password = PasswordField('New password', validators=[
71-
InputRequired(),
72-
EqualTo('new_password2', 'Passwords must match.')
73-
])
74-
new_password2 = PasswordField('Confirm new password',
75-
validators=[InputRequired()])
62+
email = EmailField(
63+
'Email', validators=[
64+
InputRequired(), Length(1, 64), Email()
65+
])
66+
new_password = PasswordField(
67+
'New password',
68+
validators=[
69+
InputRequired(), EqualTo('new_password2', 'Passwords must match.')
70+
])
71+
new_password2 = PasswordField(
72+
'Confirm new password', validators=[InputRequired()])
7673
submit = SubmitField('Reset password')
7774

7875
def validate_email(self, field):
@@ -81,31 +78,33 @@ def validate_email(self, field):
8178

8279

8380
class CreatePasswordForm(Form):
84-
password = PasswordField('Password', validators=[
85-
InputRequired(),
86-
EqualTo('password2', 'Passwords must match.')
87-
])
88-
password2 = PasswordField('Confirm new password',
89-
validators=[InputRequired()])
81+
password = PasswordField(
82+
'Password',
83+
validators=[
84+
InputRequired(), EqualTo('password2', 'Passwords must match.')
85+
])
86+
password2 = PasswordField(
87+
'Confirm new password', validators=[InputRequired()])
9088
submit = SubmitField('Set password')
9189

9290

9391
class ChangePasswordForm(Form):
9492
old_password = PasswordField('Old password', validators=[InputRequired()])
95-
new_password = PasswordField('New password', validators=[
96-
InputRequired(),
97-
EqualTo('new_password2', 'Passwords must match.')
98-
])
99-
new_password2 = PasswordField('Confirm new password',
100-
validators=[InputRequired()])
93+
new_password = PasswordField(
94+
'New password',
95+
validators=[
96+
InputRequired(), EqualTo('new_password2', 'Passwords must match.')
97+
])
98+
new_password2 = PasswordField(
99+
'Confirm new password', validators=[InputRequired()])
101100
submit = SubmitField('Update password')
102101

103102

104103
class ChangeEmailForm(Form):
105-
email = EmailField('New email', validators=[
106-
InputRequired(),
107-
Length(1, 64),
108-
Email()])
104+
email = EmailField(
105+
'New email', validators=[
106+
InputRequired(), Length(1, 64), Email()
107+
])
109108
password = PasswordField('Password', validators=[InputRequired()])
110109
submit = SubmitField('Update email')
111110

app/account/views.py

Lines changed: 41 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
from flask import render_template, redirect, request, url_for, flash
2-
from flask.ext.login import (
3-
login_required,
4-
login_user,
5-
logout_user,
6-
current_user
7-
)
1+
from flask import flash, redirect, render_template, request, url_for
2+
from flask.ext.login import (current_user, login_required, login_user,
3+
logout_user)
84
from flask.ext.rq import get_queue
5+
96
from . import account
107
from .. import db
118
from ..email import send_email
129
from ..models import User
13-
from .forms import (
14-
LoginForm,
15-
RegistrationForm,
16-
CreatePasswordForm,
17-
ChangePasswordForm,
18-
ChangeEmailForm,
19-
RequestResetPasswordForm,
20-
ResetPasswordForm
21-
)
10+
from .forms import (ChangeEmailForm, ChangePasswordForm, CreatePasswordForm,
11+
LoginForm, RegistrationForm, RequestResetPasswordForm,
12+
ResetPasswordForm)
2213

2314

2415
@account.route('/login', methods=['GET', 'POST'])
@@ -42,10 +33,11 @@ def register():
4233
"""Register a new user, and send them a confirmation email."""
4334
form = RegistrationForm()
4435
if form.validate_on_submit():
45-
user = User(first_name=form.first_name.data,
46-
last_name=form.last_name.data,
47-
email=form.email.data,
48-
password=form.password.data)
36+
user = User(
37+
first_name=form.first_name.data,
38+
last_name=form.last_name.data,
39+
email=form.email.data,
40+
password=form.password.data)
4941
db.session.add(user)
5042
db.session.commit()
5143
token = user.generate_confirmation_token()
@@ -56,8 +48,7 @@ def register():
5648
subject='Confirm Your Account',
5749
template='account/email/confirm',
5850
user=user,
59-
confirm_link=confirm_link
60-
)
51+
confirm_link=confirm_link)
6152
flash('A confirmation link has been sent to {}.'.format(user.email),
6253
'warning')
6354
return redirect(url_for('main.index'))
@@ -90,20 +81,18 @@ def reset_password_request():
9081
user = User.query.filter_by(email=form.email.data).first()
9182
if user:
9283
token = user.generate_password_reset_token()
93-
reset_link = url_for('account.reset_password', token=token,
94-
_external=True)
84+
reset_link = url_for(
85+
'account.reset_password', token=token, _external=True)
9586
get_queue().enqueue(
9687
send_email,
9788
recipient=user.email,
9889
subject='Reset Your Password',
9990
template='account/email/reset_password',
10091
user=user,
10192
reset_link=reset_link,
102-
next=request.args.get('next')
103-
)
93+
next=request.args.get('next'))
10494
flash('A password reset link has been sent to {}.'
105-
.format(form.email.data),
106-
'warning')
95+
.format(form.email.data), 'warning')
10796
return redirect(url_for('account.login'))
10897
return render_template('account/reset_password.html', form=form)
10998

@@ -155,8 +144,8 @@ def change_email_request():
155144
if current_user.verify_password(form.password.data):
156145
new_email = form.email.data
157146
token = current_user.generate_email_change_token(new_email)
158-
change_email_link = url_for('account.change_email', token=token,
159-
_external=True)
147+
change_email_link = url_for(
148+
'account.change_email', token=token, _external=True)
160149
get_queue().enqueue(
161150
send_email,
162151
recipient=new_email,
@@ -165,8 +154,7 @@ def change_email_request():
165154
# current_user is a LocalProxy, we want the underlying user
166155
# object
167156
user=current_user._get_current_object(),
168-
change_email_link=change_email_link
169-
)
157+
change_email_link=change_email_link)
170158
flash('A confirmation link has been sent to {}.'.format(new_email),
171159
'warning')
172160
return redirect(url_for('main.index'))
@@ -199,11 +187,9 @@ def confirm_request():
199187
template='account/email/confirm',
200188
# current_user is a LocalProxy, we want the underlying user object
201189
user=current_user._get_current_object(),
202-
confirm_link=confirm_link
203-
)
204-
flash('A new confirmation link has been sent to {}.'.
205-
format(current_user.email),
206-
'warning')
190+
confirm_link=confirm_link)
191+
flash('A new confirmation link has been sent to {}.'.format(
192+
current_user.email), 'warning')
207193
return redirect(url_for('main.index'))
208194

209195

@@ -220,8 +206,8 @@ def confirm(token):
220206
return redirect(url_for('main.index'))
221207

222208

223-
@account.route('/join-from-invite/<int:user_id>/<token>',
224-
methods=['GET', 'POST'])
209+
@account.route(
210+
'/join-from-invite/<int:user_id>/<token>', methods=['GET', 'POST'])
225211
def join_from_invite(user_id, token):
226212
"""
227213
Confirm new user's account with provided token and prompt them to set
@@ -240,30 +226,32 @@ def join_from_invite(user_id, token):
240226
return redirect(url_for('main.index'))
241227

242228
if new_user.confirm_account(token):
243-
form = CreatePasswordForm()
244-
if form.validate_on_submit():
245-
new_user.password = form.password.data
246-
db.session.add(new_user)
247-
db.session.commit()
248-
flash('Your password has been set. After you log in, you can '
249-
'go to the "Your Account" page to review your account '
250-
'information and settings.', 'success')
251-
return redirect(url_for('account.login'))
252-
return render_template('account/join_invite.html', form=form)
229+
form = CreatePasswordForm()
230+
if form.validate_on_submit():
231+
new_user.password = form.password.data
232+
db.session.add(new_user)
233+
db.session.commit()
234+
flash('Your password has been set. After you log in, you can '
235+
'go to the "Your Account" page to review your account '
236+
'information and settings.', 'success')
237+
return redirect(url_for('account.login'))
238+
return render_template('account/join_invite.html', form=form)
253239
else:
254240
flash('The confirmation link is invalid or has expired. Another '
255241
'invite email with a new link has been sent to you.', 'error')
256242
token = new_user.generate_confirmation_token()
257-
invite_link = url_for('account.join_from_invite', user_id=user_id,
258-
token=token, _external=True)
243+
invite_link = url_for(
244+
'account.join_from_invite',
245+
user_id=user_id,
246+
token=token,
247+
_external=True)
259248
get_queue().enqueue(
260249
send_email,
261250
recipient=new_user.email,
262251
subject='You Are Invited To Join',
263252
template='account/email/invite',
264253
user=new_user,
265-
invite_link=invite_link
266-
)
254+
invite_link=invite_link)
267255
return redirect(url_for('main.index'))
268256

269257

0 commit comments

Comments
 (0)