Move login code out of the refactored do_create_vm
This commit is contained in:
parent
9d765fcb6e
commit
812157b6c6
1 changed files with 13 additions and 3 deletions
|
@ -1017,11 +1017,18 @@ class OrderConfirmationView(DetailView, FormView):
|
||||||
"requires_source_action")
|
"requires_source_action")
|
||||||
msg = subscription_result.get('error')
|
msg = subscription_result.get('error')
|
||||||
return show_error(msg, self.request)
|
return show_error(msg, self.request)
|
||||||
do_create_vm(req, user, stripe_api_cus_id,
|
do_create_vm(
|
||||||
|
req, user, stripe_api_cus_id,
|
||||||
card_details_response, stripe_subscription_obj,
|
card_details_response, stripe_subscription_obj,
|
||||||
stripe_onetime_charge, gp_details, specs, vm_template_id,
|
stripe_onetime_charge, gp_details, specs, vm_template_id,
|
||||||
template, request.session.get('billing_address_data')
|
template, request.session.get('billing_address_data')
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
|
custom_user = CustomUser.objects.get(email=user.get('email'))
|
||||||
|
login(self.request, custom_user)
|
||||||
|
except (CustomUser.DoesNotExist,
|
||||||
|
CustomUser.MultipleObjectsReturned) as ex:
|
||||||
|
logger.error(str(ex))
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
'status': True,
|
'status': True,
|
||||||
|
@ -1102,16 +1109,17 @@ def do_create_vm(request, user, stripe_api_cus_id, card_details_response,
|
||||||
stripe_customer_id = stripe_customer.id
|
stripe_customer_id = stripe_customer.id
|
||||||
new_user = authenticate(username=custom_user.email,
|
new_user = authenticate(username=custom_user.email,
|
||||||
password=password)
|
password=password)
|
||||||
# TODO do we need login here ?
|
logger.debug("User %s is authenticated" % custom_user.email)
|
||||||
login(request, new_user)
|
|
||||||
if 'new_user_hosting_key_id' in request:
|
if 'new_user_hosting_key_id' in request:
|
||||||
user_hosting_key = UserHostingKey.objects.get(
|
user_hosting_key = UserHostingKey.objects.get(
|
||||||
id=request['new_user_hosting_key_id'])
|
id=request['new_user_hosting_key_id'])
|
||||||
user_hosting_key.user = new_user
|
user_hosting_key.user = new_user
|
||||||
user_hosting_key.save()
|
user_hosting_key.save()
|
||||||
|
logger.debug("User's key is saved" % custom_user.email)
|
||||||
|
|
||||||
if 'card_id' in request:
|
if 'card_id' in request:
|
||||||
card_id = request.get('card_id')
|
card_id = request.get('card_id')
|
||||||
|
logger.debug("card_id %s was in request" % card_id)
|
||||||
user_card_detail = UserCardDetail.objects.get(id=card_id)
|
user_card_detail = UserCardDetail.objects.get(id=card_id)
|
||||||
card_details_dict = {
|
card_details_dict = {
|
||||||
'last4': user_card_detail.last4,
|
'last4': user_card_detail.last4,
|
||||||
|
@ -1124,6 +1132,8 @@ def do_create_vm(request, user, stripe_api_cus_id, card_details_response,
|
||||||
stripe_source_id=user_card_detail.card_id
|
stripe_source_id=user_card_detail.card_id
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
logger.debug("card_id %s was NOT in request, using "
|
||||||
|
"card_details_response")
|
||||||
ucd = UserCardDetail.get_or_create_user_card_detail(
|
ucd = UserCardDetail.get_or_create_user_card_detail(
|
||||||
stripe_customer=custom_user.stripecustomer,
|
stripe_customer=custom_user.stripecustomer,
|
||||||
card_details=card_details_response
|
card_details=card_details_response
|
||||||
|
|
Loading…
Reference in a new issue