Beispiel #1
0
    def __init__(self, request):
        self.request = request

        if request.feature('activity_pages'):
            email_schema = schemas.EmailChangeSchema().bind(request=request)
        else:
            email_schema = schemas.LegacyEmailChangeSchema().bind(
                request=request)

        password_schema = schemas.PasswordChangeSchema().bind(request=request)

        # Ensure deform generates unique field IDs for each field in this
        # multiple-form page.
        counter = itertools.count()

        self.forms = {
            'email':
            request.create_form(email_schema,
                                buttons=(_('Change email address'), ),
                                formid='email',
                                counter=counter),
            'password':
            request.create_form(password_schema,
                                buttons=(_('Change password'), ),
                                formid='password',
                                counter=counter),
        }
Beispiel #2
0
    def __init__(self, request):
        self.request = request

        email_schema = schemas.EmailChangeSchema().bind(request=request)
        password_schema = schemas.PasswordChangeSchema().bind(request=request)

        # Ensure deform generates unique field IDs for each field in this
        # multiple-form page.
        counter = itertools.count()

        self.forms = {
            "email":
            request.create_form(
                email_schema,
                buttons=(_("Save"), ),
                formid="email",
                counter=counter,
                use_inline_editing=True,
            ),
            "password":
            request.create_form(
                password_schema,
                buttons=(_("Save"), ),
                formid="password",
                counter=counter,
                use_inline_editing=True,
            ),
        }
Beispiel #3
0
    def test_it_is_invalid_if_passwords_dont_match(self, pyramid_csrf_request):
        user = Mock()
        pyramid_csrf_request.user = user
        schema = schemas.PasswordChangeSchema().bind(
            request=pyramid_csrf_request)

        with pytest.raises(colander.Invalid) as exc:
            schema.deserialize({'new_password': '******',
                                'new_password_confirm': 'wibble!',
                                'password': '******'})

        assert 'new_password_confirm' in exc.value.asdict()
Beispiel #4
0
def test_PasswordChangeSchema_rejects_non_matching_passwords(config,
                                                             user_model):
    user = Mock()
    request = csrf_request(config, authenticated_user=user)
    schema = schemas.PasswordChangeSchema().bind(request=request)

    with pytest.raises(colander.Invalid) as exc:
        schema.deserialize({'new_password': '******',
                            'new_password_confirm': 'wibble!',
                            'password': '******'})

    assert 'new_password_confirm' in exc.value.asdict()
Beispiel #5
0
    def test_it_is_invalid_if_passwords_dont_match(self, pyramid_csrf_request):
        user = Mock()
        pyramid_csrf_request.user = user
        schema = schemas.PasswordChangeSchema().bind(
            request=pyramid_csrf_request)

        with pytest.raises(colander.Invalid) as exc:
            schema.deserialize({
                "new_password": "******",
                "new_password_confirm": "wibble!",
                "password": "******",
            })

        assert "new_password_confirm" in exc.value.asdict()
Beispiel #6
0
    def __init__(self, request):
        self.request = request

        email_schema = schemas.EmailChangeSchema().bind(request=request)
        password_schema = schemas.PasswordChangeSchema().bind(request=request)

        self.forms = {
            'email': deform.Form(email_schema,
                                 buttons=(_('Change email address'),),
                                 formid='email'),
            'password': deform.Form(password_schema,
                                    buttons=(_('Change password'),),
                                    formid='password'),
        }
Beispiel #7
0
def test_PasswordChangeSchema_rejects_wrong_password(config, user_model):
    user = Mock()
    request = csrf_request(config, authenticated_user=user)
    schema = schemas.PasswordChangeSchema().bind(request=request)
    # The password does not check out
    user_model.validate_user.return_value = False

    with pytest.raises(colander.Invalid) as exc:
        schema.deserialize({'new_password': '******',
                            'new_password_confirm': 'wibble!',
                            'password': '******'})

    user_model.validate_user.assert_called_once_with(user, 'flibble')
    assert 'password' in exc.value.asdict()
Beispiel #8
0
    def test_it_is_invalid_if_current_password_is_wrong(self,
                                                        pyramid_csrf_request,
                                                        user_password_service):
        user = Mock()
        pyramid_csrf_request.user = user
        schema = schemas.PasswordChangeSchema().bind(
            request=pyramid_csrf_request)
        user_password_service.check_password.return_value = False

        with pytest.raises(colander.Invalid) as exc:
            schema.deserialize({'new_password': '******',
                                'new_password_confirm': 'wibble',
                                'password': '******'})

        user_password_service.check_password.assert_called_once_with(user, 'flibble')
        assert 'password' in exc.value.asdict()
Beispiel #9
0
    def __init__(self, request):
        self.request = request

        if request.feature('activity_pages'):
            email_schema = schemas.EmailChangeSchema().bind(request=request)
        else:
            email_schema = schemas.LegacyEmailChangeSchema().bind(request=request)

        password_schema = schemas.PasswordChangeSchema().bind(request=request)

        self.forms = {
            'email': request.create_form(email_schema,
                                         buttons=(_('Change email address'),),
                                         formid='email'),
            'password': request.create_form(password_schema,
                                            buttons=(_('Change password'),),
                                            formid='password'),
        }