+
+ # download identity for jfed
+ elif 'dl_identity' in request.POST:
+ for account_detail in account_details:
+ for platform_detail in platform_details:
+ if platform_detail['platform_id'] == account_detail['platform_id']:
+ if 'myslice' in platform_detail['platform']:
+ account_config = json.loads(account_detail['config'])
+ if 'user_private_key' in account_config:
+ private_key = account_config['user_private_key']
+ user_hrn = account_config.get('user_hrn','N/A')
+ registry = 'http://sfa-fed4fire.pl.sophia.inria.fr:12345/'
+ jfed_identity = user_hrn + '\n' + registry + '\n' + private_key
+ response = HttpResponse(jfed_identity, content_type='text/plain')
+ response['Content-Disposition'] = 'attachment; filename="jfed_identity.txt"'
+ return response
+ else:
+ messages.error(request, 'Download error: Private key is not stored in the server')
+ return HttpResponseRedirect("/portal/account/")
+
+ else:
+ messages.error(request, 'Account error: You need an account in myslice platform to perform this action')
+ return HttpResponseRedirect("/portal/account/")
+
+ #clear all creds
+ elif 'clear_cred' in request.POST:
+ for account_detail in account_details:
+ for platform_detail in platform_details:
+ if platform_detail['platform_id'] == account_detail['platform_id']:
+ if 'myslice' in platform_detail['platform']:
+ account_config = json.loads(account_detail['config'])
+ user_cred = account_config.get('delegated_user_credential','N/A')
+ if 'N/A' not in user_cred:
+ user_hrn = account_config.get('user_hrn','N/A')
+ user_pub_key = json.dumps(account_config.get('user_public_key','N/A'))
+ user_priv_key = json.dumps(account_config.get('user_private_key','N/A'))
+ updated_config = '{"user_public_key":'+ user_pub_key + ', "user_private_key":'+ user_priv_key + ', "user_hrn":"'+ user_hrn + '"}'
+ user_params = { 'config': updated_config}
+ manifold_update_account(request,user_id, user_params)
+ messages.success(request, 'All Credentials cleared')
+ return HttpResponseRedirect("/portal/account/")
+ else:
+ messages.error(request, 'Delete error: Credentials are not stored in the server')
+ return HttpResponseRedirect("/portal/account/")
+ else:
+ messages.error(request, 'Account error: You need an account in myslice platform to perform this action')
+ return HttpResponseRedirect("/portal/account/")
+
+
+ # Download delegated_user_cred
+ elif 'dl_user_cred' in request.POST:
+ if 'delegated_user_credential' in account_config:
+ user_cred = account_config['delegated_user_credential']
+ response = HttpResponse(user_cred, content_type='text/plain')
+ response['Content-Disposition'] = 'attachment; filename="user_cred.txt"'
+ return response
+ else:
+ messages.error(request, 'Download error: User credential is not stored in the server')
+ return HttpResponseRedirect("/portal/account/")
+