Beispiel #1
0
class Passenger(Form):
    firstName = StringField(
        "<strong>First Name</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=45),
                    Alpha()])
    lastName = StringField(
        "<strong>Last Name</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=45),
                    Alpha()])
    passport = StringField(
        "<strong>Passport Number</strong>",
        validators=[InputRequired(),
                    Length(min=6, max=9),
                    AlphaNumeric()])
Beispiel #2
0
class ContactForm(FlaskForm):
    firstName = StringField(
        "<strong>First Name</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=45),
                    Alpha()])
    lastName = StringField(
        "<strong>Last Name</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=45),
                    Alpha()])
    email = StringField(
        "<strong>Email</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=100),
                    Email()])
    subject = StringField("<strong>Subject</strong>",
                          validators=[
                              InputRequired(),
                              Length(min=4, max=100),
                              Regexp(
                                  textRegex,
                                  message="Input contains illegal characters.")
                          ])
    message = TextAreaField(
        "<strong>Message</strong>",
        validators=[
            InputRequired(),
            Length(min=4, max=1000),
            Regexp(textRegex, message="Input contains illegal characters.")
        ],
        render_kw={
            "rows": 6,
            "cols": 1
        })
    submit = SubmitField("Contact Us")

    # Check if user with that email exists
    def validate_email(self, email):
        with app.app_context():
            cursor = mysql.connection.cursor()
            cursor.callproc("RecoverCredentials", [self.email.data])
            found = cursor.fetchone()
            cursor.close()
        if found is None:
            raise ValidationError('There is no account with that email.')
Beispiel #3
0
class YourTripForm(FlaskForm):
    firstName3 = StringField(
        "<strong>First Name</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=45),
                    Alpha()])
    lastName3 = StringField(
        "<strong>Last Name</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=45),
                    Alpha()])
    bookingNumber3 = StringField(
        "<strong>Booking Number</strong>",
        validators=[
            InputRequired(),
            Length(min=6, max=6, message="Field must be 6 characters long."),
            Alpha()
        ])
    submit3 = SubmitField("Search")
Beispiel #4
0
class LoginForm(FlaskForm):
  username = StringField(
    u"Login",
    validators = [
      DataRequired(message = u"Somente letras, tudojuntoeminusculo. \
        Não tem login ainda? Clique em 'Registrar' lá embaixo!"),
      Alpha(message = u"Somente letras, tudojuntoeminusculo"),
    ],
    description='jocimara',
    render_kw=({
      'oninvalid': 'this.setCustomValidity("Somente letras, \
        tudojuntoeminusculo. Não tem login ainda? Clique em \'Registrar\' lá \
        embaixo!");',
      'oninput': 'this.setCustomValidity("");',
    }),
  )
  password = PasswordField(
    u"Senha",
    validators = [
      DataRequired(message = u"Qual é a senha?"),
    ],
    description='********',
    render_kw=({
      'oninvalid': 'this.setCustomValidity("Qual é a senha?");',
      'oninput': 'this.setCustomValidity("");',
    }),
  )
  mr_robot = BooleanField(
    u"Eu não sou um robô",
    validators=[DataRequired(message=(u"Não autenticamos robôs por este \
      formulário, favor marcar esta opção."),),],
    render_kw=({
      'oninvalid': 'this.setCustomValidity("Não autenticamos robôs por este \
        formulário, favor marcar esta opção.");',
      'oninput': 'this.setCustomValidity("");',
    }),
  )
  remember_me = BooleanField(u"Lembrar de mim")
  submit = SubmitField(u"Entrar")
Beispiel #5
0
class SignupForm(FlaskForm):
  username = StringField(
    u"Login",
    validators = [
      DataRequired(message = u"Login é necessário e tu precisa decorar, assim \
        como a senha."),
      Alpha(message = u"Somente letras, tudojuntoeminusculo"),
    ],
    description='jocimara',
    render_kw=({
      'oninvalid': 'this.setCustomValidity("Somente letras, \
        tudojuntoeminusculo. Não tem login ainda? Clique em \'Registrar\' lá \
        embaixo!");',
      'oninput': 'this.setCustomValidity("");',
    }),
  )
  password = PasswordField(
    u"Senha",
    validators = [
      DataRequired(message = u"Senha é necessária e tu precisa decorar."),
      Length(
        min=3,
        message = u"A senha precisa ter pelo menos 3 (três) caracteres.",
      ),
      EqualTo('confirm', message=u"As duas senhas na verdade são a mesma!",),
    ],
    description='********',
    render_kw=({
      'oninvalid': 'this.setCustomValidity("Qual é a senha?");',
      'oninput': 'this.setCustomValidity("");',
    }),
  )
  confirm = PasswordField(
    u"Senha de novo",
    validators = [
      DataRequired(message = u"É a mesma senha de novo!"),
      Length(
        min=3,
        message = u"A senha tinha que ter pelo menos 3 (três) caracteres.",
      ),
    ],
    description='********',
    render_kw=({
      'oninvalid': 'this.setCustomValidity("Qual é a senha de novo?");',
      'oninput': 'this.setCustomValidity("");',
    }),
  )
  nome = StringField(
    u"Nome",
    validators=[DataRequired(message = u"Qual é o teu nome?")],
    description=u"Jocimara da Silva dos Santos",
    render_kw=({
      'oninvalid': 'this.setCustomValidity("Qual é o teu nome?");',
      'oninput': 'this.setCustomValidity("");',
    }),
  )
  ## TODO A Marta disse que vai contra nova cartilha de etiqueta de comunicação
