aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/auth/forms.py36
-rw-r--r--app/auth/routes.py9
-rw-r--r--app/models.py5
3 files changed, 45 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