account: template specific for fed4fire
[unfold.git] / portal / accountview.py
index 9b0c466..5c8d15f 100644 (file)
@@ -11,7 +11,7 @@ from django.http                        import HttpResponse, HttpResponseRedirec
 from django.contrib                     import messages
 from django.contrib.auth.decorators     import login_required
 
-from theme import ThemeView
+from myslice.theme import ThemeView
 
 #
 import json, os, re, itertools
@@ -24,7 +24,7 @@ class AccountView(LoginRequiredAutoLogoutView, ThemeView):
 
 
     def get_context_data(self, **kwargs):
-
+        self.template_name = self.template
         page = Page(self.request)
         page.add_js_files  ( [ "js/jquery.validate.js", "js/my_account.register.js", "js/my_account.edit_profile.js" ] )
         page.add_css_files ( [ "css/onelab.css", "css/account_view.css","css/plugin.css" ] )
@@ -179,7 +179,6 @@ class AccountView(LoginRequiredAutoLogoutView, ThemeView):
         # we could use zip. this one is used if columns have unequal rows 
         platform_list = [{'platform_no_access': t[0]}
             for t in itertools.izip_longest(total_platform_list)]
-
         context = super(AccountView, self).get_context_data(**kwargs)
         context['principal_acc'] = principal_acc_list
         context['ref_acc'] = ref_acc_list
@@ -203,6 +202,7 @@ class AccountView(LoginRequiredAutoLogoutView, ThemeView):
         # so we can sho who is logged
         context['username'] = the_user(self.request)
         context['theme'] = self.theme
+        context['section'] = "User account"
 #        context ['firstname'] = config['firstname']
         prelude_env = page.prelude_env()
         context.update(prelude_env)
@@ -454,6 +454,29 @@ def account_process(request):
         else:
             messages.error(request, 'Account error: You need an account in myslice platform to perform this action')    
             return HttpResponseRedirect("/portal/account/")
+    
+    # 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: