diff --git a/app/auth/forms.py b/app/auth/forms.py index 43a64679..3a71b095 100644 --- a/app/auth/forms.py +++ b/app/auth/forms.py @@ -14,7 +14,25 @@ class LoginForm(FlaskForm): class RegistrationForm(FlaskForm): - email = StringField('Email', validators=[DataRequired(), Length(1, 64), Email()]) + email = StringField('Email', validators=[DataRequired(), Length(1, 64), + Email()]) + username = StringField('Username', validators=[ + DataRequired(), Length(1, 64), + Regexp('^[A-Za-z][A-Za-z0-9_.]*$', 0, + 'Usernames must have only letters, numbers, dots or ' + 'underscores')]) + password = PasswordField('Password', validators=[ + DataRequired(), EqualTo('password2', message='Passwords must match.')]) + password2 = PasswordField('Confirm password', validators=[DataRequired()]) + submit = SubmitField('Register') + + def validate_email(self, field): + if User.query.filter_by(email=field.data.lower()).first(): + raise ValidationError('Email already registered.') + + def validate_username(self, field): + if User.query.filter_by(username=field.data).first(): + raise ValidationError('Username already in use.') class PasswordResetRequestForm(FlaskForm): diff --git a/app/templates/auth/login.html.j2 b/app/templates/auth/login.html.j2 index 325e99c4..3c9fdf4a 100644 --- a/app/templates/auth/login.html.j2 +++ b/app/templates/auth/login.html.j2 @@ -10,9 +10,9 @@
diff --git a/app/templates/auth/register.html.j2 b/app/templates/auth/register.html.j2 index 6a85c9a9..52070a1a 100644 --- a/app/templates/auth/register.html.j2 +++ b/app/templates/auth/register.html.j2 @@ -2,33 +2,47 @@ {% block page_content %}