Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ def create_app(config_name):
app.register_blueprint(admin_blueprint, url_prefix='/admin')

from bulk_resource import bulk_resource as bulk_resource_blueprint
app.register_blueprint(bulk_resource_blueprint,
url_prefix='/bulk-resource')
app.register_blueprint(
bulk_resource_blueprint, url_prefix='/bulk-resource')

from descriptor import descriptor as descriptor_blueprint
app.register_blueprint(descriptor_blueprint, url_prefix='/descriptor')

from single_resource import single_resource as single_resource_blueprint
app.register_blueprint(single_resource_blueprint,
url_prefix='/single-resource')
app.register_blueprint(
single_resource_blueprint, url_prefix='/single-resource')

from suggestion import suggestion as suggestion_blueprint
app.register_blueprint(suggestion_blueprint, url_prefix='/suggestion')
Expand Down
87 changes: 37 additions & 50 deletions app/account/forms.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,40 @@
from flask.ext.wtf import Form
from wtforms.fields import (
BooleanField,
PasswordField,
StringField,
SubmitField
)
from wtforms import ValidationError
from wtforms.fields import (BooleanField, PasswordField, StringField,
SubmitField)
from wtforms.fields.html5 import EmailField
from wtforms.validators import Email, EqualTo, InputRequired, Length
from wtforms import ValidationError

from ..models import User


class LoginForm(Form):
email = EmailField('Email', validators=[
InputRequired(),
Length(1, 500),
Email()
])
email = EmailField(
'Email', validators=[InputRequired(), Length(1, 500), Email()])
password = PasswordField('Password', validators=[InputRequired()])
remember_me = BooleanField('Keep me logged in')
submit = SubmitField('Log in')


class RequestResetPasswordForm(Form):
email = EmailField('Email', validators=[
InputRequired(),
Length(1, 500),
Email()])
email = EmailField(
'Email', validators=[InputRequired(), Length(1, 500), Email()])
submit = SubmitField('Reset password')

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


class ResetPasswordForm(Form):
email = EmailField('Email', validators=[
InputRequired(),
Length(1, 500),
Email()])
new_password = PasswordField('New password', validators=[
InputRequired(),
EqualTo('new_password2', 'Passwords must match.')
])
new_password2 = PasswordField('Confirm new password',
validators=[InputRequired()])
email = EmailField(
'Email', validators=[InputRequired(), Length(1, 500), Email()])
new_password = PasswordField(
'New password',
validators=[
InputRequired(), EqualTo('new_password2', 'Passwords must match.')
])
new_password2 = PasswordField(
'Confirm new password', validators=[InputRequired()])
submit = SubmitField('Reset password')

def validate_email(self, field):
Expand All @@ -52,31 +43,31 @@ def validate_email(self, field):


class CreatePasswordForm(Form):
password = PasswordField('Password', validators=[
InputRequired(),
EqualTo('password2', 'Passwords must match.')
])
password2 = PasswordField('Confirm new password',
validators=[InputRequired()])
password = PasswordField(
'Password',
validators=[
InputRequired(), EqualTo('password2', 'Passwords must match.')
])
password2 = PasswordField(
'Confirm new password', validators=[InputRequired()])
submit = SubmitField('Set password')


class ChangePasswordForm(Form):
old_password = PasswordField('Old password', validators=[InputRequired()])
new_password = PasswordField('New password', validators=[
InputRequired(),
EqualTo('new_password2', 'Passwords must match.')
])
new_password2 = PasswordField('Confirm new password',
validators=[InputRequired()])
new_password = PasswordField(
'New password',
validators=[
InputRequired(), EqualTo('new_password2', 'Passwords must match.')
])
new_password2 = PasswordField(
'Confirm new password', validators=[InputRequired()])
submit = SubmitField('Update password')


class ChangeEmailForm(Form):
email = EmailField('New email', validators=[
InputRequired(),
Length(1, 500),
Email()])
email = EmailField(
'New email', validators=[InputRequired(), Length(1, 500), Email()])
password = PasswordField('Password', validators=[InputRequired()])
submit = SubmitField('Update email')

