def authenticate(self, request): account = Account() login_status, user = account.is_bk_token_valid(request) if not login_status: return None return user
def process_view(self, request, view, args, kwargs): """process_view.""" if RUN_MODE == "DEVELOP": request.user.username = "******" request.user.is_superuser = True return None if getattr(view, 'login_exempt', False): return None # 对[公众号]weixin 路径不需要蓝鲸登录 use_weixin = getattr(settings, "USE_WEIXIN", None) weixin_path_prefix = getattr(settings, "WEIXIN_SITE_URL", None) weixin_app_external_host = getattr(settings, "WEIXIN_APP_EXTERNAL_HOST", None) if (use_weixin and weixin_path_prefix and weixin_app_external_host and request.path.startswith(weixin_path_prefix) and request.get_host() == weixin_app_external_host): return None # 对于微信小程序的路径不需要蓝鲸登录 use_miniweixin = getattr(settings, "USE_MINIWEIXIN", None) miniweixin_path_prefix = getattr(settings, "MINIWEIXIN_SITE_URL", None) miniweixin_app_external_host = getattr(settings, "MINIWEIXIN_APP_EXTERNAL_HOST", None) if (use_miniweixin and miniweixin_path_prefix and miniweixin_app_external_host and request.path.startswith(miniweixin_path_prefix) and request.get_host() == miniweixin_app_external_host): return None user = authenticate(request=request) if user: request.user = user get_csrf_token(request) return None account = Account() return account.redirect_login(request)
def process_view(self, request, view, args, kwargs): """process_view.""" if getattr(view, 'login_exempt', False): return None user = authenticate(request=request) if user: request.user = user get_csrf_token(request) return None print 'ssssssssssssssssssssss' account = Account() return account.redirect_login(request)
def process_view(self, request, view, args, kwargs): """process_view.""" if getattr(view, 'login_exempt', False): return None user = authenticate(request=request) if user: request.user = user return None account = Account() return account.redirect_login(request)
def process_view(self, request, view, args, kwargs): """process_view.""" if getattr(view, 'login_exempt', False): return None username = request.user.username user = authenticate(request=request) if user: request.user = user if request.user.username != username: auth_login(request, user) return None account = Account() return account.redirect_login(request)
def process_view(self, request, view, args, kwargs): """process_view.""" if RUN_MODE == 'DEVELOP': request.user.username = '******' return None if getattr(view, 'login_exempt', False): return None user = authenticate(request=request) if user: request.user = user get_csrf_token(request) return None account = Account() return account.redirect_login(request)
def process_view(self, request, view, args, kwargs): """process_view.""" # 模拟登录账号 username = '******' user_model = get_user_model() if user_model.objects.filter(username=username).exists(): user = user_model.objects.get(username=username) else: user = user_model.objects.create(username=username, chname=username, is_staff=False, is_superuser=False, is_in_app=True) request.user = user return None if getattr(view, 'login_exempt', False): return None # 对[公众号]weixin 路径不需要蓝鲸登录 use_weixin = getattr(settings, "USE_WEIXIN", None) weixin_path_prefix = getattr(settings, "WEIXIN_SITE_URL", None) weixin_app_external_host = getattr(settings, "WEIXIN_APP_EXTERNAL_HOST", None) if (use_weixin and weixin_path_prefix and weixin_app_external_host and request.path.startswith(weixin_path_prefix) and request.get_host() == weixin_app_external_host): return None # 对于微信小程序的路径不需要蓝鲸登录 use_miniweixin = getattr(settings, "USE_MINIWEIXIN", None) miniweixin_path_prefix = getattr(settings, "MINIWEIXIN_SITE_URL", None) miniweixin_app_external_host = getattr(settings, "MINIWEIXIN_APP_EXTERNAL_HOST", None) if (use_miniweixin and miniweixin_path_prefix and miniweixin_app_external_host and request.path.startswith(miniweixin_path_prefix) and request.get_host() == miniweixin_app_external_host): return None user = authenticate(request=request) if user: request.user = user get_csrf_token(request) return None account = Account() return account.redirect_login(request)
def process_view(self, request, view, args, kwargs): """process_view.""" # if DEBUG: # request.user.chname = "admin" # request.user.username = "******" # request.user.is_super_user = False # return None if getattr(view, 'login_exempt', False): return None user = authenticate(request=request) if user: request.user = user get_csrf_token(request) return None account = Account() return account.redirect_login(request)
def process_request(self, request): account = Account() # 通过登录态获取用户名 username = account.is_bk_token_valid(request)[1] # 获取登录主页后生成的 session is_login = request.session.get('logined',None) # 如果session & username不存在则直接去请求权限app if is_login is None and username is not None: url = settings.BK_PAAS_HOST + "/o/bkpermission/" + "return_result_b/?app_code=" + settings.APP_ID + "&username="******"/o/bkpermission" + '/return_forbidden/' + "?username=" + str(username) print url res = json.loads(requests.get(url=url).content) if not res['result']: ''' @note: 重定向到403页面 ''' return HttpResponseRedirect(redirect_url)
def get(self, request, *args, **kwargs): """ 磁盘信息 :param request: :param args: :param kwargs: :return: """ account = Account() username = account.get_username(request) if username == 'admin': result = True else: result = False diskdata = DiskInfo.objects.all().values() diskdata = list(diskdata) ostype = [ {'id': 1, 'text': 'liunx'}, {'id': 2, 'text': 'windows'} ] return render_mako_context(request, 'iwork/diskinfo.html',{'result':result, 'diskdata':json.dumps(diskdata), 'ostype': ostype})
def process_response(self, request, response): if response.status_code == 406: account = Account() response = account.redirect_login(request) return response
def authenticate(self, request): account = Account() login_status, user = account.is_bk_token_valid(request) if not login_status: return None return user
def check_failed(request): """权限验证错误页面""" account = Account() return account.check_failed(request)
def logout(request): account = Account() return account.logout(request)