From: Yasin Date: Mon, 23 Sep 2013 14:31:07 +0000 (+0200) Subject: MyAccount: Download pubkey+priv key- OK X-Git-Tag: myslice-0.2-4~50^2~2 X-Git-Url: http://git.onelab.eu/?p=myslice.git;a=commitdiff_plain;h=460f78080696a2115f1ff4c01cfb9eaafd3f1b18 MyAccount: Download pubkey+priv key- OK --- diff --git a/portal/accountview.py b/portal/accountview.py index 30e0b9a4..d5f85e97 100644 --- a/portal/accountview.py +++ b/portal/accountview.py @@ -1,6 +1,6 @@ -from portal.templateviews import LoginRequiredAutoLogoutView +from portal.templateviews import LoginRequiredAutoLogoutView # -from manifold.core.query import Query +from manifold.core.query import Query from manifold.manifoldapi import execute_query from portal.actions import manifold_update_user, manifold_update_account # @@ -93,6 +93,16 @@ class AccountView(LoginRequiredAutoLogoutView): def account_process(request): user_query = Query().get('local:user').select('password','config') user_details = execute_query(request, user_query) + + account_query = Query().get('local:account').select('user_id','platform_id','auth_type','config') + account_details = execute_query(request, account_query) + + platform_query = Query().get('local:platform').select('platform_id','platform') + platform_details = execute_query(request, platform_query) + + # for account_detail in account_details: + # if account_detail['platform_id'] == 5: + # account_config = json.loads(account_detail['config']) if 'submit_name' in request.POST: edited_first_name = request.POST['fname'] @@ -173,6 +183,42 @@ def account_process(request): # return HttpResponse('Please upload a valid RSA public key [.txt or .pub].') messages.error(request, 'RSA key error: Please upload a valid RSA public key [.txt or .pub].') 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.success(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']) + print "hello" + 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.success(request, 'download error: Private key is not stored in the server') + return HttpResponseRedirect("/portal/account/") + + else: + messages.success(request, 'Account error: You need an account in myslice platform to perform this action') + return HttpResponseRedirect("/portal/account/") + else: messages.info(request, 'Under Construction. Please try again later!')