Do a user login after creation

This commit is contained in:
M.Ravi 2017-09-22 12:46:33 +02:00
parent 31f7c4a51a
commit 4c0c1ffb27

View file

@ -537,10 +537,8 @@ class OrderConfirmationView(DetailView):
stripe_api_cus_id = customer.stripe_id stripe_api_cus_id = customer.stripe_id
else: else:
stripe_api_cus_id = stripe_customer_id stripe_api_cus_id = stripe_customer_id
vm_template_id = template.get('id', 1) vm_template_id = template.get('id', 1)
# Make stripe charge to a customer
stripe_utils = StripeUtils() stripe_utils = StripeUtils()
card_details = stripe_utils.get_card_details(stripe_api_cus_id, card_details = stripe_utils.get_card_details(stripe_api_cus_id,
request.session.get( request.session.get(
@ -575,8 +573,8 @@ class OrderConfirmationView(DetailView):
'response_object').stripe_plan_id}]) 'response_object').stripe_plan_id}])
stripe_subscription_obj = subscription_result.get('response_object') stripe_subscription_obj = subscription_result.get('response_object')
# Check if the subscription was approved and is active # Check if the subscription was approved and is active
if stripe_subscription_obj is None or \ if stripe_subscription_obj is None \
stripe_subscription_obj.status != 'active': or stripe_subscription_obj.status != 'active':
msg = subscription_result.get('error') msg = subscription_result.get('error')
messages.add_message(self.request, messages.ERROR, msg, messages.add_message(self.request, messages.ERROR, msg,
extra_tags='failed_payment') extra_tags='failed_payment')
@ -593,7 +591,6 @@ class OrderConfirmationView(DetailView):
logger.debug( logger.debug(
"Customer {} does not exist.".format(user.get('email'))) "Customer {} does not exist.".format(user.get('email')))
password = CustomUser.get_random_password() password = CustomUser.get_random_password()
# Register the user, and do not send emails
custom_user = CustomUser.register( custom_user = CustomUser.register(
user.get('name'), password, user.get('name'), password,
user.get('email'), user.get('email'),
@ -604,6 +601,9 @@ class OrderConfirmationView(DetailView):
stripe_customer = StripeCustomer.objects. \ stripe_customer = StripeCustomer.objects. \
create(user=custom_user, stripe_id=stripe_api_cus_id) create(user=custom_user, stripe_id=stripe_api_cus_id)
stripe_customer_id = stripe_customer.id stripe_customer_id = stripe_customer.id
new_user = authenticate(username=custom_user.email,
password=password)
login(request, new_user)
else: else:
customer = StripeCustomer.objects.filter( customer = StripeCustomer.objects.filter(
id=stripe_customer_id).first() id=stripe_customer_id).first()