Skip to content

Commit

Permalink
added validators for registration form
Browse files Browse the repository at this point in the history
  • Loading branch information
p-koskey committed Sep 24, 2020
1 parent 5169f1a commit dd60ab6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/auth/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask_wtf import FlaskForm
from flask import flash
from wtforms import StringField,PasswordField,SubmitField
from wtforms.validators import Required,Email,EqualTo
from wtforms import StringField,PasswordField,BooleanField,SubmitField
Expand All @@ -15,11 +16,15 @@ class RegistrationForm(FlaskForm):

def validate_email(self,data_field):
if User.query.filter_by(email =data_field.data).first():
raise ValidationError('There is an account with that email')
flash ('There is an account with that email', 'danger')

def validate_username(self,data_field):
if User.query.filter_by(username = data_field.data).first():
raise ValidationError('That username is taken')
flash('That username is taken', 'danger')

def validate_password(self,pass1=password,pass2=password_confirm):
if pass1 != pass2:
flash('Passwords must match','danger')

class LoginForm(FlaskForm):
email = StringField('Your Email Address:',validators=[Required(),Email()])
Expand Down
7 changes: 7 additions & 0 deletions app/templates/auth/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ <h1 class="text-center"><i class="fa fa-user-edit"></i> Sign up to Pitches</h1>
<div class="row mt-3">
<div class="col-md-2"> </div>
<div class="col-md-8">
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }}"> {{ message|capitalize }} </div>
{% endfor %}
{% endif %}
{% endwith %}

{{wtf.quick_form(registration_form)}}

Expand Down

0 comments on commit dd60ab6

Please sign in to comment.