La version 5 de Planète Casio. Regroupe le forum, les programmes, les tutoriel, les sprites et tous les autres outils développés par nos soins.
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.

validators.py 1.2KB

12345678910111213141516171819202122232425262728293031
  1. from flask_login import current_user
  2. from wtforms.validators import ValidationError
  3. from app.models.users import User, Member
  4. def name(form, name):
  5. if not User.valid_name(name.data):
  6. raise ValidationError("Nom d'utilisateur invalide.")
  7. # last check: do not ask db if useless
  8. member = Member.query.filter_by(name=name.data).first()
  9. if member is not None:
  10. raise ValidationError('Pseudo indisponible.')
  11. def email(form, email):
  12. member = Member.query.filter_by(email=email.data).first()
  13. if member is not None:
  14. raise ValidationError('Adresse email déjà utilisée.')
  15. def password(form, password):
  16. if len(password.data) != 0 and len(password.data) < 10:
  17. raise ValidationError('Mot de passe est trop court (10 caractères minimum).')
  18. # TODO: add more rules >:]
  19. def avatar(form, avatar):
  20. pass
  21. def old_password(form, field):
  22. if field.data:
  23. if not form.old_password.data:
  24. raise ValidationError('Votre ancien mot de passe est requis pour cette modification.')
  25. if not current_user.check_password(form.old_password.data):
  26. raise ValidationError('Mot de passe actuel erroné.')