todo: userConfig
This commit is contained in:
parent
48077eb75f
commit
6617b483cf
@ -22,7 +22,9 @@ var GlobalConfig *Config = loadConfig()
|
|||||||
// Config 配置结构
|
// Config 配置结构
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// Users 账号密码集
|
// 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
|
configLock *sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
users:
|
users:
|
||||||
eson: xxx
|
eson: xxx
|
||||||
admin: yame
|
admin: yame
|
||||||
|
paths:
|
||||||
|
- /opt/data/ocean-opm-obs
|
||||||
|
permit:
|
||||||
|
ocean-opm-obs:
|
||||||
|
- eson
|
||||||
|
- yame
|
@ -13,4 +13,12 @@ func TestLoadConifg(t *testing.T) {
|
|||||||
t.Error(value)
|
t.Error(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(config.Paths) < 1 {
|
||||||
|
t.Error(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(config.Permit) < 1 {
|
||||||
|
t.Error(config.Permit)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
11
main.go
11
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() {
|
func main() {
|
||||||
|
|
||||||
eg := gin.New()
|
eg := gin.New()
|
||||||
@ -58,5 +68,6 @@ func main() {
|
|||||||
eg.Use(auth)
|
eg.Use(auth)
|
||||||
|
|
||||||
eg.POST("/api/login", login)
|
eg.POST("/api/login", login)
|
||||||
|
eg.POST("/api/user/config", userConfig)
|
||||||
log.Fatal(eg.Run(":3001"))
|
log.Fatal(eg.Run(":3001"))
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ const { Option } = Select;
|
|||||||
|
|
||||||
const App = () => (
|
const App = () => (
|
||||||
|
|
||||||
<SiderConfig ></SiderConfig>
|
<SiderConfig></SiderConfig>
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -19,7 +19,8 @@ class Login extends React.Component {
|
|||||||
form.append("pwd", pwd);
|
form.append("pwd", pwd);
|
||||||
axios.post("/api/login", form).then(value => {
|
axios.post("/api/login", form).then(value => {
|
||||||
console.log(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
|
return
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { TreeSelect } from 'antd';
|
import { TreeSelect } from 'antd';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
const { TreeNode } = TreeSelect;
|
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() {
|
render() {
|
||||||
@ -31,6 +39,7 @@ class NamespaceSelect extends React.Component {
|
|||||||
multiple={false}
|
multiple={false}
|
||||||
treeDefaultExpandAll
|
treeDefaultExpandAll
|
||||||
onChange={this.onChange}
|
onChange={this.onChange}
|
||||||
|
onDropdownVisibleChange={this.onDropdownVisibleChange}
|
||||||
>
|
>
|
||||||
<TreeNode value="parent %#@" title="parent 112312312321312313132131313131231" key="0-1">
|
<TreeNode value="parent %#@" title="parent 112312312321312313132131313131231" key="0-1">
|
||||||
<TreeNode value="parent 1%#@0" title="parent 112312312321312313132131313131231-0" key="0-1-1">
|
<TreeNode value="parent 1%#@0" title="parent 112312312321312313132131313131231-0" key="0-1-1">
|
||||||
|
@ -43,12 +43,14 @@ class SiderConfig extends React.Component {
|
|||||||
</Menu>
|
</Menu>
|
||||||
</Sider>
|
</Sider>
|
||||||
<Layout>
|
<Layout>
|
||||||
<Header style={{ background: '#fff', padding: 0, }}>
|
<Header itemType="flex" style={{ justifyContent: "flex-end", background: '#fff', padding: 0, }}>
|
||||||
|
|
||||||
<Row type="flex" justify="end">
|
<Row type="flex" justify="end">
|
||||||
|
<Col>
|
||||||
<Col span={4}> <Text style={{fontSize: 16, color: "#f37b1d"}}>用户:</Text> <Text style={{fontSize: 16}}>黄思敏</Text> </Col>
|
<Text style={{ alignSelf: "flex-end", fontSize: 16, color: "#f37b1d" }}>用户:</Text>
|
||||||
<Col span={4}><Button type="primary" style={{ width: '100px', }}>退出</Button></Col>
|
<Text style={{ fontSize: 16 }}>{this.props.userName}</Text>
|
||||||
|
<Button type="primary" style={{ margin: "0px 10px 0 20px", width: '100px', }}>退出</Button>
|
||||||
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
</Header >
|
</Header >
|
||||||
@ -57,7 +59,7 @@ class SiderConfig extends React.Component {
|
|||||||
<Breadcrumb.Item>User</Breadcrumb.Item>
|
<Breadcrumb.Item>User</Breadcrumb.Item>
|
||||||
<Breadcrumb.Item>Bill</Breadcrumb.Item>
|
<Breadcrumb.Item>Bill</Breadcrumb.Item>
|
||||||
</Breadcrumb>
|
</Breadcrumb>
|
||||||
<TextArea style={{ minHeight: '90vh' }}>
|
<TextArea style={{ minHeight: '92%' }}>
|
||||||
|
|
||||||
</TextArea>
|
</TextArea>
|
||||||
</Content>
|
</Content>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user