MyAccount: user_hrn preserved while using genkey and upload key
authorYasin <mohammed-yasin.rahman@lip6.fr>
Fri, 15 Nov 2013 14:48:09 +0000 (15:48 +0100)
committerYasin <mohammed-yasin.rahman@lip6.fr>
Fri, 15 Nov 2013 14:48:09 +0000 (15:48 +0100)
portal/accountview.py
portal/registrationview.py

index d9666cb..646ea2c 100644 (file)
@@ -164,12 +164,17 @@ def account_process(request):
                         # now we overwrite the config field with keypair
                         # once there will be user_hrn, we need to keep user_hrn and change only the keypair
                         # see submit_name section for implementing this    
-                        keypair = '{"user_public_key":'+ public_key + ', "user_private_key":'+ private_key + '}'
 #                       keypair = re.sub("\r", "", keypair)
 #                       keypair = re.sub("\n", "\\n", keypair)
 #                       #keypair = keypair.rstrip('\r\n')
 #                       keypair = ''.join(keypair.split())
                         # updating maniolf local:account table
+                        account_config = json.loads(account_detail['config'])
+                        # preserving user_hrn
+                        user_hrn = account_config['user_hrn']
+                        keypair = '{"user_public_key":'+ public_key + ', "user_private_key":'+ private_key + ', "user_hrn":"'+ user_hrn + '"}'
+                        updated_config = json.dumps(account_config) 
+
                         user_params = { 'config': keypair, 'auth_type':'managed'}
                         manifold_update_account(request,user_params)
                         messages.success(request, 'Sucess: New Keypair Generated!')
@@ -189,7 +194,10 @@ def account_process(request):
                         file_extension = os.path.splitext(file_name)[1] 
                         allowed_extension =  ['.pub','.txt']
                         if file_extension in allowed_extension and re.search(r'ssh-rsa',file_content):
-                            file_content = '{"user_public_key":"'+ file_content +'"}'
+                            account_config = json.loads(account_detail['config'])
+                            # preserving user_hrn
+                            user_hrn = account_config['user_hrn']
+                            file_content = '{"user_public_key":"'+ file_content + '", "user_hrn":"'+ user_hrn +'"}'
                             #file_content = re.sub("\r", "", file_content)
                             #file_content = re.sub("\n", "\\n",file_content)
                             file_content = ''.join(file_content.split())
index aebe181..85935f2 100644 (file)
@@ -93,7 +93,7 @@ class RegistrationView (FreeAccessView):
 #                private_key = ''.join(private_key.split())
 #                public_key = "ssh-rsa " + public_key
                 # Saving to DB
-                keypair = '{"user_public_key":'+ public_key + ', "user_private_key":'+ private_key + ', "user_hrn":'+ user_hrn + '}'
+                keypair = '{"user_public_key":'+ public_key + ', "user_private_key":'+ private_key + ', "user_hrn":"'+ user_hrn + '"}'
                 #keypair = re.sub("\r", "", keypair)
                 #keypair = re.sub("\n", "\\n", keypair)
                 #keypair = keypair.rstrip('\r\n')
@@ -105,7 +105,7 @@ class RegistrationView (FreeAccessView):
                 file_extension = os.path.splitext(file_name)[1]
                 allowed_extension =  ['.pub','.txt']
                 if file_extension in allowed_extension and re.search(r'ssh-rsa',file_content):
-                    keypair = '{"user_public_key":"'+ file_content +'"}'
+                    keypair = '{"user_public_key":"'+ file_content + '", "user_hrn":"'+ user_hrn +'"}'
                     keypair = re.sub("\r", "", keypair)
                     keypair = re.sub("\n", "\\n",keypair)
                     keypair = ''.join(keypair.split())
@@ -135,11 +135,11 @@ class RegistrationView (FreeAccessView):
                     'first_name'    : reg_fname, 
                     'last_name'     : reg_lname, 
                     'authority_hrn' : reg_auth,
-                    'email'         : reg_email, 
+                    'email'         : reg_email,
+                    'user_hrn'      : user_hrn,
                     'keypair'       : 'Public Key :' + public_key,
                     'cc_myself'     : True # form.cleaned_data['cc_myself']
                     }
-
                 recipients = authority_get_pi_emails(request,reg_auth)
 
                 if ctx['cc_myself']: