user logged in after signup on payment page
This commit is contained in:
		
					parent
					
						
							
								f2a04c20f2
							
						
					
				
			
			
				commit
				
					
						7a4573f7ad
					
				
			
		
					 3 changed files with 43 additions and 19 deletions
				
			
		| 
						 | 
				
			
			@ -68,6 +68,11 @@
 | 
			
		|||
                        <h3><b>{%trans "Billing Address"%}</b></h3>
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
                    <hr class="top-hr">
 | 
			
		||||
                    {% for message in messages %}
 | 
			
		||||
                        {% if 'duplicate_email' in message.tags %}
 | 
			
		||||
                        <p class="text-danger">{{message}}</p>
 | 
			
		||||
                        {% endif %}
 | 
			
		||||
                    {% endfor %}
 | 
			
		||||
                    <form role="form" id="billing-form" method="post" action="" novalidate>
 | 
			
		||||
                        {% csrf_token %}
 | 
			
		||||
                        {% for field in form %}
 | 
			
		||||
| 
						 | 
				
			
			@ -146,10 +151,14 @@
 | 
			
		|||
                                {% endif %}
 | 
			
		||||
                                <div id='payment_error'>
 | 
			
		||||
                                    {% for message in messages %}
 | 
			
		||||
                                        {% if 'failed_payment' or 'make_charge_error' in message.tags %}
 | 
			
		||||
                                         <ul class="list-unstyled"><li>
 | 
			
		||||
                                             <p class="card-warning-content card-warning-error">{{ message|safe }}</p>
 | 
			
		||||
                                        </li></ul>
 | 
			
		||||
                                        {% if 'failed_payment' in message.tags or 'make_charge_error' in message.tags %}
 | 
			
		||||
                                            <ul class="list-unstyled">
 | 
			
		||||
                                                <li><p class="card-warning-content card-warning-error">{{ message|safe }}</p></li>
 | 
			
		||||
                                            </ul>
 | 
			
		||||
                                        {% elif not form.non_field_errors %}
 | 
			
		||||
                                            <p class="card-warning-content">
 | 
			
		||||
                                                {% trans "You are not making any payment yet. After placing your order, you will be taken to the Submit Payment Page." %}
 | 
			
		||||
                                            </p>
 | 
			
		||||
                                        {% endif %}
 | 
			
		||||
                                    {% endfor %}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
from django import forms
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from django.contrib import messages
 | 
			
		||||
from django.contrib.auth import login, authenticate
 | 
			
		||||
from django.core.exceptions import ValidationError
 | 
			
		||||
from django.core.urlresolvers import reverse
 | 
			
		||||
from django.http import HttpResponseRedirect
 | 
			
		||||
| 
						 | 
				
			
			@ -484,30 +485,44 @@ class PaymentOrderView(FormView):
 | 
			
		|||
            billing_address_data = form.cleaned_data
 | 
			
		||||
            token = form.cleaned_data.get('token')
 | 
			
		||||
            if request.user.is_authenticated():
 | 
			
		||||
                user = {
 | 
			
		||||
                this_user = {
 | 
			
		||||
                    'email': request.user.email,
 | 
			
		||||
                    'name': request.user.name
 | 
			
		||||
                }
 | 
			
		||||
            else:
 | 
			
		||||
                user = {
 | 
			
		||||
                this_user = {
 | 
			
		||||
                    'email': form.cleaned_data.get('email'),
 | 
			
		||||
                    'name': form.cleaned_data.get('name')
 | 
			
		||||
                }
 | 
			
		||||
            request.session['user'] = user
 | 
			
		||||
                try:
 | 
			
		||||
                CustomUser.objects.get(email=user.get('email'))
 | 
			
		||||
                    custom_user = CustomUser.objects.get(
 | 
			
		||||
                        email=this_user.get('email'))
 | 
			
		||||
                except CustomUser.DoesNotExist:
 | 
			
		||||
                    password = CustomUser.get_random_password()
 | 
			
		||||
                    # Register the user, and do not send emails
 | 
			
		||||
                CustomUser.register(user.get('name'),
 | 
			
		||||
                                    password,
 | 
			
		||||
                                    user.get('email'),
 | 
			
		||||
                                    app='dcl',
 | 
			
		||||
                                    base_url=None, send_email=False)
 | 
			
		||||
                    custom_user = CustomUser.register(
 | 
			
		||||
                        this_user.get('name'), password,
 | 
			
		||||
                        this_user.get('email'),
 | 
			
		||||
                        app='dcl', base_url=None, send_email=False
 | 
			
		||||
                    )
 | 
			
		||||
                    new_user = authenticate(
 | 
			
		||||
                        username=custom_user.email,
 | 
			
		||||
                        password=password)
 | 
			
		||||
                    login(request, new_user)
 | 
			
		||||
                else:
 | 
			
		||||
                    # new user used the email of existing user, fail
 | 
			
		||||
                    messages.error(
 | 
			
		||||
                        self.request,
 | 
			
		||||
                        _('Another user exists with that email!'),
 | 
			
		||||
                        extra_tags='duplicate_email'
 | 
			
		||||
                    )
 | 
			
		||||
                    return HttpResponseRedirect(
 | 
			
		||||
                        reverse('datacenterlight:payment'))
 | 
			
		||||
 | 
			
		||||
            request.session['user'] = this_user
 | 
			
		||||
            # Get or create stripe customer
 | 
			
		||||
            customer = StripeCustomer.get_or_create(
 | 
			
		||||
                email=user.get('email'),
 | 
			
		||||
                email=this_user.get('email'),
 | 
			
		||||
                token=token)
 | 
			
		||||
            if not customer:
 | 
			
		||||
                form.add_error("__all__", "Invalid credit card")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								hosting/static/hosting/css/bootstrap.min.css
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								hosting/static/hosting/css/bootstrap.min.css
									
										
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue