Esempio n. 1
0
    def get(self, request, *args, **kwargs):
        """
        登录页面获取云帮Logo、标题、github、gitlab配置信息(不要Authorization头)
        ---
        """
        try:
            # 判断是否已经初始化权限默认数据,没有则初始化
            status = role_perm_repo.initialize_permission_settings()
            code = 200
            data = dict()
            logo = config_service.get_image()
            host_name = request.get_host()
            build_absolute_uri = request.build_absolute_uri()
            scheme = "http"
            if build_absolute_uri.startswith("https"):
                scheme = "https"
            data["logo"] = "{0}".format(str(logo))
            # 判断是否为公有云
            if settings.MODULES.get('SSO_LOGIN'):
                data["url"] = "https://sso.goodrain.com/#/login/"
                data["is_public"] = True
            else:
                data["url"] = "{0}://{1}/index#/user/login".format(scheme, request.get_host())
                data["is_public"] = False

            title = config_service.get_config_by_key("TITLE")
            if not title:
                config = config_service.add_config("TITLE", "好雨云帮", "string", "云帮title")
                title = config.value
            data["title"] = title
            if settings.MODULES.get('SSO_LOGIN'):
                data["is_user_register"] = True
            else:
                users = user_repo.get_all_users()
                if users:
                    data["is_user_register"] = True
                else:
                    data["is_user_register"] = False

            github_config = config_service.get_github_config()
            data["github_config"] = github_config

            gitlab_config = config_service.get_gitlab_config()
            data["gitlab_config"] = gitlab_config


            result = general_message(code, "query success", "Logo获取成功", bean=data, initialize_info=status)
            return Response(result, status=code)
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result)
Esempio n. 2
0
 def get(self, request, *args, **kwargs):
     """
     获取云帮Logo
     ---
     """
     try:
         code = 200
         data = dict()
         logo = config_service.get_image()
         host_name = request.get_host()
         data["logo"] = str(host_name) + str(logo)
         result = general_message(code, "query success", "Logo获取成功", bean=data)
         return Response(result, status=code)
     except Exception as e:
         logger.exception(e)
         result = error_message(e.message)
     return Response(result)
Esempio n. 3
0
 def get(self, request, *args, **kwargs):
     """
     查询logo
     ---
     """
     try:
         logo = config_service.get_image()
         bean = {}
         host_name = request.get_host()
         bean["logo"] = str(host_name) + str(logo)
         code = "0000"
         msg = "success"
         msg_show = "查询成功"
         result = generate_result(code, msg, msg_show, bean)
     except Exception as e:
         result = generate_error_result()
         logger.exception(e)
     return Response(result)
Esempio n. 4
0
    def get(self, request, *args, **kwargs):
        """
        登录页面获取云帮Logo、标题、github、gitlab配置信息(不要Authorization头)
        ---
        """
        try:
            # 判断是否已经初始化权限默认数据,没有则初始化
            status = role_perm_repo.initialize_permission_settings()
            code = 200
            data = dict()
            logo = config_service.get_image()
            build_absolute_uri = request.build_absolute_uri()
            scheme = "http"

            if build_absolute_uri.startswith("https"):
                scheme = "https"
            data["logo"] = "{0}".format(str(logo))
            # 判断是否为公有云
            if settings.MODULES.get('SSO_LOGIN'):
                data["url"] = os.getenv(
                    "SSO_BASE_URL", "https://sso.goodrain.com") + "/#/login/"
                data["is_public"] = True
            else:
                data["url"] = "{0}://{1}/index#/user/login".format(
                    scheme, request.get_host())
                data["is_public"] = False

            title = config_service.get_config_by_key("TITLE")
            if not title:
                config = config_service.add_config("TITLE", "好雨云帮", "string",
                                                   "云帮title")
                title = config.value
            data["title"] = title
            if settings.MODULES.get('SSO_LOGIN'):
                data["is_user_register"] = True
            else:
                users = user_repo.get_all_users()
                if users:
                    data["is_user_register"] = True
                else:
                    data["is_user_register"] = False

            is_regist = config_service.get_config_by_key("REGISTER_STATUS")
            if not is_regist:
                is_regist = config_service.add_config(
                    key="REGISTER_STATUS",
                    default_value="yes",
                    type="string",
                    desc="开启/关闭注册").value
            if is_regist == "yes":
                data["is_regist"] = True
            else:
                data["is_regist"] = False
            # if register_config[0].value != "yes":
            #     data["is_regist"] = False
            # else:
            #     data["is_regist"] = True

            github_config = config_service.get_github_config()
            data["github_config"] = github_config

            gitlab_config = config_service.get_gitlab_config()
            data["gitlab_config"] = gitlab_config

            data["eid"] = None
            enterprise = enterprise_repo.get_enterprise_first()
            if enterprise:
                data["eid"] = enterprise.enterprise_id
                data["enterprise_name"] = enterprise.enterprise_alias
            data["version"] = os.getenv("RELEASE_DESC", "public-cloud")
            result = general_message(
                code,
                "query success",
                "Logo获取成功",
                bean=data,
                initialize_info=status)
            return Response(result, status=code)
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result)