From 5abab265d806d9de899ead6e896feb4afdf20540 Mon Sep 17 00:00:00 2001 From: Yasin Date: Wed, 18 Sep 2013 15:40:17 +0200 Subject: [PATCH] MyAccount: Generate keys+Upload keys Ok [users needs to have account on myslice to do that], CSS improved. actions.py: update account function fixed. --- portal/accountview.py | 18 ++++++++++-------- portal/actions.py | 2 +- portal/static/css/account_view_html.css | 18 ++++-------------- portal/templates/account-view.html | 2 +- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/portal/accountview.py b/portal/accountview.py index 5f7a3960..5671b51c 100644 --- a/portal/accountview.py +++ b/portal/accountview.py @@ -2,13 +2,13 @@ from portal.templateviews import LoginRequiredAutoLogoutView # from manifold.core.query import Query from manifold.manifoldapi import execute_query -from portal.actions import manifold_update_user +from portal.actions import manifold_update_user, manifold_update_account # from myslice.viewutils import topmenu_items, the_user # from django.http import HttpResponse from django.contrib.auth.decorators import login_required -import json +import json, os, re # requires login class AccountView(LoginRequiredAutoLogoutView): @@ -132,14 +132,15 @@ def account_process(request): private_key = k.as_pem() private_key = ''.join(private_key.split()) public_key = "ssh-rsa " + public_key + print "testing" # Saving to DB 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()) - get_user.keypair = keypair - get_user.save() + user_params = { 'config': keypair} + manifold_update_account(request,user_params) return HttpResponse('Success: New Keypair Generated! %s' % keypair) elif 'upload_key' in request.POST: @@ -150,11 +151,12 @@ def account_process(request): 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 +'"}' - file_content = re.sub("\r", "", file_content) - file_content = re.sub("\n", "\\n",file_content) + #file_content = re.sub("\r", "", file_content) + #file_content = re.sub("\n", "\\n",file_content) file_content = ''.join(file_content.split()) - get_user.keypair = file_content - get_user.save() + # update manifold account table + user_params = { 'config': file_content} + manifold_update_account(request,user_params) return HttpResponse('Success: Publickey uploaded! Old records overwritten') else: return HttpResponse('Please upload a valid RSA public key [.txt or .pub].') diff --git a/portal/actions.py b/portal/actions.py index 03a0e93b..21b2563e 100644 --- a/portal/actions.py +++ b/portal/actions.py @@ -72,7 +72,7 @@ def manifold_add_account(request, account_params): def manifold_update_account(request,account_params): # account_params: config - query = Query.update('local:account').filter_by('email', '==', request.user.email).set(account_params).select('email') + query = Query.update('local:account').filter_by('platform', '==', 'myslice').set(account_params).select('user_id') results = execute_query(request,query) # NOTE: results remains empty and goes to Exception. However, it updates the manifold DB. # That's why I commented the exception part. -- Yasin diff --git a/portal/static/css/account_view_html.css b/portal/static/css/account_view_html.css index 0b1b6bb9..dd77998d 100644 --- a/portal/static/css/account_view_html.css +++ b/portal/static/css/account_view_html.css @@ -205,21 +205,11 @@ ul.errorlist li { -table.mytable { border-collapse: collapse; border: 1px solid #839E99; -background: #f1f8ee; font: .9em/1.2em Georgia, "Times New Roman", Times, serif; color: #033;table-layout:fixed; } -.mytable caption { font-size: 1.3em; font-weight: bold; text-align: left; padding: 1em 4px; } +table.mytable { border-collapse: collapse; border: 1px solid #839E99;background: #f1f8ee; font: .9em/1.2em Georgia, "Times New Roman", Times, serif; color: #033; table-layout:fixed; width:870px} .mytable td, th { padding: 3px 3px .75em 3px; line-height: 1.3em; } -.mytable th { background: #839E99; color: #fff; font-weight: bold; text-align: left; padding-right: .5em; vertical-align: top; align="center" style="width:15%;word-wrap: break-word" } -.mytable thead th { background: #2C5755; text-align: center; } -.mytable thead td {style="width:15%;word-wrap: break-word"} -.mytable .odd td { background: #DBE6DD; style="width:15%;word-wrap: break-word"} -.mytable .odd th { background: #6E8D88; } -.mytable td a, td a:link { color: #325C91; } -.mytable td a:visited { color: #466C8E; } -.mytable td a:hover, td a:focus { color: #1E4C94; } -.mytable th a, td a:active { color: #fff; } -.mytable tfoot th, tfoot td { background: #2C5755; color: #fff; } -.mytable th + td { padding-left: .5em; } +.mytable th { background: #839E99; color: #fff; font-weight: bold; padding-right: .5em; vertical-align: top; text-align:center } +.mytable td {word-wrap: break-word; text-align:center} +tr.border_bottom td {border-bottom:1pt solid green;} /****************************** diff --git a/portal/templates/account-view.html b/portal/templates/account-view.html index 8cd7c637..4e97f9d7 100644 --- a/portal/templates/account-view.html +++ b/portal/templates/account-view.html @@ -21,7 +21,7 @@ Pub Key {% for row in data %} - + {{ row.platform_name }} {{ row.account_type }} {{ row.usr_hrn }} -- 2.43.0