Browse Source

minor: 通过后端配置,控制sso登录开关

tuon 1 year ago
parent
commit
ae71167534
4 changed files with 43 additions and 34 deletions
  1. 1 0
      .eslintrc.cjs
  2. 3 2
      public/config.js
  3. 33 29
      server/controllers/config.go
  4. 6 3
      src/pages/login/index.tsx

+ 1 - 0
.eslintrc.cjs

@@ -10,5 +10,6 @@ module.exports = {
   plugins: ['react-refresh'],
   rules: {
     'react-refresh/only-export-components': 'warn',
+      '@typescript-eslint/ban-ts-comment':"warn"
   },
 }

+ 3 - 2
public/config.js

@@ -1,4 +1,5 @@
 // config.js
 window.CONFIG = {
-    baseApi: '/api/nginx-ui/api'
-}
+    baseApi: '/api/nginx-ui/api',
+    SSO: true
+}

+ 33 - 29
server/controllers/config.go

@@ -1,29 +1,33 @@
-package controllers
-
-import (
-	"fmt"
-	"github.com/astaxie/beego/logs"
-	config2 "server/config"
-)
-
-type ConfigController struct {
-	BaseController
-}
-
-// Get 前端的配置文件
-func (c *ConfigController) Get() {
-
-	config := config2.Config
-
-	js := fmt.Sprintf("  window.CONFIG = {\n        baseApi: '%s'\n    }", config.BaseApi)
-	output := c.Ctx.Output
-
-	output.SetStatus(200)
-	output.Header("Cache-Control", "no-cache")
-	output.Header("content-type", "text/javascript")
-	err := c.Ctx.Output.Body([]byte(js))
-	if err != nil {
-		logs.Error("config.js fail", err)
-		return
-	}
-}
+package controllers
+
+import (
+	"fmt"
+	"github.com/astaxie/beego/logs"
+	config2 "server/config"
+)
+
+type ConfigController struct {
+	BaseController
+}
+
+// Get 前端的配置文件
+func (c *ConfigController) Get() {
+
+	config := config2.Config
+	oauth2Config := config2.OauthConfig
+	var sso = "false"
+	if oauth2Config.Enable {
+		sso = "true"
+	}
+	js := fmt.Sprintf("  window.CONFIG = {\n        baseApi: '%s',\n SSO: %s   }", config.BaseApi, sso)
+	output := c.Ctx.Output
+
+	output.SetStatus(200)
+	output.Header("Cache-Control", "no-cache")
+	output.Header("content-type", "text/javascript")
+	err := c.Ctx.Output.Body([]byte(js))
+	if err != nil {
+		logs.Error("config.js fail", err)
+		return
+	}
+}

+ 6 - 3
src/pages/login/index.tsx

@@ -97,12 +97,15 @@ export const LoginPage = ()=>{
             key: 'account',
             children: <AccountPanel />
         },
-        {
+    ]
+    // @ts-ignore
+    if (window.CONFIG.SSO){
+        tabItems.push({
             label: "SSO",
             key: 'sso',
             children: <Spin />
-        }
-    ]
+        })
+    }
 
     return (<div className="login-page">
         <div className="login-container">