From 4d47564ea6dab4f60bb168391b2a08706ef6ca00 Mon Sep 17 00:00:00 2001 From: Levi Date: Sat, 30 Apr 2016 13:55:55 -0500 Subject: [PATCH] Added redirect urls after signup/login --- hosting/mixins.py | 1 + hosting/views.py | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/hosting/mixins.py b/hosting/mixins.py index 7104e157..1f6366ab 100644 --- a/hosting/mixins.py +++ b/hosting/mixins.py @@ -16,5 +16,6 @@ class ProcessVMSelectionMixin(object): request.session['vm_specs'] = vm_specs if not request.user.is_authenticated(): request.session['vm_specs'] = vm_specs + request.session['next'] = reverse('hosting:payment') return redirect(reverse('hosting:login')) return redirect(reverse('hosting:payment')) diff --git a/hosting/views.py b/hosting/views.py index ecebdd80..65bbbcf3 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -110,13 +110,16 @@ class LoginView(FormView): form_class = HostingUserLoginForm moodel = CustomUser + def get_success_url(self): + next_url = self.request.session.get('next', self.success_url) + return next_url + def form_valid(self, form): email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') auth_user = authenticate(email=email, password=password) if auth_user: - login(self.request, auth_user) return HttpResponseRedirect(self.get_success_url()) @@ -129,7 +132,8 @@ class SignupView(CreateView): moodel = CustomUser def get_success_url(self): - return reverse_lazy('hosting:signup') + next_url = self.request.session.get('next', reverse_lazy('hosting:signup')) + return next_url def form_valid(self, form): @@ -190,14 +194,14 @@ class PaymentVMView(FormView): # Make stripe charge to a customer stripe_utils = StripeUtils() charge_response = stripe_utils.make_charge(amount=final_price, - customer=customer.stripe_id) + customer=customer.stripe_id) charge = charge_response.get('response_object') - # Check if the payment was approved + # Check if the payment was approved if not charge: context.update({ 'paymentError': charge_response.get('error'), - 'form':form + 'form': form }) return render(request, self.template_name, context) @@ -209,14 +213,15 @@ class PaymentVMView(FormView): # If the Stripe payment was successed, set order status approved order.set_approved() request.session.update({ - 'charge':charge, - 'order':order.id, - 'billing_address':billing_address.id + 'charge': charge, + 'order': order.id, + 'billing_address': billing_address.id }) return HttpResponseRedirect(reverse('hosting:invoice')) else: return self.form_invalid(form) + class InvoiceVMView(LoginRequiredMixin, View): template_name = "hosting/invoice.html" login_url = reverse_lazy('hosting:login') @@ -242,7 +247,6 @@ class InvoiceVMView(LoginRequiredMixin, View): } return context - def get(self, request, *args, **kwargs): context = self.get_context_data()