class SigninForm(wtf.Form): email = wtf.TextField('email', validators=[ wtf.Required(message=u'请填写电子邮件'), wtf.Email(message=u'无效的电子邮件') ]) password = wtf.PasswordField('password', validators=[ wtf.Required(message=u'请填写密码'), wtf.Length(min=5, max=20, message=u'密应应为5到20位字符') ]) next = wtf.HiddenField('next') remember = wtf.BooleanField('remember') openid_identifier = wtf.HiddenField('openid_identifier') openid_provider = wtf.HiddenField('openid_provider') def __init__(self, *args, **kargs): wtf.Form.__init__(self, *args, **kargs) self.user = None def validate(self): # 验证邮箱是否注册 if wtf.Form.validate(self): user = get_user(email=self.email.data) if not user: self.email.errors.append(u'该邮箱尚未在本站注册') elif not user.check_password(self.password.data): self.password.errors.append(u'密码错误') else: self.user = user return len(self.errors) == 0
class RegisterForm(Form): fullname = wtf.TextField('Full name', validators=[wtf.Required()]) email = wtf.html5.EmailField('Email address', validators=[wtf.Required(), wtf.Email()]) username = wtf.TextField('Username (optional)', validators=[wtf.Optional()]) password = wtf.PasswordField('Password', validators=[wtf.Required()]) confirm_password = wtf.PasswordField( 'Confirm password', validators=[wtf.Required(), wtf.EqualTo('password')]) recaptcha = wtf.RecaptchaField( 'Are you human?', description="Type both words into the text box") def validate_username(self, field): if field.data in RESERVED_USERNAMES: raise wtf.ValidationError, "That name is reserved" if not valid_username(field.data): raise wtf.ValidationError( u"Invalid characters in name. Names must be made of ‘a-z’, ‘0-9’ and ‘-’, without trailing dashes" ) existing = User.query.filter_by(username=field.data).first() if existing is not None: raise wtf.ValidationError("That username is taken") def validate_email(self, field): existing = UserEmail.query.filter_by(email=field.data).first() if existing is not None: raise wtf.ValidationError( Markup( 'This email address is already registered. Do you want to <a href="%s">login</a> instead?' % url_for('login')))
class SignUpForm(Form): """Sign up form.""" name = wtf.TextField('Name', validators=[ wtf.Required(), wtf.Length(max=100), ], description='e.g. Johnny') primary_email = wtf.TextField('E-mail', validators=[ wtf.Required(), wtf.Email(), wtf.Length(max=100), ]) password = wtf.PasswordField('Password', validators=[ wtf.Required(), ]) password_check = wtf.PasswordField('Password once more', validators=[ wtf.EqualTo( 'password', message='Passwords must match'), ], description='protection against typos')
class ProfileNewForm(ProfileFormBase, Form): fullname = wtf.TextField('Full name', validators=[wtf.Required()]) email = wtf.html5.EmailField('Email address', validators=[wtf.Required(), wtf.Email()]) username = wtf.TextField('Username (optional)') description = wtf.TextAreaField('Bio') def validate_email(self, field): existing = UserEmail.query.filter_by(email=field.data).first() self.existing_email = existing # Save for later if existing is not None and existing.user != self.edit_obj: raise wtf.ValidationError( "This email address has been claimed by another user.")
class SignupForm(wtf.Form): email = wtf.TextField('email', validators=[ wtf.Required(message=u'请填写电子邮件'), wtf.Email(message=u'无效的电子邮件') ]) nickname = wtf.TextField('nickname', validators=[ wtf.Required(message=u'请填写昵称'), wtf.Length(min=2, max=20, message=u'昵称应为2到20字符') ]) password = wtf.PasswordField('password', validators=[ wtf.Required(message=u'请填写密码'), wtf.Length(min=5, max=20, message=u'密码应为5到20位字符') ]) repassword = wtf.PasswordField('repassword', validators=[ wtf.Required(message=u'请填写确认密码'), wtf.EqualTo('password', message=u'两次输入的密码不一致') ]) next = wtf.HiddenField('next') def __init__(self, *args, **kargs): wtf.Form.__init__(self, *args, **kargs) self.user = None def validate(self): wtf.Form.validate(self) # 验证邮箱是否注册 if not self.email.errors: user = get_user(email=self.email.data) user and self.email.errors.append(u'该邮箱已被注册') self.user = User(email=self.email.data, nickname=self.nickname.data, openids=[ UserOpenID(provider=session['openid_provider'], openid=session['current_openid']) ]) self.user.set_password(self.password.data) self.user.info = UserInfo() return len(self.errors) == 0
class EmailContactForm(Form): """Basic email contact creation form.""" name = wtf.TextField('Name', validators=[ wtf.Required(), wtf.Length(max=100), ], description='e.g. Susan') email = wtf.TextField('E-mail', validators=[ wtf.Required(), wtf.Email(), wtf.Length(max=100), ])
class ProfileForm(wtf.Form): password = wtf.PasswordField('Password', validators=[ wtf.Required(), wtf.EqualTo( 'confirm', message='Passwords must match.') ]) confirm = wtf.PasswordField('Repeat Password', validators=[wtf.Required()]) name = wtf.TextField('Screen name', validators=[wtf.Required(), wtf.Length(1, 45)]) email = wtf.html5.EmailField('Email', validators=[wtf.Optional(), wtf.Email()]) url = wtf.html5.URLField('Website', validators=[wtf.Optional(), wtf.URL()]) submit = wtf.SubmitField('Save')
class SignUpForm(wtf.Form): login = wtf.TextField('Login name', validators=[ wtf.Required(), wtf.Length(2, 45), wtf.Regexp(User.LOGIN_PATTERN) ]) password = wtf.PasswordField('Password', validators=[ wtf.Required(), wtf.EqualTo( 'confirm', message='Passwords must match.') ]) confirm = wtf.PasswordField('Repeat Password', validators=[wtf.Required()]) name = wtf.TextField('Screen name', validators=[wtf.Required(), wtf.Length(1, 45)]) email = wtf.html5.EmailField('Email', validators=[wtf.Optional(), wtf.Email()]) url = wtf.html5.URLField('Website', validators=[wtf.Optional(), wtf.URL()]) @classmethod def get_instance(cls, *args, **kwargs): if ('RECAPTCHA_PUBLIC_KEY' in current_app.config and 'RECAPTCHA_PRIVATE_KEY' in current_app.config): class SignUpForm_recaptcha(cls): recaptcha = wtf.RecaptchaField() submit = wtf.SubmitField('Sign up') return SignUpForm_recaptcha(*args, **kwargs) class SignUpForm_plain(cls): submit = wtf.SubmitField('Sign up') return SignUpForm_plain(*args, **kwargs) def validate_login(form, field): if g.session.query(User).filter_by(login=field.data).count(): raise wtf.ValidationError('{0} is already taken.'.format( field.data))
class NewEmailAddressForm(Form): email = wtf.html5.EmailField('Email address', validators=[wtf.Required(), wtf.Email()]) def validate_email(self, field): existing = UserEmail.query.filter_by(email=field.data).first() if existing is not None: if existing.user == g.user: raise wtf.ValidationError( "You have already registered this email address.") else: raise wtf.ValidationError( "This email address has already been claimed.") existing = UserEmailClaim.query.filter_by(email=field.data, user=g.user).first() if existing is not None: raise wtf.ValidationError( "This email address is pending verification.")
class SettingsForm(Form): """Simple settings form.""" name = wtf.TextField('Name', validators=[ wtf.Required(), wtf.Length(max=100), ], description='e.g. Johnny') email = wtf.TextField('E-mail', validators=[ wtf.Required(), wtf.Email(), wtf.Length(max=100), ]) timezone = wtf.SelectField('My timezone is', choices=tz_choices(), validators=[ wtf.Required(), ])
class ProfileForm(Form): fullname = wtf.TextField('Full name', validators=[wtf.Required()]) email = wtf.html5.EmailField('Email address', validators=[wtf.Required(), wtf.Email()]) username = wtf.TextField('Username', validators=[wtf.Required()]) description = wtf.TextAreaField('Bio') timezone = wtf.SelectField('Timezone', validators=[wtf.Required()], choices=timezones) def __init__(self, *args, **kwargs): super(ProfileForm, self).__init__(*args, **kwargs) self.existing_email = None def validate_username(self, field): ## Usernames are now mandatory. This should be commented out: # if not field.data: # field.data = None # return if not valid_username(field.data): raise wtf.ValidationError("Invalid characters in username") if field.data in RESERVED_USERNAMES: raise wtf.ValidationError("That name is reserved") existing = User.query.filter_by(username=field.data).first() if existing is not None and existing.id != self.edit_id: raise wtf.ValidationError("That username is taken") existing = Organization.query.filter_by(name=field.data).first() if existing is not None: raise wtf.ValidationError("That username is taken") def validate_email(self, field): existing = UserEmail.query.filter_by(email=field.data).first() if existing is not None and existing.user != self.edit_obj: raise wtf.ValidationError( "This email address has been claimed by another user.")