コード例 #1
0
ファイル: tests.py プロジェクト: superawesome/mozillians
    def test_validate_username(self):
        """Test validate_username helper."""
        valid_usernames = ["giorgos", "aakash", "nikos", "bat-man"]

        invalid_usernames = ["administrator", "test", "no-reply", "noreply", "spam"]

        for name in valid_usernames:
            self.assertTrue(validate_username(name), "Username: %s did not pass test" % name)

        for name in invalid_usernames:
            self.assertFalse(validate_username(name), "Username: %s did not pass test" % name)
コード例 #2
0
ファイル: tests.py プロジェクト: bensternthal/mozillians
    def test_validate_username(self):
        """Test validate_username helper."""
        valid_usernames = ['giorgos', 'aakash', 'nikos', 'bat-man']

        invalid_usernames = [
            'administrator', 'test', 'no-reply', 'noreply', 'spam'
        ]

        for name in valid_usernames:
            self.assertTrue(validate_username(name),
                            'Username: %s did not pass test' % name)

        for name in invalid_usernames:
            self.assertFalse(validate_username(name),
                             'Username: %s did not pass test' % name)
コード例 #3
0
    def clean_username(self):
        username = self.cleaned_data['username']
        if not username:
            return self.instance.user.username

        # Don't be jacking somebody's username
        # This causes a potential race condition however the worst that can
        # happen is bad UI.
        if (User.objects.filter(username=username).exclude(
                pk=self.instance.user.id).exists()):
            raise forms.ValidationError(
                _('This username is in use. Please try'
                  ' another.'))

        # No funky characters in username.
        if not re.match(r'^[\w.@+-]+$', username):
            raise forms.ValidationError(
                _('Please use only alphanumeric'
                  ' characters'))

        if not validate_username(username):
            raise forms.ValidationError(
                _('This username is not allowed, '
                  'please choose another.'))
        return username
コード例 #4
0
ファイル: forms.py プロジェクト: bensternthal/mozillians
    def clean_username(self):
        username = self.cleaned_data['username']
        if not username:
            return self.instance.user.username

        # Don't be jacking somebody's username
        # This causes a potential race condition however the worst that can
        # happen is bad UI.
        if (User.objects.filter(username=username).
            exclude(pk=self.instance.user.id).exists()):
            raise forms.ValidationError(_('This username is in use. Please try'
                                          ' another.'))

        # No funky characters in username.
        if not re.match(r'^[\w.@+-]+$', username):
            raise forms.ValidationError(_('Please use only alphanumeric'
                                          ' characters'))

        if not validate_username(username):
            raise forms.ValidationError(_('This username is not allowed, '
                                          'please choose another.'))
        return username