def select_account(self, request):
        ctx = self.get_context_data()

        # Check for blocked users
        if security.is_blocked(request):
            messages.error(request,
                           "You are currently blocked from using accounts")
            return http.HttpResponseRedirect(
                reverse('checkout:payment-deatils'))

        # If account form has been submitted, validate it and show the
        # allocation form if the account has non-zero balance
        form = forms.ValidAccountForm(self.request.user,
                                      self.request.POST)
        ctx['account_form'] = form
        if not form.is_valid():
            security.record_failed_request(self.request)
            return self.render_to_response(ctx)

        security.record_successful_request(self.request)
        ctx['allocation_form'] = forms.AllocationForm(
            form.account, self.request.basket,
            ctx['shipping_total_incl_tax'],
            ctx['order_total_incl_tax'],
            self.get_account_allocations())
        return self.render_to_response(ctx)
 def test_blocks_after_freeze_threshold(self):
     for __ in range(3):
         security.record_failed_request(self.request)
     self.assertTrue(security.is_blocked(self.request))
 def test_resets_after_success(self):
     for __ in range(2):
         security.record_failed_request(self.request)
     security.record_successful_request(self.request)
     security.record_failed_request(self.request)
     self.assertFalse(security.is_blocked(self.request))
 def form_invalid(self, form):
     security.record_failed_request(self.request)
     return super(AccountBalanceView, self).form_invalid(form)