Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
securelearn/forms.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
37 lines (26 sloc)
1.5 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# forms.py | |
from flask_wtf import FlaskForm | |
from wtforms import StringField, PasswordField, SubmitField, TextAreaField | |
from wtforms.validators import InputRequired, Email, Length, ValidationError | |
from helpers import load_deny_list | |
class LoginForm(FlaskForm): | |
email = StringField('Email', validators=[InputRequired(), Email(), Length(min=6, max=55)]) | |
password = PasswordField('Password', validators=[InputRequired()]) | |
submit = SubmitField('Login') | |
class RegistrationForm(FlaskForm): | |
email = StringField('Email', validators=[InputRequired(), Email(), Length(min=6, max=55)]) | |
password = PasswordField('Password', validators=[InputRequired(), Length(min=8, max=30)], | |
description='Password must be at least 8 characters long but no more than 30 characters.') | |
submit = SubmitField('Register') | |
def validate_password(self, password): | |
deny_list = load_deny_list() | |
if password.data.lower() in deny_list: | |
raise ValidationError('Password is too common.') | |
class ModuleForm(FlaskForm): | |
code = StringField('Code', validators=[InputRequired(), Length(min=2, max=7)]) | |
name = StringField('Title', validators=[InputRequired(), Length(min=7, max=55)]) | |
description = StringField('Description', validators=[InputRequired(), Length(min=2, max=255)]) | |
submit = SubmitField('Add Module') | |
class CommentForm(FlaskForm): | |
text = TextAreaField('Comment', validators=[InputRequired(), Length(min=1, max=400)]) | |
submit = SubmitField('Add Comment') |