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.

53 lines
2.2 KiB

4 years ago
  1. # -*- coding: utf-8 -*-
  2. """
  3. :author: Grey Li ()
  4. :url: http://greyli.com
  5. :copyright: © 2018 Grey Li <withlihui@gmail.com>
  6. :license: MIT, see LICENSE for more details.
  7. """
  8. from flask_wtf import FlaskForm
  9. from wtforms import StringField, PasswordField, SubmitField, BooleanField
  10. from wtforms import ValidationError
  11. from wtforms.validators import DataRequired, Length, Email, EqualTo, Regexp
  12. from albumy.models import User
  13. class LoginForm(FlaskForm):
  14. email = StringField('邮箱', validators=[DataRequired(), Length(1, 254), Email()])
  15. password = PasswordField('密码', validators=[DataRequired()])
  16. remember_me = BooleanField('记住我')
  17. submit = SubmitField('登陆')
  18. class RegisterForm(FlaskForm):
  19. name = StringField('名称', validators=[DataRequired(), Length(1, 30)])
  20. email = StringField('邮箱', validators=[DataRequired(), Length(1, 254), Email()])
  21. username = StringField('用户名', validators=[DataRequired(), Length(1, 20),
  22. Regexp('^[a-zA-Z0-9]*$',
  23. message='用户名称必须包含 a-z, A-Z 和 0-9')])
  24. password = PasswordField('密码', validators=[
  25. DataRequired(), Length(8, 128), EqualTo('password2')])
  26. password2 = PasswordField('确认密码', validators=[DataRequired()])
  27. submit = SubmitField('提交')
  28. def validate_email(self, field):
  29. if User.query.filter_by(email=field.data.lower()).first():
  30. raise ValidationError('该邮箱已被注册')
  31. def validate_username(self, field):
  32. if User.query.filter_by(username=field.data).first():
  33. raise ValidationError('该用户名已被注册')
  34. class ForgetPasswordForm(FlaskForm):
  35. email = StringField('邮箱', validators=[DataRequired(), Length(1, 254), Email()])
  36. submit = SubmitField('提交')
  37. class ResetPasswordForm(FlaskForm):
  38. email = StringField('邮箱', validators=[DataRequired(), Length(1, 254), Email()])
  39. password = PasswordField('密码', validators=[
  40. DataRequired(), Length(8, 128), EqualTo('password2')])
  41. password2 = PasswordField('确认密码', validators=[DataRequired()])
  42. submit = SubmitField('提交')