-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms.py
28 lines (23 loc) · 1.29 KB
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from flask_wtf import FlaskForm as Form
from wtforms import validators, StringField, EmailField, PasswordField, SubmitField, TextAreaField, ValidationError
from models import User
class RegistrationForm(Form):
username = StringField('Username', [validators.DataRequired() ,validators.Length(min=3, max=25)], render_kw={'autofocus': True})
email = EmailField('Email', [validators.InputRequired(), validators.Length(min=6, max=50)])
password = PasswordField('Password',
[validators.DataRequired(),
validators.EqualTo('confirm', message='Passwords do not match')
])
confirm = PasswordField('Confirm Password')
submit = SubmitField('Sign Up')
def validate_username(self, username):
user = User.query.filter_by(username=username.data).first()
if user:
raise ValidationError("Username already exists, please try again.")
def validate_email(self, email):
user = User.query.filter_by(email=email.data).first()
if user:
raise ValidationError("Email is taken!")
class ArticleForm(Form):
title = StringField('Title', [validators.InputRequired()])
body = TextAreaField('Body', [validators.Length(min=1)], render_kw={'id': 'mytextarea', 'placeholder': "Unleash the Krakken!"})