A simple web application that allows invitation based registration to a matrix instance
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.

40 lines
1.5 KiB

6 years ago
6 years ago
6 years ago
  1. from flask_wtf import FlaskForm
  2. from wtforms import StringField, PasswordField, DateField, IntegerField, SubmitField
  3. from wtforms.validators import DataRequired, Length, EqualTo, InputRequired, \
  4. ValidationError, NumberRange, Optional
  5. import safe
  6. def safe_password_validator(form: FlaskForm, field):
  7. strength = safe.check(field.data, level=safe.MEDIUM)
  8. if not strength.valid:
  9. raise ValidationError("Password is not secure enough: %s" % strength.message)
  10. class RegistrationForm(FlaskForm):
  11. username = StringField('Username', validators=[DataRequired(), Length(min=3, max=30)])
  12. password = PasswordField(
  13. 'Password',
  14. validators=[
  15. InputRequired(),
  16. EqualTo('confirm', message='Passwords must match'),
  17. safe_password_validator
  18. ])
  19. confirm = PasswordField('Repeat Password')
  20. registration_code = StringField('Registration Code', validators=[DataRequired()])
  21. class LoginForm(FlaskForm):
  22. username = StringField('Username', validators=[DataRequired()])
  23. token = PasswordField('Token', validators=[DataRequired()])
  24. class RegistrationCodeForm(FlaskForm):
  25. expiration_time = DateField('Expiration Time', validators=[Optional()])
  26. max_usages = IntegerField('Max Usages', validators=[NumberRange(min=1)])
  27. class ExpireRegistrationCodeForm(FlaskForm):
  28. registration_code = StringField('Registration Code')
  29. expire = SubmitField(label='Expire')
  30. delete = SubmitField(label='Delete')