From 1b0263d51d4844796ec0afec8dda048f96ff4e82 Mon Sep 17 00:00:00 2001 From: Loic Baron Date: Thu, 23 Apr 2015 11:39:00 +0200 Subject: [PATCH] Session with GET request --- portal/homeview.py | 107 +++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/portal/homeview.py b/portal/homeview.py index a6135328..f14a49a5 100644 --- a/portal/homeview.py +++ b/portal/homeview.py @@ -138,59 +138,62 @@ class HomeView (FreeAccessView, ThemeView): env = self.default_env() acc_auth_cred={} - - - if request.user.is_authenticated(): - jfed_identity = get_jfed_identity(request) - if jfed_identity is not None: - import base64 - encoded_jfed_identity = base64.b64encode(jfed_identity) - env['jfed_identity'] = encoded_jfed_identity - else: - env['jfed_identity'] = None - - ## check user is pi or not - platform_details = {} - account_details = {} - acc_auth_cred = {} - acc_user_cred = {} - platform_query = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled') - account_query = Query().get('local:account').select('user_id','platform_id','auth_type','config') - # XXX Something like an invalid session seems to make the execute fail sometimes, and thus gives an error on the main page - - account_detail = get_myslice_account(self.request) - if 'config' in account_detail and account_detail['config'] is not '': - account_config = json.loads(account_detail['config']) - acc_auth_cred = account_config.get('delegated_authority_credentials','N/A') - acc_user_cred = account_config.get('delegated_user_credential','N/A') - # assigning values - #if acc_auth_cred=={} or acc_auth_cred=='N/A': - # pi = "is_not_pi" - #else: - # pi = "is_pi" - user_email = str(self.request.user) - pi = authority_check_pis(self.request, user_email) - # check if the user has creds or not - if acc_user_cred == {} or acc_user_cred == 'N/A': - user_cred = 'no_creds' - else: - exp_date = get_expiration(acc_user_cred, 'timestamp') - if exp_date < time.time(): - user_cred = 'creds_expired' + try: + if request.user.is_authenticated(): + jfed_identity = get_jfed_identity(request) + if jfed_identity is not None: + import base64 + encoded_jfed_identity = base64.b64encode(jfed_identity) + env['jfed_identity'] = encoded_jfed_identity else: - user_cred = 'has_creds' - - # list the pending slices of this user - pending_slices = [] - for slices in PendingSlice.objects.filter(type_of_nodes__iexact=self.request.user).all(): - pending_slices.append(slices.slice_name) - - env['pending_slices'] = pending_slices - env['pi'] = pi - env['user_cred'] = user_cred - env['person'] = self.request.user - else: - env['person'] = None + env['jfed_identity'] = None + + ## check user is pi or not + platform_details = {} + account_details = {} + acc_auth_cred = {} + acc_user_cred = {} + platform_query = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled') + account_query = Query().get('local:account').select('user_id','platform_id','auth_type','config') + # XXX Something like an invalid session seems to make the execute fail sometimes, and thus gives an error on the main page + + account_detail = get_myslice_account(self.request) + if 'config' in account_detail and account_detail['config'] is not '': + account_config = json.loads(account_detail['config']) + acc_auth_cred = account_config.get('delegated_authority_credentials','N/A') + acc_user_cred = account_config.get('delegated_user_credential','N/A') + # assigning values + #if acc_auth_cred=={} or acc_auth_cred=='N/A': + # pi = "is_not_pi" + #else: + # pi = "is_pi" + user_email = str(self.request.user) + pi = authority_check_pis(self.request, user_email) + # check if the user has creds or not + if acc_user_cred == {} or acc_user_cred == 'N/A': + user_cred = 'no_creds' + else: + exp_date = get_expiration(acc_user_cred, 'timestamp') + if exp_date < time.time(): + user_cred = 'creds_expired' + else: + user_cred = 'has_creds' + + # list the pending slices of this user + pending_slices = [] + for slices in PendingSlice.objects.filter(type_of_nodes__iexact=self.request.user).all(): + pending_slices.append(slices.slice_name) + + env['pending_slices'] = pending_slices + env['pi'] = pi + env['user_cred'] = user_cred + env['person'] = self.request.user + else: + env['person'] = None + except Exception as e: + print e + env['person'] = None + env['state'] = "Your session has expired" env['theme'] = self.theme env['section'] = "Dashboard" -- 2.43.0