From 47c1017ecb82f8880e56565fb0f2eb7e7baccc5b Mon Sep 17 00:00:00 2001 From: Yasin Date: Fri, 2 Aug 2013 17:47:18 +0200 Subject: [PATCH] /portal/account: upload file stores it into PendingUser:Keypair Field --- portal/templates/my_account.html | 2 +- portal/views.py | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/portal/templates/my_account.html b/portal/templates/my_account.html index 35dfa102..634f2c5c 100644 --- a/portal/templates/my_account.html +++ b/portal/templates/my_account.html @@ -103,7 +103,7 @@
- + diff --git a/portal/views.py b/portal/views.py index baa33a45..0412f930 100644 --- a/portal/views.py +++ b/portal/views.py @@ -36,6 +36,7 @@ from manifold.core.query import Query from unfold.page import Page from myslice.viewutils import topmenu_items, the_user from django.http import HttpResponseRedirect, HttpResponse +import os.path, re class DashboardView(TemplateView): template_name = "dashboard.html" @@ -465,6 +466,8 @@ def my_account(request): #my_acc form value processing def acc_process(request): + # getting the user_id from the session [now hardcoded] + get_user = PendingUser.objects.get(id='1') # here we will get the id/email from session e.g., person.email if 'submit_name' in request.POST: edited_first_name = request.POST['fname'] edited_last_name = request.POST['lname'] @@ -482,7 +485,7 @@ def acc_process(request): # select and update [will be used throughout this view] # select the logged in user [for the moment hard coded] - get_user = PendingUser.objects.get(id='1') # here we will get the id/email from session e.g., person.email + #get_user = PendingUser.objects.get(id='1') # here we will get the id/email from session e.g., person.email # update first and last name get_user.first_name = edited_first_name get_user.last_name = edited_last_name @@ -492,7 +495,7 @@ def acc_process(request): elif 'submit_pass' in request.POST: edited_password = request.POST['password'] # select the logged in user [for the moment hard coded] - get_user = PendingUser.objects.get(id='1') # here we will get the id/email from session e.g., person.email + #get_user = PendingUser.objects.get(id='1') # here we will get the id/email from session e.g., person.email # update password get_user.password = edited_password get_user.save() @@ -501,6 +504,22 @@ def acc_process(request): a =2 message = 'Here will generate ssh-rsa keys :D %d' %a return HttpResponse(message) + elif 'upload_key' in request.POST: + up_file = request.FILES['pubkey'] + file_content = up_file.read() + file_name = up_file.name + file_extension = os.path.splitext(file_name)[1] + allowed_extension = ['.pub','.txt'] + if file_extension in allowed_extension: + file_content = '{user_public_key:'+ file_content +'}' + file_content = re.sub("\r", "", file_content) + file_content = re.sub("\n", "\\n",file_content) + get_user.keypair = file_content + get_user.save() + return HttpResponse('Success: Publickey uploaded! Old records overwritten') + else: + return HttpResponse('Please upload a valid public key.') + else: message = 'You submitted an empty form.' return HttpResponse(message) -- 2.43.0