Skip to content

Instantly share code, notes, and snippets.

@larry-liu
Created July 29, 2015 02:37
Show Gist options
  • Save larry-liu/64610f4a601b44f66420 to your computer and use it in GitHub Desktop.
Save larry-liu/64610f4a601b44f66420 to your computer and use it in GitHub Desktop.
class RegisterForm(Form):
name = TextField('Username', [Required()])
email = TextField('Email address', [Required(), Email()])
password = PasswordField('Password', [Required()])
confirm = PasswordField('Repeat Password', [
Required(),
EqualTo('password', message='Passwords must match')
])
accept_tos = BooleanField('I accept the TOS', [Required()])
recaptcha = RecaptchaField()
def __init__(self, *args, **kwargs):
Form.__init__(self, *args, **kwargs)
self.user = None
def validate(self):
rv = Form.validate(self)
if not rv:
return False
user = User.query.filter_by(
username=self.username.data).first()
if user not is None:
#username exists, some error info
return False
self.user = user
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment