todo: userConfig

This commit is contained in:
eson 2020-01-06 02:38:55 +08:00
parent 48077eb75f
commit 6617b483cf
8 changed files with 48 additions and 9 deletions

View File

@ -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
}

View File

@ -1,3 +1,9 @@
users:
eson: xxx
admin: yame
admin: yame
paths:
- /opt/data/ocean-opm-obs
permit:
ocean-opm-obs:
- eson
- yame

View File

@ -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)
}
}

11
main.go
View File

@ -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"))
}

View File

@ -11,7 +11,7 @@ const { Option } = Select;
const App = () => (
<SiderConfig ></SiderConfig>
<SiderConfig></SiderConfig>
);

View File

@ -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(<SiderConfig></SiderConfig>, document.getElementById('root'))
console.log("Cookies are ", document.cookie)
ReactDom.render(<SiderConfig userName={user}></SiderConfig>, document.getElementById('root'))
return
});

View File

@ -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}
>
<TreeNode value="parent %#@" title="parent 112312312321312313132131313131231" key="0-1">
<TreeNode value="parent 1%#@0" title="parent 112312312321312313132131313131231-0" key="0-1-1">

View File

@ -43,12 +43,14 @@ class SiderConfig extends React.Component {
</Menu>
</Sider>
<Layout>
<Header style={{ background: '#fff', padding: 0, }}>
<Header itemType="flex" style={{ justifyContent: "flex-end", background: '#fff', padding: 0, }}>
<Row type="flex" justify="end">
<Col span={4}> <Text style={{fontSize: 16, color: "#f37b1d"}}>用户:</Text> <Text style={{fontSize: 16}}></Text> </Col>
<Col span={4}><Button type="primary" style={{ width: '100px', }}>退出</Button></Col>
<Col>
<Text style={{ alignSelf: "flex-end", fontSize: 16, color: "#f37b1d" }}>用户:</Text>
<Text style={{ fontSize: 16 }}>{this.props.userName}</Text>
<Button type="primary" style={{ margin: "0px 10px 0 20px", width: '100px', }}>退出</Button>
</Col>
</Row>
</Header >
@ -57,7 +59,7 @@ class SiderConfig extends React.Component {
<Breadcrumb.Item>User</Breadcrumb.Item>
<Breadcrumb.Item>Bill</Breadcrumb.Item>
</Breadcrumb>
<TextArea style={{ minHeight: '90vh' }}>
<TextArea style={{ minHeight: '92%' }}>
</TextArea>
</Content>