Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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['order_total_incl_tax'],
            self.get_account_allocations())
        return self.render_to_response(ctx)
Exemplo n.º 3
0
    def get_context_data(self, **kwargs):
        ctx = super(PaymentDetailsView, self).get_context_data(**kwargs)

        # Add variable to indicate if the user is blocked from paying with
        # accounts.
        ctx['is_blocked'] = security.is_blocked(self.request)

        form = forms.ValidAccountForm(self.request.user)
        ctx['account_form'] = form

        # Add accounts that are linked to this user
        if self.request.user.is_authenticated():
            ctx['user_accounts'] = gateway.user_accounts(self.request.user)

        # Add existing allocations to context
        allocations = self.get_account_allocations()
        ctx['account_allocations'] = allocations
        ctx['to_allocate'] = ctx['order_total_incl_tax'] - allocations.total

        return ctx
Exemplo n.º 4
0
    def get_context_data(self, **kwargs):
        ctx = super(PaymentDetailsView, self).get_context_data(**kwargs)

        # Add variable to indicate if the user is blocked from paying with
        # accounts.
        ctx['is_blocked'] = security.is_blocked(self.request)

        form = forms.ValidAccountForm(self.request.user)
        ctx['account_form'] = form

        # Add accounts that are linked to this user
        if self.request.user.is_authenticated():
            ctx['user_accounts'] = gateway.user_accounts(self.request.user)

        # Add existing allocations to context
        allocations = self.get_account_allocations()
        ctx['account_allocations'] = allocations
        ctx['to_allocate'] = ctx['order_total_incl_tax'] - allocations.total

        return ctx
Exemplo n.º 5
0
 def post(self, request, *args, **kwargs):
     # Check for blocked users before trying to validate form
     if security.is_blocked(request):
         return self.get(request, *args, **kwargs)
     return super(AccountBalanceView, self).post(request, *args, **kwargs)
Exemplo n.º 6
0
 def get_context_data(self, **kwargs):
     ctx = super(AccountBalanceView, self).get_context_data(**kwargs)
     ctx['is_blocked'] = security.is_blocked(self.request)
     return ctx
 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 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_does_not_block_by_default(self):
     self.assertFalse(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 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_does_not_block_by_default(self):
     self.assertFalse(security.is_blocked(self.request))