Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
 def process_response(self, request, response):
     if response.status_code == 406:
         account = Account()
         response = account.redirect_login(request)
     return response