forked from TencentBlueKing/bk-cmdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
95 lines (79 loc) · 2.58 KB
/
user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Tencent is pleased to support the open source community by making 蓝鲸 available.
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package controllers
import (
"fmt"
"github.com/gin-gonic/contrib/sessions"
"github.com/gin-gonic/gin"
"configcenter/src/common"
"configcenter/src/common/blog"
"configcenter/src/common/core/cc/api"
"configcenter/src/common/core/cc/wactions"
"configcenter/src/web_server/application/middleware/user"
)
const BkAccountUrl = "site.bk_account_url"
func init() {
wactions.RegisterNewAction(wactions.Action{common.HTTPSelectGet, "/user/list", nil, GetUserList})
wactions.RegisterNewAction(wactions.Action{common.HTTPUpdate, "/user/language/:language", nil, UpdateUserLanguage})
}
type userResult struct {
Message string `json:"message"`
Data interface{} `json:"data"`
Code string `json:"code"`
Result bool `json:"result"`
}
type userDataResult struct {
Message string `json:"bk_error_msg"`
Data interface{} `json:"data"`
Code string `json:"bk_error_code"`
Result bool `json:"result"`
}
var getUserFailData = userDataResult{
Result: false,
Message: "get user list false",
Code: "",
Data: nil,
}
// GetUserList get user list
func GetUserList(c *gin.Context) {
a := api.NewAPIResource()
config, _ := a.ParseConfig()
accountURL := config[BkAccountUrl]
user := user.NewUser()
code, data := user.GetUserList(c, accountURL)
c.JSON(code, data)
return
}
func UpdateUserLanguage(c *gin.Context) {
session := sessions.Default(c)
language := c.Param("language")
session.Set("language", language)
err := session.Save()
if nil != err {
blog.Errorf("user update language error:%s", err.Error())
c.JSON(200, userDataResult{
Result: false,
Message: "user update language error",
Code: fmt.Sprintf("%d", common.CCErrCommHTTPDoRequestFailed),
Data: nil,
})
return
}
c.SetCookie("blueking_language", language, 0, "/", "", false, true)
c.JSON(200, userDataResult{
Result: true,
Message: "",
Code: "00",
Data: nil,
})
return
}