From 26fab27c3fb476c255b02f5fec343d2e2d31d9e7 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 1 Jul 2019 23:17:27 +0530 Subject: [PATCH] Set new_user_hosting_key_id session variable to track newly created key --- utils/views.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/utils/views.py b/utils/views.py index 0429c7db..05d0fdc2 100644 --- a/utils/views.py +++ b/utils/views.py @@ -225,13 +225,16 @@ class SSHKeyCreateView(FormView): 'form': UserHostingKeyForm(request=self.request), }) - owner = self.request.user - manager = OpenNebulaManager( - email=owner.email, - password=owner.password - ) - keys_to_save = get_all_public_keys(self.request.user) - manager.save_key_in_opennebula_user('\n'.join(keys_to_save)) + if self.request.user.is_authenticated(): + owner = self.request.user + manager = OpenNebulaManager( + email=owner.email, + password=owner.password + ) + keys_to_save = get_all_public_keys(self.request.user) + manager.save_key_in_opennebula_user('\n'.join(keys_to_save)) + else: + self.request.session["new_user_hosting_key_id"] = form.instance.id return HttpResponseRedirect(self.success_url) def post(self, request, *args, **kwargs):