def test_successful_change(self):
        """change user password"""
        User = get_user_model()
        test_user = User.objects.create_user('Bob', '*****@*****.**', 'Pass.123')
        old_password = test_user.password

        password_token = make_password_reset_token(test_user)

        response = self.client.get(
            reverse('misago:reset_password_form',
                    kwargs={'user_id': test_user.pk, 'token': password_token}))
        self.assertEqual(response.status_code, 200)
        self.assertIn('Set new password for Bob', response.content)

        test_user = User.objects.get(pk=test_user.pk)
        self.assertEqual(test_user.password, old_password)

        response = self.client.post(
            reverse('misago:reset_password_form',
                    kwargs={'user_id': test_user.pk, 'token': password_token}),
            data={'new_password': '******'})
        self.assertEqual(response.status_code, 302)

        test_user = User.objects.get(pk=test_user.pk)
        self.assertNotEqual(test_user.password, old_password)
    def test_successful_change(self):
        """change user password"""
        User = get_user_model()
        test_user = User.objects.create_user('Bob', '*****@*****.**', 'Pass.123')
        old_password = test_user.password

        password_token = make_password_reset_token(test_user)

        response = self.client.get(
            reverse('misago:reset_password_form',
                    kwargs={
                        'user_id': test_user.pk,
                        'token': password_token
                    }))
        self.assertEqual(response.status_code, 200)
        self.assertIn('Set new password for Bob', response.content)

        test_user = User.objects.get(pk=test_user.pk)
        self.assertEqual(test_user.password, old_password)

        response = self.client.post(reverse('misago:reset_password_form',
                                            kwargs={
                                                'user_id': test_user.pk,
                                                'token': password_token
                                            }),
                                    data={'new_password': '******'})
        self.assertEqual(response.status_code, 302)

        test_user = User.objects.get(pk=test_user.pk)
        self.assertNotEqual(test_user.password, old_password)
Exemple #3
0
def request_reset(request):
    form = ResetPasswordForm()

    if request.method == "POST":
        form = ResetPasswordForm(request.POST)
        if form.is_valid():
            requesting_user = form.user_cache
            request.session["reset_password_link_sent_to"] = requesting_user.pk

            mail_subject = _("Change %(user)s password " "on %(forum_title)s forums")
            subject_formats = {"user": requesting_user.username, "forum_title": settings.forum_name}
            mail_subject = mail_subject % subject_formats

            confirmation_token = make_password_reset_token(requesting_user)

            mail_user(
                request,
                requesting_user,
                mail_subject,
                "misago/emails/change_password_form_link",
                {"confirmation_token": confirmation_token},
            )

            return redirect("misago:reset_password_link_sent")

    return render(request, "misago/forgottenpassword/request.html", {"form": form})
Exemple #4
0
def request_reset(request):
    form = ResetPasswordForm()

    if request.method == 'POST':
        form = ResetPasswordForm(request.POST)
        if form.is_valid():
            requesting_user = form.user_cache
            request.session['reset_password_link_sent_to'] = requesting_user.pk

            mail_subject = _("Change %(user)s password "
                             "on %(forum_title)s forums")
            subject_formats = {
                'user': requesting_user.username,
                'forum_title': settings.forum_name
            }
            mail_subject = mail_subject % subject_formats

            confirmation_token = make_password_reset_token(requesting_user)

            mail_user(request, requesting_user, mail_subject,
                      'misago/emails/change_password_form_link',
                      {'confirmation_token': confirmation_token})

            return redirect('misago:reset_password_link_sent')

    return render(request, 'misago/forgottenpassword/request.html',
                  {'form': form})
    def test_change_password_on_inactive(self):
        """change inactive user password errors"""
        User = get_user_model()
        test_user = User.objects.create_user('Bob', '*****@*****.**', 'Pass.123',
                                             requires_activation=1)
        old_password = test_user.password

        password_token = make_password_reset_token(test_user)

        response = self.client.get(
            reverse('misago:reset_password_form',
                    kwargs={'user_id': test_user.pk, 'token': password_token}))
        self.assertEqual(response.status_code, 302)

        test_user = User.objects.get(pk=test_user.pk)
        self.assertEqual(test_user.password, old_password)

        self.assertTrue(not mail.outbox)
    def test_change_password_on_banned(self):
        """change banned user password errors"""
        User = get_user_model()
        test_user = User.objects.create_user('Bob', '*****@*****.**', 'Pass.123')
        old_password = test_user.password

        Ban.objects.create(test=BAN_USERNAME, banned_value='bob',
                           user_message='Nope!')

        password_token = make_password_reset_token(test_user)

        response = self.client.get(
            reverse('misago:reset_password_form',
                    kwargs={'user_id': test_user.pk, 'token': password_token}))
        self.assertEqual(response.status_code, 302)

        test_user = User.objects.get(pk=test_user.pk)
        self.assertEqual(test_user.password, old_password)

        self.assertTrue(not mail.outbox)
    def test_change_password_on_inactive(self):
        """change inactive user password errors"""
        User = get_user_model()
        test_user = User.objects.create_user('Bob',
                                             '*****@*****.**',
                                             'Pass.123',
                                             requires_activation=1)
        old_password = test_user.password

        password_token = make_password_reset_token(test_user)

        response = self.client.get(
            reverse('misago:reset_password_form',
                    kwargs={
                        'user_id': test_user.pk,
                        'token': password_token
                    }))
        self.assertEqual(response.status_code, 302)

        test_user = User.objects.get(pk=test_user.pk)
        self.assertEqual(test_user.password, old_password)

        self.assertTrue(not mail.outbox)
    def test_change_password_on_banned(self):
        """change banned user password errors"""
        User = get_user_model()
        test_user = User.objects.create_user('Bob', '*****@*****.**', 'Pass.123')
        old_password = test_user.password

        Ban.objects.create(test=BAN_USERNAME,
                           banned_value='bob',
                           user_message='Nope!')

        password_token = make_password_reset_token(test_user)

        response = self.client.get(
            reverse('misago:reset_password_form',
                    kwargs={
                        'user_id': test_user.pk,
                        'token': password_token
                    }))
        self.assertEqual(response.status_code, 302)

        test_user = User.objects.get(pk=test_user.pk)
        self.assertEqual(test_user.password, old_password)

        self.assertTrue(not mail.outbox)