Exemplo n.º 1
0
 def test_012_PasswordResetNoNewPassword(self):
     """Test Password Reset when no new password is passed"""
     f = forms.PasswordReset(data={
         'uuid': self.valid_prr.uuid,
         'confirmPassword': '******'
     })
     self.assertFalse(f.is_valid())
Exemplo n.º 2
0
    def post(self, request, reset_uuid):

        if request.POST.get('confirmation', '') == "True":
            return redirect('Home')

        form = forms.PasswordReset(request.POST)
        if form.is_valid():
            user, pwd = form.save()
            user = authenticate(username=user.username, password=pwd)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return render(request,
                                  "RegisteredUsers/pages/PasswordChange.html",
                                  context={'confirmation': True})
                else:
                    raise SuspiciousOperation(
                        'Attempt to reset password on inactive user !')
            else:
                raise SuspiciousOperation('Anonymous user attempting reset !')
        else:
            c = self.context.copy()
            c['form'] = form
            return render(request,
                          "RegisteredUsers/pages/PasswordChange.html",
                          context=c)
Exemplo n.º 3
0
 def test_013_PasswordResetPasswordNoMatch(self):
     """Test Password Reset when passwords don't match"""
     f = forms.PasswordReset(
         data={
             'uuid': self.valid_prr.uuid,
             'newPassword': '******',
             'confirmPassword': '******'
         })
     self.assertFalse(f.is_valid())
Exemplo n.º 4
0
 def test_014_PasswordResetPasswordOk(self):
     """Test Password Reset when passwords don't match"""
     f = forms.PasswordReset(
         data={
             'uuid': self.valid_prr.uuid,
             'newPassword': '******',
             'confirmPassword': '******'
         })
     self.assertTrue(f.is_valid())
     f.save()
     u = authenticate(username=self.chester.username, password='******')
     self.assertEqual(u, self.chester)
Exemplo n.º 5
0
    def get(self, request, reset_uuid):

        try:
            prr = models.PasswordResetRequest.objects.get(
                uuid=uuid.UUID(reset_uuid))
        except ObjectDoesNotExist:
            return render(request, "RegisteredUsers/pages/UnknownReset.html")

        if prr.expiry < dt.today():
            return render(request, "RegisteredUsers/pages/UnknownReset.html")

        form = forms.PasswordReset(initial={'uuid': reset_uuid})

        c = self.context.copy()
        c['form'] = form

        return render(request,
                      "RegisteredUsers/pages/PasswordChange.html",
                      context=c)
Exemplo n.º 6
0
 def test_010_PasswordResetNoPassword(self):
     """Test Password Reset when no password is passed"""
     f = forms.PasswordReset(data={'uuid': self.valid_prr.uuid})
     self.assertFalse(f.is_valid())