Expand All @@ -86,12 +77,8 @@ def validate_email(self, field):


class ChangeAccountInfoForm(Form):
first_name = StringField('First name', validators=[
InputRequired(),
Length(1, 500)
])
last_name = StringField('Last name', validators=[
InputRequired(),
Length(1, 500)
])
first_name = StringField(
'First name', validators=[InputRequired(), Length(1, 500)])
last_name = StringField(
'Last name', validators=[InputRequired(), Length(1, 500)])
submit = SubmitField('Update account information')
80 changes: 34 additions & 46 deletions app/account/views.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
from flask import flash, redirect, render_template, request, url_for
from flask.ext.login import (
current_user,
login_required,
login_user,
logout_user
)
from flask.ext.login import (current_user, login_required, login_user,
logout_user)
from flask.ext.rq import get_queue

from . import account
from .. import db
from ..email import send_email
from ..models import User
from .forms import (
ChangeAccountInfoForm,
ChangeEmailForm,
ChangePasswordForm,
CreatePasswordForm,
LoginForm,
RequestResetPasswordForm,
ResetPasswordForm
)
from .forms import (ChangeAccountInfoForm, ChangeEmailForm, ChangePasswordForm,
CreatePasswordForm, LoginForm, RequestResetPasswordForm,
ResetPasswordForm)


@account.route('/login', methods=['GET', 'POST'])
Expand Down Expand Up @@ -63,20 +54,18 @@ def reset_password_request():
user = User.query.filter_by(email=form.email.data).first()
if user:
token = user.generate_password_reset_token()
reset_link = url_for('account.reset_password', token=token,
_external=True)
reset_link = url_for(
'account.reset_password', token=token, _external=True)
get_queue().enqueue(
send_email,
recipient=user.email,
subject='Reset Your Password',
template='account/email/reset_password',
user=user,
reset_link=reset_link,
next=request.args.get('next')
)
next=request.args.get('next'))
flash('A password reset link has been sent to {}.'
.format(form.email.data),
'warning')
.format(form.email.data), 'warning')
return redirect(url_for('account.login'))
return render_template('account/reset_password.html', form=form)

Expand Down Expand Up @@ -149,8 +138,8 @@ def change_email_request():
if current_user.verify_password(form.password.data):
new_email = form.email.data
token = current_user.generate_email_change_token(new_email)
change_email_link = url_for('account.change_email', token=token,
_external=True)
change_email_link = url_for(
'account.change_email', token=token, _external=True)
get_queue().enqueue(
send_email,
recipient=new_email,
Expand All @@ -159,8 +148,7 @@ def change_email_request():
# current_user is a LocalProxy, we want the underlying user
# object
user=current_user._get_current_object(),
change_email_link=change_email_link
)
change_email_link=change_email_link)
flash('A confirmation link has been sent to {}.'.format(new_email),
'warning')
return redirect(url_for('main.index'))
Expand Down Expand Up @@ -193,11 +181,9 @@ def confirm_request():
template='account/email/confirm',
# current_user is a LocalProxy, we want the underlying user object
user=current_user._get_current_object(),
confirm_link=confirm_link
)
flash('A new confirmation link has been sent to {}.'.
format(current_user.email),
'warning')
confirm_link=confirm_link)
flash('A new confirmation link has been sent to {}.'.format(
current_user.email), 'warning')
return redirect(url_for('main.index'))


Expand All @@ -214,8 +200,8 @@ def confirm(token):
return redirect(url_for('main.index'))


