class ChangePasswordFrom(FlaskForm):
    password = PasswordField(
        _('type your password'),
        validators=[DataRequired(_('Your current password is required'))])

    new_password = PasswordField(
        _('Create a new password'),
        validators=[
            DataRequired(_('Your new password is required')),
            EqualTo('new_password_confirm',
                    message=app.config['PASSWORD_MATCH_ERROR_TEXT']),
            Length(min=app.config['PASSWORD_MIN_LENGTH'],
                   max=app.config['PASSWORD_MAX_LENGTH'],
                   message=app.config['PASSWORD_CRITERIA_ERROR_TEXT'])
        ])
    new_password_confirm = PasswordField(_('Re-type your new password'))

    @staticmethod
    def validate_new_password(form, field):
        new_password = field.data
        if new_password.isalnum() or not any(
                char.isupper()
                for char in new_password) or not any(char.isdigit()
                                                     for char in new_password):
            raise ValidationError(app.config['PASSWORD_CRITERIA_ERROR_TEXT'])
class ContactDetailsChangeForm(FlaskForm):
    first_name = StringField(
        _('First name'),
        validators=[
            DataRequired(_('First name is required')),
            Length(max=254,
                   message=_('Your first name must be less than 254 '
                             'characters'))
        ])
    last_name = StringField(
        _('Last name'),
        validators=[
            DataRequired(_('Last name is required')),
            Length(
                max=254,
                message=_('Your last name must be less than 254 characters'))
        ])
    phone_number = StringField(
        _('Telephone number'),
        validators=[
            DataRequired(_('Phone number is required')),
            Length(min=9,
                   max=15,
                   message=_(
                       'This should be a valid phone number between 9 and 15 '
                       'digits'))
        ],
        default=None)
    # TODO: Remove comments and delete the field without validation once email change functionality is enabled.
    # This was commented out rather then feature flagged as it's difficult to feature flag a model.
    email_address = StringField(_('Email address'))
Ejemplo n.º 3
0
class ContactDetailsChangeForm(FlaskForm):
    first_name = StringField(_('First name'), validators=[DataRequired(_('First name is required')),
                                                          Length(max=254,
                                                                 message=_('Your first name must be less than 254 '
                                                                           'characters'))])
    last_name = StringField(_('Last name'),
                            validators=[DataRequired(_('Last name is required')),
                                        Length(max=254, message=_('Your last name must be less than 254 characters'))])
    phone_number = StringField(_('Telephone number'),
                               validators=[DataRequired(_('Phone number is required')),
                                           Length(min=9,
                                                  max=15,
                                                  message=_('This should be a valid phone number between 9 and 15 '
                                                            'digits'))],
                               default=None)
Ejemplo n.º 4
0
class ContactDetailsChangeForm(FlaskForm):
    first_name = StringField(
        _("First name"),
        validators=[
            DataRequired(_("First name is required")),
            Length(max=254,
                   message=_("Your first name must be less than 254 "
                             "characters")),
        ],
    )
    last_name = StringField(
        _("Last name"),
        validators=[
            DataRequired(_("Last name is required")),
            Length(
                max=254,
                message=_("Your last name must be less than 254 characters")),
        ],
    )
    phone_number = StringField(
        _("Telephone number"),
        validators=[
            DataRequired(_("Phone number is required")),
            Length(min=9,
                   max=15,
                   message=_(
                       "This should be a valid phone number between 9 and 15 "
                       "digits")),
        ],
        default=None,
    )
    email_address = StringField(
        _("Email address"),
        validators=[
            DataRequired(_("Email address is required")),
            Email(message=_("Invalid email address")),
            Length(
                max=254,
                message=_("Your email must have fewer than 254 characters")),
        ],
    )
class SecureMessagingForm(FlaskForm):
    send = SubmitField(label=_('Send'), id='send-message-btn')
    subject = StringField(_('Subject'))
    body = TextAreaField(_('Message'),
                         validators=[
                             DataRequired(_('Message is required')),
                             Length(max=50000,
                                    message=_(
                                        'Message must be less than 50000 '
                                        'characters'))
                         ])
    msg_id = HiddenField('Message id')
    thread_id = HiddenField('Thread id')
    hidden_subject = HiddenField('Hidden Subject')
Ejemplo n.º 6
0
class ResetPasswordForm(FlaskForm):
    password = PasswordField(_('New password'),
                             validators=[DataRequired(_('Password is required')),
                                         EqualTo('password_confirm', message=app.config['PASSWORD_MATCH_ERROR_TEXT']),
                                         Length(min=app.config['PASSWORD_MIN_LENGTH'],
                                                max=app.config['PASSWORD_MAX_LENGTH'],
                                                message=app.config['PASSWORD_CRITERIA_ERROR_TEXT'])])
    password_confirm = PasswordField(_('Re-type new password'))

    @staticmethod
    def validate_password(form, field):
        password = field.data
        if password.isalnum() or not any(char.isupper() for char in password) or not any(char.isdigit() for char in
                                                                                         password):
            raise ValidationError(app.config['PASSWORD_CRITERIA_ERROR_TEXT'])
Ejemplo n.º 7
0
class SecureMessagingForm(FlaskForm):
    send = SubmitField(label=_("Send"), id="send-message-btn")
    subject = StringField(_("Subject"))
    body = TextAreaField(
        _("Message"),
        validators=[
            DataRequired(_("Message is required")),
            Length(max=50000,
                   message=_("Message must be less than 50000 "
                             "characters")),
        ],
    )
    msg_id = HiddenField("Message id")
    thread_id = HiddenField("Thread id")
    hidden_subject = HiddenField("Hidden Subject")
