forked from phachon/mm-wiki
/
main.go
54 lines (46 loc) · 1.38 KB
/
main.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
package controllers
import (
"fmt"
"mm-wiki/app/models"
)
type MainController struct {
BaseController
}
func (this *MainController) Index() {
var err error
var menus = []map[string]string{}
var controllers = []map[string]string{}
user, err := models.UserModel.GetUserByUserId(this.UserId)
if err != nil {
this.ViewError("查找用户失败!")
}
if len(user) == 0 {
this.ViewError("用户不存在!")
}
roleId := user["role_id"]
if roleId == fmt.Sprintf("%d", models.Role_Root_Id) {
menus, controllers, err = models.PrivilegeModel.GetTypePrivilegesByDisplay(models.Privilege_DisPlay_True)
if err != nil {
this.ViewError("查找用户权限失败!")
}
} else {
rolePrivileges, err := models.RolePrivilegeModel.GetRolePrivilegesByRoleId(roleId)
if err != nil {
this.ViewError("查找用户权限出错")
}
var privilegeIds = []string{}
for _, rolePrivilege := range rolePrivileges {
privilegeIds = append(privilegeIds, rolePrivilege["privilege_id"])
}
menus, controllers, err = models.PrivilegeModel.GetTypePrivilegesByDisplayPrivilegeIds(models.Privilege_DisPlay_True, privilegeIds)
if err != nil {
this.ViewError("查找用户权限失败!")
}
}
this.Data["menus"] = menus
this.Data["controllers"] = controllers
this.viewLayout("main/index", "main")
}
func (this *MainController) Default() {
this.viewLayout("main/default", "default")
}