from flask_wtf import FlaskForm from wtforms import StringField, PasswordField, SubmitField, BooleanField from wtforms.validators import DataRequired, EqualTo, ValidationError, Length from app.models import User class LoginForm(FlaskForm): username = StringField('Username', validators=[DataRequired()]) password = PasswordField('Password', validators=[DataRequired()]) remember_me = BooleanField('Remember Me', default=True) submit = SubmitField('Sign In') class RegistrationForm(FlaskForm): username = StringField('Username', validators=[DataRequired(), Length(min=0, max=64)]) password = PasswordField('Password', validators=[DataRequired(), Length(min=0, max=128)]) password2 = PasswordField( 'Repeat Password', validators=[DataRequired(), EqualTo('password')]) submit = SubmitField('Register') def validate_username(self, username): user = User.query.filter_by(name=username.data).first() if user is not None: raise ValidationError('Please use a different username.') class ChangePasswordForm(FlaskForm): old_password = PasswordField('Old Password', validators=[DataRequired(), Length(min=0, max=128)]) new_password = PasswordField('New Password', validators=[DataRequired(), Length(min=0, max=128)]) new_password2 = PasswordField( 'Repeat New Password', validators=[DataRequired(), EqualTo('new_password')]) submit = SubmitField('Apply') class SetPasswordForm(FlaskForm): new_password = PasswordField('New Password', validators=[DataRequired(), Length(min=0, max=128)]) new_password2 = PasswordField( 'Repeat New Password', validators=[DataRequired(), EqualTo('new_password')]) submit = SubmitField('Set Password')