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 UserRegisterForm(wtf.Form): username = wtf.TextField( 'Username', validators=[ wtf.Required(), wtf.Length(min=2, max=50), wtf.Regexp( '^[a-zA-Z0-9_]*$', message= ('Username must only contain a to z, 0 to 9, and underscores.' )) ], description=( 'Your username is public and used as part of your project name.')) email = wtf.TextField('Email', validators=[wtf.Required(), wtf.validators.Email()]) password = wtf.PasswordField('Password', validators=[ wtf.Required(), wtf.Length(5), wtf.EqualTo('confirm', 'Passwords do not match.'), ]) confirm = wtf.PasswordField('Confirm Password') def validate_username(form, field): from notifico.views.account import _reserved username = field.data.strip().lower() if username in _reserved or User.username_exists(username): raise wtf.ValidationError('Sorry, but that username is taken.')
class UserPasswordForm(wtf.Form): password = wtf.PasswordField('Password', validators=[ wtf.Required(), wtf.Length(5), wtf.EqualTo('confirm', 'Passwords do not match.'), ]) confirm = wtf.PasswordField('Confirm Password')
class ChangePasswordForm(wtf.Form): password = wtf.PasswordField('Password', validators=[ wtf.Required(), wtf.EqualTo( 'confirm', message='Passwords must match.') ]) confirm = wtf.PasswordField('Repeat Password', validators=[wtf.Required()]) submit = wtf.SubmitField('Save')
class PasswordChangeForm(Form): old_password = wtf.PasswordField('Current password', validators=[wtf.Required()]) password = wtf.PasswordField('New password', validators=[wtf.Required()]) confirm_password = wtf.PasswordField( 'Confirm password', validators=[wtf.Required(), wtf.EqualTo('password')]) def validate_old_password(self, field): if g.user is None: raise wtf.ValidationError, "Not logged in" if not g.user.password_is(field.data): raise wtf.ValidationError, "Incorrect password"
class UserDeleteForm(wtf.Form): password = wtf.PasswordField('Password', validators=[ wtf.Required(), wtf.Length(5), wtf.EqualTo('confirm', 'Passwords do not match.'), ]) confirm = wtf.PasswordField('Confirm Password') def validate_password(form, field): if not User.login(g.user.username, field.data): raise wtf.ValidationError('Password is incorrect.')
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 EditPassForm(RedirectForm): old_password = wtf.PasswordField( u'当前密码', validators=[wtf.Required(message=u'请提供当前密码')]) password = wtf.PasswordField(u'新密码', validators=[ \ wtf.Required(message=u'请填写新密码,不能少与5位字符'), \ wtf.EqualTo('confirm', message=u'两次输入的密码不一致'), \ wtf.Length(min=5, max=20, message=u'密码应为5到20位字符') ]) confirm = wtf.PasswordField(u'确认密码', validators=[wtf.Required(message=u'请再次输入新密码')]) def validate_old_password(form, field): if not current_user.user.check_password(field.data): raise wtf.ValidationError(u'提供的原始密码不正确')
class PasswordForm(Form): """Password changing form.""" old_password = wtf.PasswordField('Old password', validators=[ wtf.Required(), ]) new_password = wtf.PasswordField('New password', validators=[ wtf.Required(), ]) password_check = wtf.PasswordField('New password once more', validators=[ wtf.EqualTo( 'new_password', message='Passwords must match'), ], description='protection against typos')
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 PasswordResetForm(Form): password = wtf.PasswordField('New password', validators=[wtf.Required()]) confirm_password = wtf.PasswordField( 'Confirm password', validators=[wtf.Required(), wtf.EqualTo('password')])