Formatted code and added condition to create user only if an email does not exist
This commit is contained in:
		
					parent
					
						
							
								e5ad57d3f1
							
						
					
				
			
			
				commit
				
					
						f67b69d490
					
				
			
		
					 1 changed files with 26 additions and 19 deletions
				
			
		| 
						 | 
				
			
			@ -32,6 +32,7 @@ from .models import BetaAccess, BetaAccessVMType, BetaAccessVM, VMTemplate
 | 
			
		|||
 | 
			
		||||
logger = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ContactUsView(FormView):
 | 
			
		||||
    template_name = "datacenterlight/contact_form.html"
 | 
			
		||||
    form_class = ContactForm
 | 
			
		||||
| 
						 | 
				
			
			@ -479,7 +480,8 @@ class PaymentOrderView(FormView):
 | 
			
		|||
                return self.render_to_response(
 | 
			
		||||
                    self.get_context_data(form=form))
 | 
			
		||||
            request.session['token'] = token
 | 
			
		||||
            request.session['customer'] = customer.id if request.user.is_authenticated() else customer
 | 
			
		||||
            request.session[
 | 
			
		||||
                'customer'] = customer.id if request.user.is_authenticated() else customer
 | 
			
		||||
            return HttpResponseRedirect(
 | 
			
		||||
                reverse('datacenterlight:order_confirmation'))
 | 
			
		||||
        else:
 | 
			
		||||
| 
						 | 
				
			
			@ -500,7 +502,8 @@ class OrderConfirmationView(DetailView):
 | 
			
		|||
            return HttpResponseRedirect(reverse('datacenterlight:payment'))
 | 
			
		||||
        stripe_customer_id = request.session.get('customer')
 | 
			
		||||
        if request.user.is_authenticated():
 | 
			
		||||
            customer = StripeCustomer.objects.filter(id=stripe_customer_id).first()
 | 
			
		||||
            customer = StripeCustomer.objects.filter(
 | 
			
		||||
                id=stripe_customer_id).first()
 | 
			
		||||
            stripe_api_cus_id = customer.stripe_id
 | 
			
		||||
        else:
 | 
			
		||||
            stripe_api_cus_id = stripe_customer_id
 | 
			
		||||
| 
						 | 
				
			
			@ -529,7 +532,8 @@ class OrderConfirmationView(DetailView):
 | 
			
		|||
        user = request.session.get('user')
 | 
			
		||||
        stripe_customer_id = request.session.get('customer')
 | 
			
		||||
        if request.user.is_authenticated():
 | 
			
		||||
            customer = StripeCustomer.objects.filter(id=stripe_customer_id).first()
 | 
			
		||||
            customer = StripeCustomer.objects.filter(
 | 
			
		||||
                id=stripe_customer_id).first()
 | 
			
		||||
            stripe_api_cus_id = customer.stripe_id
 | 
			
		||||
        else:
 | 
			
		||||
            stripe_api_cus_id = stripe_customer_id
 | 
			
		||||
| 
						 | 
				
			
			@ -579,13 +583,16 @@ class OrderConfirmationView(DetailView):
 | 
			
		|||
            return HttpResponseRedirect(
 | 
			
		||||
                reverse('datacenterlight:payment') + '#payment_error')
 | 
			
		||||
 | 
			
		||||
        # Create user if the user is not logged in
 | 
			
		||||
        if not request.user.is_authenticated():
 | 
			
		||||
        # Create user if the user is not logged in and if he is not already
 | 
			
		||||
        # registered
 | 
			
		||||
        if not request.user.is_authenticated() and CustomUser.objects.filter(
 | 
			
		||||
                email=user.get('email')).exists():
 | 
			
		||||
            try:
 | 
			
		||||
                custom_user = CustomUser.objects.get(
 | 
			
		||||
                    email=user.get('email'))
 | 
			
		||||
            except CustomUser.DoesNotExist:
 | 
			
		||||
                logger.debug("Customer {} does not exist.".format(user.get('email')))
 | 
			
		||||
                logger.debug(
 | 
			
		||||
                    "Customer {} does not exist.".format(user.get('email')))
 | 
			
		||||
                password = CustomUser.get_random_password()
 | 
			
		||||
                # Register the user, and do not send emails
 | 
			
		||||
                custom_user = CustomUser.register(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue