aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2019-08-19 16:42:38 +0100
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2019-08-19 16:45:13 +0100
commitd2bd7472dec27d7ebcb88a05517b9394b63df014 (patch)
tree96ccc4cc8436965f8413572d38944d1052a538fa
parentCode quality (diff)
downloadAnnotateChange-d2bd7472dec27d7ebcb88a05517b9394b63df014.tar.gz
AnnotateChange-d2bd7472dec27d7ebcb88a05517b9394b63df014.zip
Add various user flags for registration
-rw-r--r--app/auth/forms.py36
-rw-r--r--app/auth/routes.py9
-rw-r--r--app/models.py5
-rw-r--r--migrations/versions/48da31c2de2c_user_flags.py32
-rw-r--r--migrations/versions/b74a19cbe419_.py32
5 files changed, 109 insertions, 5 deletions
diff --git a/app/auth/forms.py b/app/auth/forms.py
index ea194a5..14f390f 100644
--- a/app/auth/forms.py
+++ b/app/auth/forms.py
@@ -1,10 +1,16 @@
# -*- coding: utf-8 -*-
-from flask import current_app
+from flask import current_app, flash
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField, BooleanField
-from wtforms.validators import DataRequired, ValidationError, Email, EqualTo
+from wtforms.validators import (
+ DataRequired,
+ Email,
+ EqualTo,
+ Optional,
+ ValidationError,
+)
from app.models import User
@@ -18,12 +24,24 @@ class LoginForm(FlaskForm):
class RegistrationForm(FlaskForm):
username = StringField("Username", validators=[DataRequired()])
email = StringField("Email", validators=[DataRequired(), Email()])
+ fullname = StringField("Full Name (optional)", validators=[])
password = PasswordField("Password", validators=[DataRequired()])
password2 = PasswordField(
"Repeat Password", validators=[DataRequired(), EqualTo("password")]
)
- toc = BooleanField("I agree to the Terms and Conditions.",
- validators=[DataRequired(), ])
+ toc = BooleanField(
+ "I agree to the Terms and Conditions.", validators=[DataRequired()]
+ )
+ credit = BooleanField(
+ "Check this box if you would like to be publically credited with having "
+ "contributed to this work. By default, users will remain anonymous.",
+ validators=[Optional()],
+ )
+ updated = BooleanField(
+ "Check this box if you wish to be kept up to date with the "
+ "progress of this work by email.",
+ validators=[Optional()],
+ )
submit = SubmitField("Register")
def validate_username(self, username):
@@ -56,6 +74,16 @@ class RegistrationForm(FlaskForm):
"AnnotateChange at this time."
)
+ def validate_credit(self, credit):
+ if credit.data and not self.fullname.data:
+ flash(
+ "Please provide your full name if you wish to "
+ "be credited with contributing to this work.", "error")
+ raise ValidationError(
+ "Please provide your full name if you wish to "
+ "be credited with contributing to this work."
+ )
+
class ResetPasswordRequestForm(FlaskForm):
email = StringField("Email", validators=[DataRequired(), Email()])
diff --git a/app/auth/routes.py b/app/auth/routes.py
index 0e40fbb..fa792c2 100644
--- a/app/auth/routes.py
+++ b/app/auth/routes.py
@@ -134,7 +134,14 @@ def register():
return redirect(url_for("main.index"))
form = RegistrationForm()
if form.validate_on_submit():
- user = User(username=form.username.data, email=form.email.data)
+ user = User(
+ username=form.username.data,
+ email=form.email.data,
+ fullname=form.fullname.data,
+ read_toc=form.toc.data,
+ wants_credit=form.credit.data,
+ wants_updates=form.updated.data,
+ )
user.set_password(form.password.data)
db.session.add(user)
db.session.commit()
diff --git a/app/models.py b/app/models.py
index f7dd2fa..947deb1 100644
--- a/app/models.py
+++ b/app/models.py
@@ -29,6 +29,11 @@ class User(UserMixin, db.Model):
# after all demo tasks completed:
is_introduced = db.Column(db.Boolean(), default=False)
+ # checkboxes during registration
+ read_toc = db.Column(db.Boolean(), default=False)
+ wants_credit = db.Column(db.Boolean(), default=False)
+ wants_updates = db.Column(db.Boolean(), default=False)
+
def __repr__(self):
return "<User %r>" % self.username
diff --git a/migrations/versions/48da31c2de2c_user_flags.py b/migrations/versions/48da31c2de2c_user_flags.py
new file mode 100644
index 0000000..528d18c
--- /dev/null
+++ b/migrations/versions/48da31c2de2c_user_flags.py
@@ -0,0 +1,32 @@
+"""user flags
+
+Revision ID: 48da31c2de2c
+Revises: 43c24fc4dd24
+Create Date: 2019-08-19 16:38:18.529600
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = '48da31c2de2c'
+down_revision = '43c24fc4dd24'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.add_column('user', sa.Column('read_toc', sa.Boolean(), nullable=True))
+ op.add_column('user', sa.Column('wants_credit', sa.Boolean(), nullable=True))
+ op.add_column('user', sa.Column('wants_updates', sa.Boolean(), nullable=True))
+ # ### end Alembic commands ###
+
+
+def downgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.drop_column('user', 'wants_updates')
+ op.drop_column('user', 'wants_credit')
+ op.drop_column('user', 'read_toc')
+ # ### end Alembic commands ###
diff --git a/migrations/versions/b74a19cbe419_.py b/migrations/versions/b74a19cbe419_.py
new file mode 100644
index 0000000..1bade64
--- /dev/null
+++ b/migrations/versions/b74a19cbe419_.py
@@ -0,0 +1,32 @@
+"""empty message
+
+Revision ID: b74a19cbe419
+Revises: 48da31c2de2c
+Create Date: 2019-08-19 16:43:58.062573
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = 'b74a19cbe419'
+down_revision = '48da31c2de2c'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.add_column('user', sa.Column('read_toc', sa.Boolean(), nullable=True))
+ op.add_column('user', sa.Column('wants_credit', sa.Boolean(), nullable=True))
+ op.add_column('user', sa.Column('wants_updates', sa.Boolean(), nullable=True))
+ # ### end Alembic commands ###
+
+
+def downgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.drop_column('user', 'wants_updates')
+ op.drop_column('user', 'wants_credit')
+ op.drop_column('user', 'read_toc')
+ # ### end Alembic commands ###