diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-08-19 16:42:38 +0100 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-08-19 16:45:13 +0100 |
| commit | d2bd7472dec27d7ebcb88a05517b9394b63df014 (patch) | |
| tree | 96ccc4cc8436965f8413572d38944d1052a538fa /app/auth | |
| parent | Code quality (diff) | |
| download | AnnotateChange-d2bd7472dec27d7ebcb88a05517b9394b63df014.tar.gz AnnotateChange-d2bd7472dec27d7ebcb88a05517b9394b63df014.zip | |
Add various user flags for registration
Diffstat (limited to 'app/auth')
| -rw-r--r-- | app/auth/forms.py | 36 | ||||
| -rw-r--r-- | app/auth/routes.py | 9 |
2 files changed, 40 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() |
