Code source de Planète Casio https://planet-casio.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.2KB

  1. from flask_wtf import FlaskForm
  2. from wtforms import StringField, PasswordField, BooleanField, SubmitField
  3. from wtforms.validators import ValidationError, DataRequired, Email, EqualTo
  4. from app.models import User
  5. class LoginForm(FlaskForm):
  6. username = StringField('Pseudonyme :', validators=[DataRequired()])
  7. password = PasswordField('Mot de passe :', validators=[DataRequired()])
  8. remember_me = BooleanField('Se souvenir de moi :')
  9. submit = SubmitField('Connexion')
  10. class RegistrationForm(FlaskForm):
  11. username = StringField('Pseudonyme :', validators=[DataRequired()])
  12. email = StringField('Adresse Email :', validators=[DataRequired(), Email()])
  13. password = PasswordField('Mot de passe :', validators=[DataRequired()])
  14. password2 = PasswordField('Répéter le mot de passe', validators=[DataRequired(), EqualTo('password')])
  15. submit = SubmitField('S\'enregistrer')
  16. def validate_username(self, username):
  17. user = User.query.filter_by(username=username.data).first()
  18. if user is not None:
  19. raise ValidationError('Pseudo indisponible.')
  20. def validate_email(self, email):
  21. user = User.query.filter_by(email=email.data).first()
  22. if user is not None:
  23. raise ValidationError('Adresse email déjà utilisé.')