/
mainMenuController.go
135 lines (123 loc) · 3.36 KB
/
mainMenuController.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package controllers
import (
"github.com/astaxie/beego/context"
"github.com/hzwy23/hauth/core/groupcache"
"github.com/hzwy23/hauth/core/models"
"github.com/hzwy23/hauth/utils/crypto/sha1"
"github.com/hzwy23/hauth/utils/hret"
"github.com/hzwy23/hauth/utils/i18n"
"github.com/hzwy23/hauth/utils/jwt"
"github.com/hzwy23/hauth/utils/logs"
)
var homePageMenusModel = new(models.HomePageMenusModel)
// swagger:operation GET /v1/auth/index/entry StaticFiles SubSystemEntry
//
// According to the ID number, return subsystem information page
//
// The system will check user permissions.
// So,you must first login system,and then you can send the request.
//
// ---
// produces:
// - application/json
// - application/xml
// - text/xml
// - text/html
// parameters:
// - name: Id
// in: query
// description: subsystem id number.
// required: true
// type: string
// format:
// responses:
// '200':
// description: success
// '403':
// description: disconnect, please login.
// '404':
// description: page not found
func SubSystemEntry(ctx *context.Context) {
defer hret.HttpPanic()
ctx.Request.ParseForm()
id := ctx.Request.FormValue("Id")
// get user connection information from cookie.
cookie, _ := ctx.Request.Cookie("Authorization")
jclaim, err := jwt.ParseJwt(cookie.Value)
if err != nil {
logs.Error(err)
hret.Error(ctx.ResponseWriter, 403, i18n.Disconnect(ctx.Request))
return
}
// get url of the id number.
url, err := homePageMenusModel.GetUrl(jclaim.UserId, id)
if err != nil {
logs.Error(err)
ctx.WriteString(url)
return
}
key := sha1.GenSha1Key(id, jclaim.UserId, url)
if !groupcache.FileIsExist(key) {
groupcache.RegisterStaticFile(key, url)
}
tpl, err := groupcache.GetStaticFile(key)
if err != nil {
logs.Error(err)
hret.Error(ctx.ResponseWriter, 404, i18n.PageNotFound(ctx.Request))
return
}
ctx.ResponseWriter.Write(tpl)
}
// swagger:operation GET /v1/auth/main/menu HomePageMenus HomePageMenus
//
// If the request is successful, will return the user to be able to access the menu information
//
// The system will check user permissions.
// So,you must first login system,and then you can send the request.
//
// ---
// produces:
// - application/json
// - application/xml
// - text/xml
// - text/html
// parameters:
// - name: TypeId
// in: query
// description: The menu type, 1 means home page ,2 means subsystem page
// required: true
// type: string
// format:
// - name: Id
// in: query
// description: This up menu id , the response will return the lower menu information of the up menu id
// required: true
// type: string
// format:
// responses:
// '200':
// description: success
// '403':
// description: disconnect
// '421':
// description: get menu information failed.
func HomePageMenus(ctx *context.Context) {
defer hret.HttpPanic()
typeId := ctx.Request.FormValue("TypeId")
Id := ctx.Request.FormValue("Id")
// get user connection information from cookie
cookie, _ := ctx.Request.Cookie("Authorization")
claim, err := jwt.ParseJwt(cookie.Value)
if err != nil {
logs.Error(err)
hret.Error(ctx.ResponseWriter, 403, i18n.Disconnect(ctx.Request))
return
}
ojs, err := homePageMenusModel.Get(Id, typeId, claim.UserId)
if err != nil {
logs.Error(err)
hret.Error(ctx.ResponseWriter, 421, i18n.Get(ctx.Request, "error_query_menu"))
return
}
ctx.ResponseWriter.Write(ojs)
}