class RegistrationForm(FlaskForm):
    first_name = StringField(
        _('First name'),
        validators=[
            InputRequired(_('First name is required')),
            Length(max=254,
                   message=_('Your first name must be less than 254 '
                             'characters'))
        ])
    last_name = StringField(
        _('Last name'),
        validators=[
            InputRequired(_('Last name is required')),
            Length(
                max=254,
                message=_('Your last name must be less than 254 characters'))
        ])
    email_address = StringField(
        _('Enter your email address'),
        validators=[
            InputRequired(_('Email address is required')),
            Email(message=_('Invalid email address')),
            Length(max=254,
                   message=_('Your email must be less than 254 characters')),
            EqualTo('email_address_confirm',
                    message=app.config['EMAIL_MATCH_ERROR_TEXT'])
        ])

    email_address_confirm = StringField(_('Re-type your email address'))

    password = PasswordField(
        _('Create a password'),
        validators=[
            DataRequired(_('Password is required')),
            EqualTo('password_confirm',
                    message=app.config['PASSWORD_MATCH_ERROR_TEXT']),
            Length(min=app.config['PASSWORD_MIN_LENGTH'],
                   max=app.config['PASSWORD_MAX_LENGTH'],
                   message=app.config['PASSWORD_CRITERIA_ERROR_TEXT'])
        ])
    password_confirm = PasswordField(_('Re-type your password'))
    phone_number = StringField(
        _('Telephone number'),
        validators=[
            DataRequired(_('Phone number is required')),
            Length(min=9,
                   max=15,
                   message=_(
                       'This should be a valid phone number between 9 and 15 '
                       'digits'))
        ],
        default=None)
    enrolment_code = HiddenField('Enrolment Code')

    @staticmethod
    def validate_phone_number(form, field):
        try:
            logger.info('Checking this is a valid phone number')
            input_number = phonenumbers.parse(
                field.data, 'GB'
            )  # Default region GB (44), unless country code added by user

            if not phonenumbers.is_possible_number(input_number):
                raise ValidationError(
                    _('This should be a valid telephone number between 9 and 15 digits'
                      ))

            if not phonenumbers.is_valid_number(input_number):
                raise ValidationError(
                    _('Please use a valid telephone number e.g. 01632 496 0018.'
                      ))
        except NumberParseException:
            logger.info(
                'There is a number parse exception in the phonenumber field')
            raise ValidationError(
                _('This should be a valid telephone number e.g. 01632 496 0018. '
                  ))

    @staticmethod
    def validate_email_address(_, field):
        email = field.data
        return _validate_email_address(email)

    @staticmethod
    def validate_password(_, field):
        password = field.data
        if password.isalnum() or not any(char.isupper()
                                         for char in password) or not any(
                                             char.isdigit()
                                             for char in password):
            raise ValidationError(app.config['PASSWORD_CRITERIA_ERROR_TEXT'])
Ejemplo n.º 9
0
 def test_instantiated_field_should_have_no_required_attribute(self):
     inputReq = DataRequired()
     self.assertFalse("required" in inputReq.field_flags)
Ejemplo n.º 10
0
class PendingSurveyRegistrationForm(FlaskForm):
    first_name = StringField(
        _("First name"),
        validators=[
            InputRequired(_("First name is required")),
            Length(max=254,
                   message=_("Your first name must be less than 254 "
                             "characters")),
        ],
    )
    last_name = StringField(
        _("Last name"),
        validators=[
            InputRequired(_("Last name is required")),
            Length(
                max=254,
                message=_("Your last name must be less than 254 characters")),
        ],
    )
    email = HiddenField("Enter your email address")

    password = PasswordField(
        _("Create a password"),
        validators=[
            DataRequired(_("Password is required")),
            EqualTo("password_confirm",
                    message=app.config["PASSWORD_MATCH_ERROR_TEXT"]),
            Length(
                min=app.config["PASSWORD_MIN_LENGTH"],
                max=app.config["PASSWORD_MAX_LENGTH"],
                message=app.config["PASSWORD_CRITERIA_ERROR_TEXT"],
            ),
        ],
    )
    password_confirm = PasswordField(_("Re-type your password"))
    phone_number = StringField(
        _("Telephone number"),
        validators=[
            DataRequired(_("Phone number is required")),
            Length(min=9,
                   max=15,
                   message=_(
                       "This should be a valid phone number between 9 and 15 "
                       "digits")),
        ],
        default=None,
    )
    batch_no = HiddenField("Batch number")

    @staticmethod
    def validate_phone_number(form, field):
        try:
            logger.info("Checking this is a valid phone number")
            input_number = phonenumbers.parse(
                field.data, "GB"
            )  # Default region GB (44), unless country code added by user

            if not phonenumbers.is_possible_number(input_number):
                raise ValidationError(
                    _("This should be a valid telephone number between 9 and 15 digits"
                      ))

            if not phonenumbers.is_valid_number(input_number):
                raise ValidationError(
                    _("Please use a valid telephone number e.g. 01632 496 0018."
                      ))
        except NumberParseException:
            logger.info(
                "There is a number parse exception in the phonenumber field")
            raise ValidationError(
                _("This should be a valid telephone number e.g. 01632 496 0018. "
                  ))

    @staticmethod
    def validate_password(_, field):
        password = field.data
        if (password.isalnum() or not any(char.isupper() for char in password)
                or not any(char.isdigit() for char in password)):
            raise ValidationError(app.config["PASSWORD_CRITERIA_ERROR_TEXT"])