From 6617b483cfce2d5e6843768d0510ab93399aa8dc Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Mon, 6 Jan 2020 02:38:55 +0800 Subject: [PATCH] todo: userConfig --- config.go | 4 +++- config.yaml | 8 +++++++- config_test.go | 8 ++++++++ main.go | 11 +++++++++++ web/src/App.js | 2 +- web/src/login.js | 3 ++- web/src/namespaceSelect.js | 9 +++++++++ web/src/siderConfig.js | 12 +++++++----- 8 files changed, 48 insertions(+), 9 deletions(-) diff --git a/config.go b/config.go index 1fc471d..877a146 100644 --- a/config.go +++ b/config.go @@ -22,7 +22,9 @@ var GlobalConfig *Config = loadConfig() // Config 配置结构 type Config struct { // Users 账号密码集 - Users map[string]string `yaml:"users"` + Users map[string]string `yaml:"users"` + Paths []string `yaml:"paths"` + Permit map[string][]string `yaml:"permit"` configLock *sync.Mutex } diff --git a/config.yaml b/config.yaml index 43901c3..71c6856 100644 --- a/config.yaml +++ b/config.yaml @@ -1,3 +1,9 @@ users: eson: xxx - admin: yame \ No newline at end of file + admin: yame +paths: + - /opt/data/ocean-opm-obs +permit: + ocean-opm-obs: + - eson + - yame \ No newline at end of file diff --git a/config_test.go b/config_test.go index 628d295..abe1589 100644 --- a/config_test.go +++ b/config_test.go @@ -13,4 +13,12 @@ func TestLoadConifg(t *testing.T) { t.Error(value) } } + + if len(config.Paths) < 1 { + t.Error(config) + } + + if len(config.Permit) < 1 { + t.Error(config.Permit) + } } diff --git a/main.go b/main.go index a7dead7..a63089d 100644 --- a/main.go +++ b/main.go @@ -50,6 +50,16 @@ func login(ctx *gin.Context) { } +func userConfig(ctx *gin.Context) { + ctx.Request.ParseForm() + session := sessions.Default(ctx) + if session.Get(SessionUser) == nil { + ctx.JSON(http.StatusUnauthorized, gin.H{"error": "权限错误"}) + return + } + ctx.JSON(http.StatusOK, gin.H{"message": "获取配置成功"}) +} + func main() { eg := gin.New() @@ -58,5 +68,6 @@ func main() { eg.Use(auth) eg.POST("/api/login", login) + eg.POST("/api/user/config", userConfig) log.Fatal(eg.Run(":3001")) } diff --git a/web/src/App.js b/web/src/App.js index 090d758..b7a9461 100755 --- a/web/src/App.js +++ b/web/src/App.js @@ -11,7 +11,7 @@ const { Option } = Select; const App = () => ( - + ); diff --git a/web/src/login.js b/web/src/login.js index 7121112..9080aa0 100644 --- a/web/src/login.js +++ b/web/src/login.js @@ -19,7 +19,8 @@ class Login extends React.Component { form.append("pwd", pwd); axios.post("/api/login", form).then(value => { console.log(value); - ReactDom.render(, document.getElementById('root')) + console.log("Cookies are ", document.cookie) + ReactDom.render(, document.getElementById('root')) return }); diff --git a/web/src/namespaceSelect.js b/web/src/namespaceSelect.js index 36668b6..0117154 100644 --- a/web/src/namespaceSelect.js +++ b/web/src/namespaceSelect.js @@ -1,6 +1,7 @@ import React from 'react'; import { TreeSelect } from 'antd'; +import axios from 'axios'; const { TreeNode } = TreeSelect; @@ -17,6 +18,13 @@ class NamespaceSelect extends React.Component { }; + onDropdownVisibleChange = (open) => { + if(open) { + var resp = axios.post("/api/user/config") + console.log(resp) + + } + } render() { @@ -31,6 +39,7 @@ class NamespaceSelect extends React.Component { multiple={false} treeDefaultExpandAll onChange={this.onChange} + onDropdownVisibleChange={this.onDropdownVisibleChange} > diff --git a/web/src/siderConfig.js b/web/src/siderConfig.js index 6e53f1b..5d5c76b 100644 --- a/web/src/siderConfig.js +++ b/web/src/siderConfig.js @@ -43,12 +43,14 @@ class SiderConfig extends React.Component { -
+
- - 用户: 黄思敏 - + + 用户: + {this.props.userName} + +
@@ -57,7 +59,7 @@ class SiderConfig extends React.Component { User Bill -