Files
runnerspace/forms.py
Xevion d16df75bf5 Add better message hints to RegEx validators
I realized that users wouldn't be able to understand why their username
was invalid, so rather than getting rid of it, I added message hints
and split it up into two different validators. If the first one fails,
the second one will show as well.

Not perfect, but better than before by a longshot.
2022-03-30 01:33:17 -05:00

40 lines
1.8 KiB
Python

from flask_wtf import FlaskForm
from wtforms import BooleanField, StringField, PasswordField, TextAreaField, validators
from validators import NoProfanity
class RegistrationForm(FlaskForm):
username = StringField('Username', [validators.Length(min=4, max=25),
validators.Regexp(r'^[a-zA-Z0-9_\.]+$',
message='Only letters, numbers, underscore character and dots are allowed.'),
validators.Regexp(r'^[a-zA-Z0-9]+([._]?[a-zA-Z0-9]+)*$',
message='Dots and underscores cannot be at the start of the username, repeat or touch.'),
NoProfanity()])
name = StringField('Name', [validators.Length(min=2, max=35), NoProfanity()])
password = PasswordField('New Password', [
validators.DataRequired(),
validators.EqualTo('confirm', message='Passwords must match')
])
confirm = PasswordField('Repeat Password')
accept_tos = BooleanField('I accept the TOS', [validators.DataRequired()])
class LoginForm(FlaskForm):
username = StringField('Username', [validators.DataRequired()])
password = StringField('Password', [validators.DataRequired()])
remember_me = BooleanField('Remember Me', [validators.Optional()])
class EditProfileForm(FlaskForm):
name = RegistrationForm.name
about_me = TextAreaField('About Me', [validators.Optional(), NoProfanity()], description='Tell us about yourself', )
class NewPostForm(FlaskForm):
text = TextAreaField('Text', [validators.Length(min=15, max=1000), NoProfanity()], description='Express yourself.')
class NewCommentForm(FlaskForm):
text = StringField('Text', [validators.Length(min=1, max=50), NoProfanity()])