Esempio n. 1
0
class TestYourAppOtpForm(Form):
    """
    Simple form for OTP validation
    """

    otp_to_be_tested = CharField(max_length=6, min_length=6, required=True,
                                 label=_('One Time Password from your app to test'),
                                 validators=[OtpValidator()], widget=NumberInput())
    otp_to_be_tested.widget.attrs.update({  # pylint: disable=no-member
        'pattern': '[0-9]{6,6}', 'class': 'form-control',
    })
Esempio n. 2
0
 def test_good_ones(self):
     """
     Test good OTPs
     """
     test_items = (
         '000000', '111111', '222222', '333333', '444444', '555555', '666666', '777777', '888888', '999999',
         '123456', '654321', '012345', '543210',
     )
     for test_item in test_items:
         with self.subTest(msg='Testing good "{}"'.format(test_item)):
             result = OtpValidator()(test_item)
             self.assertIsNone(result)
class RequestOtpForm(Form):
    """
    Know a OTP?
    """

    otp = CharField(max_length=6,
                    min_length=6,
                    required=True,
                    validators=[OtpValidator()],
                    widget=NumberInput(),
                    label=_('One Time Password'))
    otp.widget.attrs.update({  # pylint: disable=no-member
        'pattern': '[0-9]{6,6}',
        'class': 'form-control',
    })
Esempio n. 4
0
class NewOtpSecretForm(Form):
    """
    Querying for a new OTP
    """

    otp_confirm = CharField(max_length=6,
                            min_length=6,
                            required=True,
                            label=_('One Time Password for Confirmation'),
                            validators=[OtpValidator()],
                            widget=NumberInput())
    otp_confirm.widget.attrs.update({  # pylint: disable=no-member
        'pattern': '[0-9]{6,6}',
        'class': 'form-control',
    })
Esempio n. 5
0
 def test_bad_ones(self):
     """
     Test bad OTPs
     """
     test_items = (
         None, '', '1', '22', '333', '4444', '55555', '7777777', '88888888', '999999999',
         'abcdef', '12ab56', 'AB12CD', '-12345', '-123456',
     )
     for test_item in test_items:
         with self.subTest('Testing bad "{}"'.format(test_item)):
             self.assertRaisesMessage(
                 ValidationError,
                 'Only numbers allowed.',
                 OtpValidator(),
                 test_item
             )
Esempio n. 6
0
class UsernamePasswordOtpForm(Form):
    """
    Standard Username / Password Form
    """
    username = CharField(max_length=150,
                         min_length=3,
                         required=True,
                         label=_('Username'),
                         validators=[
                             ASCIIUsernameValidator(),
                         ])
    username.widget.attrs.update({  # pylint: disable=no-member
        'aria-describedby': 'usernameHelp',
        'pattern': r'[\w.@+-]{3,150}',
        'class': 'form-control',
    })

    password = CharField(
        widget=PasswordInput(),
        required=True,
        max_length=1024,
        min_length=8,
        label=_('Password'),
    )
    password.widget.attrs.update(
        {  # pylint: disable=no-member
            'class': 'form-control',
        })

    otp = CharField(
        max_length=6,
        min_length=6,
        required=True,
        label=_('One Time Password'),
        validators=[
            OtpValidator(),
        ],
        widget=NumberInput(),
    )
    otp.widget.attrs.update({  # pylint: disable=no-member
        'aria-describedby': 'otpHelp',
        'pattern': '[0-9]{6,6}',
        'class': 'form-control',
    })
Esempio n. 7
0
class RegistrationStep2Form(RegistrationStep2UrlForm):
    """
    Get password and otp from user
    """

    password1 = CharField(widget=PasswordInput(),
                          required=True,
                          max_length=1024,
                          min_length=8,
                          label=_('Password'),
                          validators=[validate_password])
    password1.widget.attrs.update(
        {  # pylint: disable=no-member
            'class': 'form-control',
        })

    password2 = CharField(widget=PasswordInput(),
                          required=True,
                          max_length=1024,
                          min_length=8,
                          label=_('Repeat Password'))
    password2.widget.attrs.update(
        {  # pylint: disable=no-member
            'class': 'form-control',
        })

    otp = CharField(max_length=6,
                    min_length=6,
                    required=True,
                    label=_('One Time Password from your app'),
                    validators=[OtpValidator()],
                    widget=NumberInput())
    otp.widget.attrs.update({  # pylint: disable=no-member
        'pattern': '[0-9]{6,6}',
        'class': 'form-control',
    })