From d1d5e5f11460f50f9d8e1ae4bc80ff327014e685 Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Mon, 8 Jul 2019 14:06:35 +0200 Subject: [PATCH] Add registration form, view, template --- app/auth/forms.py | 20 +++++++- app/templates/auth/login.html.j2 | 6 +-- app/templates/auth/register.html.j2 | 68 +++++++++++++++++----------- app/templates/base.html.j2 | 1 + data_dev.sqlite | Bin 32768 -> 32768 bytes 5 files changed, 64 insertions(+), 31 deletions(-) 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 @@

Sign in into an exisiting account or register a new one!


-
- Register -
+
+ Register +
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 %}
-
-
-
- Register -
-
- - -
-
- - -
-
-
- - -
-
-
-
- - -
-
-
-
+
+
+ Register +
+ {{ form.hidden_tag() }} +
+ account_circle + {{ form.username(class='validate') }} + {{ form.username.label }} + {% for error in form.username.errors %} + {{ error }} + {% endfor %} +
+
+ vpn_key + {{ form.password(class='validate') }} + {{ form.password.label }} + {% for error in form.password.errors %} + {{ error }} + {% endfor %} +
+
+ vpn_key + {{ form.password2(class='validate') }} + {{ form.password2.label }} + {% for error in form.password2.errors %} + {{ error }} + {% endfor %} +
+
+ email + {{ form.email(class='validate', type='email') }} + {{ form.email.label }} + {% for error in form.email.errors %} + {{ error }} + {% endfor %} +
+
+ {{ form.submit(class='btn right') }} +
+
diff --git a/app/templates/base.html.j2 b/app/templates/base.html.j2 index 46aa1d10..40601f13 100644 --- a/app/templates/base.html.j2 +++ b/app/templates/base.html.j2 @@ -25,6 +25,7 @@
  • chevron_leftLog out
  • {% else %}
  • chevron_rightLog in
  • +
  • chevron_rightRegister
  • {% endif %}