Beispiel #1
0
class UserForm(Form, wtforms.ext.i18n.form.Form):
    username = TextField(lazy_gettext('login.placeholder.username'), [
        validators.Length(min=2, max=25),
        validators.Regexp('^\w+$',
                          message=lazy_gettext('signup.error.alphanum'))
    ])
    password = PasswordField(lazy_gettext('login.placeholder.password'),
                             [validators.Required()])
Beispiel #2
0
class SpammerForm(Form):
    error_msg = u"""The address you tried to add is wrong. Please type it 
like this:<ul><li>Everything <em>after</em> the "@" sign, with no spaces.</li>
<li>Example: <strong>enterprise-weasels.co.uk</strong></li></ul>"""
    address = StringField(u"Address Entry", [
        validators.DataRequired(message=u"You have to enter an address."),
        validators.Regexp(reg, flags=0, message=error_msg)
    ])
    submit = SubmitField()
Beispiel #3
0
class SpammerForm(Form):
    address = StringField(u"Address Entry", [
        validators.DataRequired(message=u"You must enter an address."),
        validators.Regexp(
            reg,
            flags=0,
            message=u"Invalid address. The address must begin with an '@'.")
    ])
    submit = SubmitField()
Beispiel #4
0
class CreditCardForm(Form):
    phone_regex = '[\d\.\-\+\() ]+'
    name = TextField('Name', validators=[Required("Please enter your name")])
    email = TextField(
        'Email',
        validators=[Optional(),
                    validators.email("Your email is not valid")])
    phone = TextField('Phone',
                      validators=[
                          Optional(),
                          validators.Regexp(
                              phone_regex,
                              message="Your phone number is not valid")
                      ])
    address1 = TextField('Address 1',
                         validators=[Required("Please enter your address")])
    address2 = TextField('Address 2', validators=[Optional()])
    city = TextField('City', validators=[Required("Please enter your city")])
    state = SelectField('State',
                        choices=[("1", "State"), ("2", "Alabama"),
                                 ("3", "Alaska"), ("4", "Arizona"),
                                 ("5", "Arkansas"), ("6", "California"),
                                 ("7", "Colorado"), ("8", "Connecticut"),
                                 ("9", "Delaware"), ("10", "Florida"),
                                 ("11", "Georgia"), ("12", "Hawaii"),
                                 ("13", "Idaho"), ("14", "Illinois"),
                                 ("15", "Indiana"), ("16", "Iowa"),
                                 ("17", "Kansas"), ("18", "Kentucky"),
                                 ("19", "Louisiana"), ("20", "Maine"),
                                 ("21", "Maryland"), ("22", "Massachusetts"),
                                 ("23", "Michigan"), ("24", "Minnesota"),
                                 ("25", "Mississippi"), ("26", "Missouri"),
                                 ("27", "Montana"), ("28", "Nebraska"),
                                 ("29", "Nevada"), ("30", "New Hampshire"),
                                 ("31", "New Jersey"), ("32", "New Mexico"),
                                 ("33", "New York"), ("34", "North Carolina"),
                                 ("35", "North Dakota"), ("36", "Ohio"),
                                 ("37", "Oklahoma"), ("38", "Oregon"),
                                 ("39", "Pennsylvania"),
                                 ("40", "Rhode Island"),
                                 ("41", "South Carolina"),
                                 ("42", "South Dakota"), ("43", "Tennessee"),
                                 ("44", "Texas"), ("45", "Utah"),
                                 ("46", "Vermont"), ("47", "Virginia"),
                                 ("48", "Washington"), ("49", "West Virginia"),
                                 ("50", "Wisconsin"), ("51", "Wyoming")],
                        validators=[Required("Please choose your state")])
    zipcode = TextField('Zip Code',
                        validators=[Required("Please enter your zip code")])
    country = TextField('Country',
                        validators=[Required("Please choose your country")])
    submit = SubmitField()
Beispiel #5
0
class ContactForm(Form):
    phone_regex = '[\d\.\-\+\() ]+'
    name = TextField('Name', validators=[Required("Please enter your name")])
    email = TextField('Email',
                      validators=[
                          Required("Please enter your email address"),
                          validators.email("Your email is not valid")
                      ])
    phone = TextField('Phone',
                      validators=[
                          Optional(),
                          validators.Regexp(
                              phone_regex,
                              message="Your phone number is not valid")
                      ])
    message = TextAreaField('Message')
    send = SubmitField()
Beispiel #6
0
class SignupForm(Form):
    username = f.TextField('Username', [
        v.Length(min=3, max=128),
        v.Regexp(r'^[^@:]*$', message="Username shouldn't contain '@' or ':'")
    ])
    email = html5.EmailField('Email address', [
        v.Length(min=3, max=128),
        v.Email(message="This should be a valid email address.")
    ])
    password = f.PasswordField('Password', [
        v.Required(),
        v.Length(min=8, message="It's probably best if your password is longer than 8 characters."),
        v.EqualTo('confirm', message="Passwords must match.")
    ])
    confirm = f.PasswordField('Confirm password')

    # Will only work if set up in config (see http://packages.python.org/Flask-WTF/)
    captcha = f.RecaptchaField('Captcha')
Beispiel #7
0
class RegistrationForm(Form):
    phone_regex = '[\d\.\-\+\() ]+'
    name = TextField('Name', validators=[Required("Please enter your name")])
    email = TextField('Email',
                      validators=[
                          Required("Please enter your email address"),
                          validators.email("Your email address is not valid")
                      ])
    phone = TextField('Phone',
                      validators=[
                          Optional(),
                          validators.Regexp(
                              phone_regex,
                              message="Your phone number is not valid")
                      ])
    company = TextField('Company')
    tell_me_more = SubmitField()
    sign_up = SubmitField()
    pagename = HiddenField()
Beispiel #8
0
def login_validator(form, field):
    invalid_chars = [
        c for c in field.data
        if c.isupper() or not c.isalnum() and c not in '._'
    ]
    if invalid_chars:
        raise ValidationError(
            gettext('Invalid characters found: %(char)s',
                    char=', '.join(invalid_chars)))
    if len(field.data) < 5:
        raise ValidationError(
            gettext('login lenght must be at least 5 characters long'))


USER_LOGIN_DEFAULT_VALIDATORS = [
    validators.Regexp("^[a-z0-9\.\_]{5,}$"), login_validator
]


def password_validator(form, field):
    if len(field.data) > 0:
        invalid_chars = [c for c in field.data if c.isspace()]
    if invalid_chars:
        raise ValidationError(gettext('Passwords can not contain a space'))
    if len(field.data) < 8:
        raise ValidationError(
            gettext('password lenght must be at least 8 characters long'))


USER_PASSWORD_DEFAULT_VALIDATORS = [
    validators.Optional(),