#  pronomes = [
#    ('a', u"Bem vind<b>a</b>"),
#    ('o', u"Bem vind<b>o</b>"),
#    ('e', u"Bem vind<b>e</b>"),
#    ('s', u"Bem vind<b>s</b>"),
#    ('x', u"Bem vind<b>x</b>"),
#    ('@', u"Bem vind<b>@</b>"),
#    ('is', u"Bem vind<b>is</b>, cacilds"),
#  ]
#  pronome = RadioField(u"Como eu te cumprimento?", choices=pronomes)
  pronome = HiddenField()
  mr_robot = BooleanField(
    u"Eu não sou um robô",
    validators=[DataRequired(message=(u"Não autenticamos robôs por este \
      formulário, favor marcar esta opção."),),],
    render_kw=({
      'oninvalid': 'this.setCustomValidity("Não autenticamos robôs por este \
        formulário, favor marcar esta opção.");',
      'oninput': 'this.setCustomValidity("");',
    }),
  )
  submit = SubmitField(u"Registrar")
Beispiel #6
0
def test_alpha_raises(test_v, dummy_form, dummy_field):
    validator = Alpha()
    dummy_field.data = test_v
    with pytest.raises(ValidationError):
        validator(dummy_form, dummy_field)
Beispiel #7
0
def test_alpha(test_v, dummy_form, dummy_field):
    validator = Alpha()
    dummy_field.data = test_v
    validator(dummy_form, dummy_field)
Beispiel #8
0
class RegisterForm(FlaskForm):
    title = SelectField("<strong>Title</strong>", choices=titles)
    firstName = StringField(
        "<strong>First Name *</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=45),
                    Alpha()])
    middleName = StringField(
        "<strong>Middle Name</strong>",
        validators=[Optional(), Length(min=4, max=45),
                    Alpha()])
    lastName = StringField(
        "<strong>Last Name *</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=45),
                    Alpha()])
    preferredName = StringField(
        "<strong>Preferred Name</strong>",
        validators=[Optional(), Length(min=1, max=45),
                    Alpha()])
    sex = SelectField("<strong>Sex *</strong>", choices=sexes)
    dateOfBirth = DateField("<strong>Date of Birth *</strong>",
                            format="%Y-%m-%d",
                            validators=[InputRequired()],
                            render_kw={
                                "min": "1990-01-01",
                                "max": datetime.date.today()
                            })
    street = StringField(
        "<strong>Street *</strong>",
        validators=[
            InputRequired(),
            Length(min=4, max=100),
            Regexp(
                streetRegex,
                message=
                "Must only contain alpha characters, numbers, spaces and periods."
            )
        ])
    city = StringField(
        "<strong>City *</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=45),
                    AlphaSpace()])
    zipCode = StringField(
        "<strong>Zip Code *</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=10),
                    Integer()])
    state = StringField(
        "<strong>State</strong>",
        validators=[Optional(),
                    Length(min=2, max=45),
                    AlphaSpace()])
    country = StringField(
        "<strong>Country *</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=45),
                    AlphaSpace()])
    phone = StringField(
        "<strong>Phone *</strong>",
        validators=[
            InputRequired(),
            Length(min=4, max=200),
            Regexp(streetRegex,
                   message=
                   "Must only contain numbers, and some special characters.")
        ])
    email = StringField(
        "<strong>Email *</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=100),
                    Email()])
    username = StringField(
        "<strong>Username *</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=45),
                    AlphaNumeric()])
    password = PasswordField("<strong>Password *</strong>",
                             validators=[
                                 InputRequired(),
                                 Length(min=4, max=64),
                                 AlphaNumeric(),
                                 EqualTo("repeatPassword",
                                         "Passwords must match.")
                             ])
    repeatPassword = PasswordField(
        "<strong>Repeat Password *</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=64),
                    AlphaNumeric()])
    securityQuestion = SelectField("<strong>Security Question *</strong>",
                                   choices=securityQuestions)
    securityAnswer = StringField(
        "<strong>Answer *</strong>",
        validators=[InputRequired(),
                    Length(min=4, max=45),
                    AlphaNumeric()])
    submit = SubmitField("Register")

    # Check if email already exist in database
    def validate_email(self, email):
        with app.app_context():
            cursor = mysql.connection.cursor()
            cursor.execute("SELECT * FROM users WHERE Email = \'%s\'" %
                           self.email.data)
            alreadyExists = cursor.fetchone()
            cursor.close()
        if alreadyExists:
            raise ValidationError(
                "This email is taken. Please choose a different one.")

    # Check if username already exist in database
    def validate_username(self, username):
        with app.app_context():
            cursor = mysql.connection.cursor()
            cursor.execute("SELECT * FROM users WHERE Username = \'%s\'" %
                           self.username.data)
            alreadyExists = cursor.fetchone()
            cursor.close()
        if alreadyExists:
            raise ValidationError(
                "This username is taken. Please choose a different one.")