@account.route('/join-from-invite/<int:user_id>/<token>',
methods=['GET', 'POST'])
@account.route(
'/join-from-invite/<int:user_id>/<token>', methods=['GET', 'POST'])
def join_from_invite(user_id, token):
"""
Confirm new user's account with provided token and prompt them to set
Expand All @@ -234,30 +220,32 @@ def join_from_invite(user_id, token):
return redirect(url_for('main.index'))

if new_user.confirm_account(token):
form = CreatePasswordForm()
if form.validate_on_submit():
new_user.password = form.password.data
db.session.add(new_user)
db.session.commit()
flash('Your password has been set. After you log in, you can '
'go to the "Your Account" page to review your account '
'information and settings.', 'success')
return redirect(url_for('account.login'))
return render_template('account/join_invite.html', form=form)
form = CreatePasswordForm()
if form.validate_on_submit():
new_user.password = form.password.data
db.session.add(new_user)
db.session.commit()
flash('Your password has been set. After you log in, you can '
'go to the "Your Account" page to review your account '
'information and settings.', 'success')
return redirect(url_for('account.login'))
return render_template('account/join_invite.html', form=form)
else:
flash('The confirmation link is invalid or has expired. Another '
'invite email with a new link has been sent to you.', 'error')
token = new_user.generate_confirmation_token()
invite_link = url_for('account.join_from_invite', user_id=user_id,
token=token, _external=True)
invite_link = url_for(
'account.join_from_invite',
user_id=user_id,
token=token,
_external=True)
get_queue().enqueue(
send_email,
recipient=new_user.email,
subject='You Are Invited To Join',
template='account/email/invite',
user=new_user,
invite_link=invite_link
)
invite_link=invite_link)
return redirect(url_for('main.index'))


Expand Down
57 changes: 28 additions & 29 deletions app/admin/forms.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
from flask.ext.wtf import Form
from wtforms import ValidationError
from wtforms.ext.sqlalchemy.fields import QuerySelectField
from wtforms.fields import PasswordField, StringField, SubmitField
from wtforms.fields.html5 import EmailField
from wtforms.ext.sqlalchemy.fields import QuerySelectField
from wtforms.validators import InputRequired, Length, Email, EqualTo
from wtforms import ValidationError
from ..models import User, Role
from wtforms.validators import Email, EqualTo, InputRequired, Length

from .. import db
from ..models import Role, User


class ChangeUserEmailForm(Form):
email = EmailField('New email', validators=[
InputRequired(),
Length(1, 500),
Email()
])
email = EmailField(
'New email', validators=[InputRequired(), Length(1, 500), Email()])
submit = SubmitField('Update email')

def validate_email(self, field):
Expand All @@ -22,26 +20,26 @@ def validate_email(self, field):


class ChangeAccountTypeForm(Form):
role = QuerySelectField('New account type',
validators=[InputRequired()],
get_label='name',
query_factory=lambda: db.session.query(Role).
order_by('permissions'))
role = QuerySelectField(
'New account type',
validators=[InputRequired()],
get_label='name',
query_factory=lambda: db.session.query(Role).order_by('permissions'))
submit = SubmitField('Update role')


class InviteUserForm(Form):
role = QuerySelectField('Account type',
validators=[InputRequired()],
get_label='name',
query_factory=lambda: db.session.query(Role).
order_by('permissions'))
first_name = StringField('First name', validators=[InputRequired(),
Length(1, 500)])
last_name = StringField('Last name', validators=[InputRequired(),
Length(1, 500)])
email = EmailField('Email', validators=[InputRequired(), Length(1, 500),
Email()])
role = QuerySelectField(
'Account type',
validators=[InputRequired()],
get_label='name',
query_factory=lambda: db.session.query(Role).order_by('permissions'))
first_name = StringField(
'First name', validators=[InputRequired(), Length(1, 500)])
last_name = StringField(
'Last name', validators=[InputRequired(), Length(1, 500)])
email = EmailField(
'Email', validators=[InputRequired(), Length(1, 500), Email()])
submit = SubmitField('Invite')

def validate_email(self, field):
Expand All @@ -50,10 +48,11 @@ def validate_email(self, field):


class NewUserForm(InviteUserForm):
password = PasswordField('Password', validators=[
InputRequired(), EqualTo('password2',
'Passwords must match.')
])
password = PasswordField(
'Password',
validators=[
InputRequired(), EqualTo('password2', 'Passwords must match.')
])
password2 = PasswordField('Confirm password', validators=[InputRequired()])

submit = SubmitField('Create')
Loading