def get_user_home(user): #LOG.info("xxx enter get_user_home of openstack_dashboard/views.py") #LOG.info("xxx user is") #LOG.info(user) try: token = user.token except AttributeError: raise exceptions.NotAuthenticated() # Domain Admin, Project Admin will default to identity dashboard = None if token.project.get('id') is None or user.is_superuser: try: dashboard = horizon.get_dashboard('identity') except base.NotRegistered: pass if dashboard is None: dashboard = horizon.get_default_dashboard() #LOG.info("dashboard = horizon.get_default_dashboard() is") #LOG.info(dashboard) #LOG.info("dashboard.get_absolute_url() is") #LOG.info(dashboard.get_absolute_url()) return dashboard.get_absolute_url()
def splash(request): LOG.info(request.__dict__) LOG.info("In splash function") LOG.info(request.user) LOG.info('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$4') if not request.user.is_authenticated(): LOG.info("User not autenticated ") raise exceptions.NotAuthenticated() if TWO_FACTOR_ENABLED: #check whether otp page is shown, if not show. if not 'otp_shown' in request.session: LOG.info('otp_shown is not present in the session') response = shortcuts.redirect('/dashboard/otp') else: LOG.info('otp_shown value is present in session') if not request.session['otp_shown']: LOG.info('enter-1') response = shortcuts.redirect('/dashboard/otp') response = shortcuts.redirect('/dashboard/otp') else: print "npoooooooooooooooooooooo" response = shortcuts.redirect(horizon.get_user_home(request.user)) if 'logout_reason' in request.COOKIES: response.delete_cookie('logout_reason') #response.delete_cookie('sessionid') LOG.info('response returned') LOG.info('++++++++++++++++++++++++++++') LOG.info(response) return response
def splash(request): LOG.info(request.__dict__) LOG.info("In splash function") LOG.info(request.user) LOG.info('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$4') if not request.user.is_authenticated(): LOG.info("User not autenticated ") raise exceptions.NotAuthenticated() user_id = api.keystone.get_user_id(request) print "USER CHECK" #LOG.info(user_info) #LOG.info('############################################') #LOG.info(user_info.two_factor_enabled) #two_factor_enabled = user_info.two_factor_enabled #two_factor_enabled = str2bool(two_factor_enabled) LOG.info('##############################################') user_details = api.keystone.user_details(request, user_id) if user_details.two_factor_enabled: two_factor_enabled = str2bool(two_factor_enabled) else: two_factor_enabled = False print user_details.two_factor_enabled print '%%%%%%%%%%%%%%%%%%%%%%%%%' print two_factor_enabled print('after tested') #Login case if two_factor_enabled: #Check whether 2factor page is shown. If else show it if not 'totp_shown' in request.session: LOG.info('totp_shown is not present in the session') #response = shortcuts.redirect('/dashboard/otp') LOG.info('redirecting to 2 factor form display page') response = shortcuts.redirect('/dashboard/twofactor') else: LOG.info('totp_shown value is present in session') if not request.session['totp_shown']: LOG.info( 'since totp_shown value is not present inside the request.session' ) LOG.info('redirecting users to twofactor form display page') response = shortcuts.redirect('/dashboard/twofactor') LOG.info('default condition to redirect the users to two factor page') response = shortcuts.redirect('/dashboard/twofactor') else: print "Redirecting users to their home page/dashboard since 2FA isn't enabled" response = shortcuts.redirect(horizon.get_user_home(request.user)) #Logout case if 'logout_reason' in request.COOKIES: response.delete_cookie('logout_reason') #Return the response corresponding to all above conditions return response
def splash(request): if not request.user.is_authenticated(): raise exceptions.NotAuthenticated() response = shortcuts.redirect(horizon.get_user_home(request.user)) if 'logout_reason' in request.COOKIES: response.delete_cookie('logout_reason') return response
def test_redirect_login_fail_to_login(self): url = settings.LOGIN_URL request = self.factory.post(url) self.get_response.return_value = request mw = middleware.HorizonMiddleware(self.get_response) resp = mw.process_exception(request, exceptions.NotAuthenticated()) resp.client = self.client self.assertRedirects(resp, settings.TESTSERVER + url)
def test_redirect_login_fail_to_login(self): url = settings.LOGIN_URL request = self.factory.post(url) mw = middleware.HorizonMiddleware() resp = mw.process_exception(request, exceptions.NotAuthenticated()) resp.client = self.client if django.VERSION >= (1, 9): self.assertRedirects(resp, settings.TESTSERVER + url) else: self.assertRedirects(resp, url)
def splash(request): if not request.user.is_authenticated(): raise exceptions.NotAuthenticated() response = shortcuts.redirect(horizon.get_user_home(request.user)) if 'logout_reason' in request.COOKIES: response.delete_cookie('logout_reason') # Display Message of the Day message from the message files # located in MESSAGES_PATH if MESSAGES_PATH: notifications.process_message_notification(request, MESSAGES_PATH) return response
def splash(request): brand = request.GET.get('brand') if brand: # store brand id and reload splash page return set_brand(shortcuts.redirect('/'), brand) if not request.user.is_authenticated(): raise exceptions.NotAuthenticated() response = shortcuts.redirect(horizon.get_user_home(request.user)) if 'logout_reason' in request.COOKIES: response.delete_cookie('logout_reason') set_brand(response, get_brand(request)) return response
def get_user_home(user): try: token = user.token except AttributeError: raise exceptions.NotAuthenticated() # Domain Admin, Project Admin will default to identity if token.project.get('id') is None or user.is_superuser: try: dashboard = horizon.get_dashboard('identity') except base.NotRegistered: pass else: dashboard = horizon.get_default_dashboard() return dashboard.get_absolute_url()
def get_user_home(user): try: token = user.token except AttributeError: raise exceptions.NotAuthenticated() # mj - we don't actually want this override # Domain Admin, Project Admin will default to identity #if token.project.get('id') is None or user.is_superuser: # try: # dashboard = horizon.get_dashboard('identity') # except base.NotRegistered: # pass #else: dashboard = horizon.get_default_dashboard() return dashboard.get_absolute_url()
def splash(request): #LOG.info("xxx enter splash!") #LOG.info("request is") #LOG.info(request) if not request.user.is_authenticated(): raise exceptions.NotAuthenticated() '''url = "sunny" context = { 'url': url, }''' '''if not request.user.is_authenticated(): return shortcuts.render(request, 'index.html', status=200)''' #LOG.info("request.user") #LOG.info(request.user) #LOG.info("horizon.get_user_home(request.user)") #LOG.info(horizon.get_user_home(request.user)) response = shortcuts.redirect(horizon.get_user_home(request.user)) #LOG.info("request.user") #LOG.info(request.user) #LOG.info("horizon.get_user_home(request.user)") #LOG.info(horizon.get_user_home(request.user)) #LOG.info("response") #LOG.info(response) #LOG.info("after response") if 'logout_reason' in request.COOKIES: response.delete_cookie('logout_reason') if 'logout_status' in request.COOKIES: response.delete_cookie('logout_status') # Display Message of the Day message from the message files # located in MESSAGES_PATH if MESSAGES_PATH: notifications.process_message_notification(request, MESSAGES_PATH) return response
def index(request): """ Function to show the TOTP page. @param : request @return : HTTP response """ LOG.info('enterrrring') # request.session['totp_invalid'] = False if not request.user.is_authenticated(): LOG.info("User not autenticated-2. Please check! ") raise exceptions.NotAuthenticated() template = loader.get_template('auth/totp.html') context = RequestContext(request, { 'totpVal': "test", }) LOG.info('returning the response-index function - totp/views.py') return HttpResponse(template.render(context))
def get_user_home(user): try: token = user.token except AttributeError: raise exceptions.NotAuthenticated() # Domain Admin, Project Admin will default to identity dashboard = None if token.project.get('id') is None or user.is_superuser: try: dashboard = horizon.get_dashboard('admin') #dashboard = horizon.get_dashboard('identity') except base.NotRegistered: pass if dashboard is None: roles = [r['name'] for r in user.roles] if settings.EXPERTCONSTANT['expert_certified_role'] in roles: dashboard = horizon.get_default_dashboard() elif settings.EXPERTCONSTANT['expert_uncertified_role'] in roles: dashboard = horizon.get_dashboard('settings') else: dashboard = horizon.get_dashboard('admin') return dashboard.get_absolute_url()
def inner(request, *args, **kwargs): need_billing = enable_billing \ and not policy.check((("identity", "cloud_admin"),), request) \ and not keystone.is_dedicated_context(request) \ and not request.user.user_domain_id == 'default' \ and not keystone.is_public_region(request) # if we enable billing if need_billing: balance = get_balance(request) if balance <= 0: LOG.error("Account Balance is less than 0") raise exceptions.NotAuthenticated( "Account Balance is less than 0") # make sure product time be earlier than resource create time create_time = datetime.datetime.utcnow()\ .strftime("%Y-%m-%d %H:%M:%S") # do request result = func(request, *args, **kwargs) # if we enable billing, create a product if need_billing: try: if 'unit' in request.DATA: kwargs['unit'] = request.DATA['unit'] if (kwargs['unit'] == 'H'): kwargs['payment_type'] = 'post_paid' elif (kwargs['unit'] == 'M'): kwargs['payment_type'] = 'pre_paid' else: kwargs['payment_type'] = 'pre_paid' elif 'metadata' in request.DATA: if 'unit' in kwargs['metadata']: kwargs['unit'] = kwargs['metadata']['unit'] if (kwargs['unit'] == 'H'): kwargs['payment_type'] = 'post_paid' elif (kwargs['unit'] == 'M'): kwargs['payment_type'] = 'pre_paid' else: kwargs['payment_type'] = 'pre_paid' else: kwargs['unit'] = 'H' kwargs['payment_type'] = 'post_paid' elif 'loadbalancer' in request.DATA: if 'unit' in request.DATA['loadbalancer']: kwargs['unit'] = request.DATA['loadbalancer'][ 'unit'] if (kwargs['unit'] == 'H'): kwargs['payment_type'] = 'post_paid' elif (kwargs['unit'] == 'M'): kwargs['payment_type'] = 'pre_paid' else: kwargs['payment_type'] = 'pre_paid' else: kwargs['unit'] = 'H' kwargs['payment_type'] = 'post_paid' else: kwargs['unit'] = 'H' kwargs['payment_type'] = 'post_paid' _create_product(request, result, create_time, *args, **kwargs) except Exception as e: LOG.error(e) # TODO(need to fix): # raise exception to Servers post() in rest/nova.py raise e return result