Exemple #1
0
    def test_with_field_name_and_password_matches(self):
        """Testing validate_old_password with explicit field_name and
        password matching User's current password
        """
        form = self.DummyForm({
            'alt_password': '******',
        })
        validate_old_password(form, self.user, field_name='alt_password')

        self.assertNotIn('alt_password', form.errors)
Exemple #2
0
    def test_with_password_matches(self):
        """Testing validate_old_password with password matching User's
        current password
        """
        form = self.DummyForm({
            'password': '******',
        })
        validate_old_password(form, self.user)

        self.assertNotIn('password', form.errors)
Exemple #3
0
    def test_with_field_name_and_password_does_not_match(self):
        """Testing validate_old_password with explicit field name and password
        not matching User's current password
        """
        form = self.DummyForm({
            'alt_password': '******',
        })
        validate_old_password(form, self.user, field_name='alt_password')

        self.assertIn('alt_password', form.errors)
        self.assertEqual(form.errors['alt_password'], ['Incorrect password.'])
Exemple #4
0
    def test_with_existing_errors(self):
        """Testing validate_old_password with field already containing errors
        """
        form = self.DummyForm({
            'password': '******',
        })
        form.errors['password'] = form.error_class(['Something went wrong.'])
        validate_old_password(form, self.user)

        self.assertIn('password', form.errors)
        self.assertEqual(form.errors['password'], ['Something went wrong.'])
Exemple #5
0
    def test_with_password_does_not_match(self):
        """Testing validate_old_password with password not matching User's
        current password
        """
        form = self.DummyForm({
            'password': '******',
        })
        validate_old_password(form, self.user)

        self.assertIn('password', form.errors)
        self.assertEqual(form.errors['password'], ['Incorrect password.'])
def do_change_password(request):
    form = ChangePasswordForm(request.POST)
    form.full_clean()
    validate_old_password(form, request.user, 'old_password')
    if not form.errors:
        # XXX Compatibility with Django 0.96 and 1.0
        formdata = getattr(form, "cleaned_data",
                           getattr(form, "clean_data", None))

        request.user.set_password(formdata['new_password1'])
        request.user.save()
        request.user.message_set.create(message="Your password was changed successfully.")
    return form
Exemple #7
0
    def test_with_field_name_and_existing_errors(self):
        """Testing validate_old_password with explicit field name and field
        already containing errors
        """
        form = self.DummyForm({
            'alt_password': '******',
        })
        form.errors['alt_password'] = form.error_class(
            ['Something went wrong.'])
        validate_old_password(form, self.user, field_name='alt_password')

        self.assertIn('alt_password', form.errors)
        self.assertEqual(form.errors['alt_password'],
                         ['Something went wrong.'])
Exemple #8
0
def do_change_password(request):
    form = ChangePasswordForm(request.POST)
    form.full_clean()
    validate_old_password(form, request.user, 'old_password')
    if not form.errors:
        # XXX Compatibility with Django 0.96 and 1.0
        formdata = getattr(form, "cleaned_data",
                           getattr(form, "clean_data", None))

        request.user.set_password(formdata['new_password1'])
        request.user.save()
        request.user.message_set.create(
            message="Your password was changed successfully.")
    return form