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.

validators.py 1.2KB

1234567891011121314151617181920212223242526272829303132
  1. from flask_login import current_user
  2. from wtforms.validators import ValidationError
  3. from app.models.users import User, Member
  4. def name_valid(form, name):
  5. if not User.valid_name(name.data):
  6. raise ValidationError("Nom d'utilisateur invalide.")
  7. def name_available(form, name):
  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é.')