forked from GoAdminGroup/go-admin
/
menu_new.go
65 lines (53 loc) · 1.41 KB
/
menu_new.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
package guard
import (
"html/template"
"strconv"
"github.com/kotovmak/go-admin/context"
"github.com/kotovmak/go-admin/modules/auth"
"github.com/kotovmak/go-admin/modules/errors"
"github.com/kotovmak/go-admin/plugins/admin/modules/form"
)
type MenuNewParam struct {
Title string
Header string
ParentId int64
Icon string
PluginName string
Uri string
Roles []string
Alert template.HTML
}
func (e MenuNewParam) HasAlert() bool {
return e.Alert != template.HTML("")
}
func (g *Guard) MenuNew(ctx *context.Context) {
parentId := ctx.FormValue("parent_id")
if parentId == "" {
parentId = "0"
}
var (
alert template.HTML
token = ctx.FormValue(form.TokenKey)
)
if !auth.GetTokenService(g.services.Get(auth.TokenServiceKey)).CheckToken(token) {
alert = getAlert(errors.EditFailWrongToken)
}
if alert == "" {
alert = checkEmpty(ctx, "title", "icon")
}
parentIdInt, _ := strconv.Atoi(parentId)
ctx.SetUserValue(newMenuParamKey, &MenuNewParam{
Title: ctx.FormValue("title"),
Header: ctx.FormValue("header"),
PluginName: ctx.FormValue("plugin_name"),
ParentId: int64(parentIdInt),
Icon: ctx.FormValue("icon"),
Uri: ctx.FormValue("uri"),
Roles: ctx.Request.Form["roles[]"],
Alert: alert,
})
ctx.Next()
}
func GetMenuNewParam(ctx *context.Context) *MenuNewParam {
return ctx.UserValue[newMenuParamKey].(*MenuNewParam)
}