Added redirect urls after signup/login

This commit is contained in:
Levi 2016-04-30 13:55:55 -05:00
parent 57b1ab7022
commit 1c5fc6a437
2 changed files with 14 additions and 9 deletions

View file

@ -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'))

View file

@ -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):
@ -197,7 +201,7 @@ class PaymentVMView(FormView):
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()