+ messages.error(request, 'Account error: You need an account in myslice platform to perform this action')
+ return HttpResponseRedirect("/portal/account/")
+
+ elif 'dl_pubkey' 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'])
+ public_key = account_config['user_public_key']
+ response = HttpResponse(public_key, content_type='text/plain')
+ response['Content-Disposition'] = 'attachment; filename="pubkey.txt"'
+ return response
+ break
+ else:
+ messages.error(request, 'Account error: You need an account in myslice platform to perform this action')
+ return HttpResponseRedirect("/portal/account/")
+
+ elif 'dl_pkey' 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']
+ response = HttpResponse(private_key, content_type='text/plain')
+ response['Content-Disposition'] = 'attachment; filename="privkey.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/")
+
+ elif 'delete' 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:
+ for key in account_config.keys():
+ if key== 'user_private_key':
+ del account_config[key]
+
+ updated_config = json.dumps(account_config)
+ user_params = { 'config': updated_config, 'auth_type':'user'}
+ manifold_update_account(request,user_params)
+ messages.success(request, 'Private Key deleted. You need to delegate credentials manually once it expires.')
+ return HttpResponseRedirect("/portal/account/")
+ else:
+ messages.error(request, 'Delete 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/")
+
+ # add reference platforms
+ elif 'add_fuseco' in request.POST:
+ # The recipients are the PI of the authority
+ #recipients = authority_get_pi_emails(request, authority_hrn)
+ recipients = ["support@myslice.info"]
+ requester = request.user # current user
+ sender = 'yasin.upmc@gmail.com' # the server email
+ msg = "OneLab user %s requested account in fuseco Platform" % requester
+ send_mail("Onelab user %s requested an account in Fuseco"%requester , msg, sender, recipients)
+ messages.info(request, 'Request to get access on Fuseco platform received. Please wait for PI\'s reply.')
+ return HttpResponseRedirect("/portal/account/")
+
+ elif 'add_ple' in request.POST:
+ # The recipients are the PI of the authority
+ #recipients = authority_get_pi_emails(request, authority_hrn)
+ recipients = ["support@myslice.info"]
+ requester = request.user # current user
+ sender = 'yasin.upmc@gmail.com' # the server email
+ msg = "OneLab user %s requested account in fuseco Platform" % requester
+ send_mail("Onelab user %s requested an account in PLE"%requester , msg, sender, recipients)
+ messages.info(request, 'Request to get access on PLE platform received. Please wait for PI\'s reply.')
+ return HttpResponseRedirect("/portal/account/")
+
+ elif 'add_omf' in request.POST:
+ # The recipients are the PI of the authority
+ #recipients = authority_get_pi_emails(request, authority_hrn)
+ recipients = ["support@myslice.info"]
+ requester = request.user # current user
+ sender = 'yasin.upmc@gmail.com' # the server email
+ msg = "OneLab user %s requested account in omf:nitos Platform" % requester
+ send_mail("Onelab user %s requested an account in OMF:NITOS"%requester , msg, sender, recipients)
+ messages.info(request, 'Request to get access on OMF:NITOS platform received. Please wait for PI\'s reply.')
+ return HttpResponseRedirect("/portal/account/")
+
+ elif 'add_wilab' in request.POST:
+ # The recipients are the PI of the authority
+ #recipients = authority_get_pi_emails(request, authority_hrn)
+ recipients = ["support@myslice.info"]
+ requester = request.user # current user
+ sender = 'yasin.upmc@gmail.com' # the server email
+ msg = "OneLab user %s requested account in Wilab Platform" % requester
+ send_mail("Onelab user %s requested an account in Wilab"%requester , msg, sender, recipients)
+ messages.info(request, 'Request to get access on Wilab platform received. Please wait for PI\'s reply.')
+ return HttpResponseRedirect("/portal/account/")
+
+ elif 'iotlab' in request.POST:
+ # The recipients are the PI of the authority
+ #recipients = authority_get_pi_emails(request, authority_hrn)
+ recipients = ["support@myslice.info"]
+ requester = request.user # current user
+ sender = 'yasin.upmc@gmail.com' # the server email
+ msg = "OneLab user %s requested account in IOTLab Platform" % requester
+ send_mail("Onelab user %s requested an account in IOTLab"%requester , msg, sender, recipients)
+ messages.info(request, 'Request to get access on IOTLab platform received. Please wait for PI\'s reply.')
+ return HttpResponseRedirect("/portal/account/")
+
+ #delete reference platoforms
+