-
Notifications
You must be signed in to change notification settings - Fork 0
/
admincheck.go
43 lines (36 loc) · 1.01 KB
/
admincheck.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
package admincheck
import (
"github.com/deatil/lakego-doak/lakego/router"
"github.com/deatil/lakego-doak-admin/admin/auth/admin"
"github.com/deatil/lakego-doak-admin/admin/support/response"
"github.com/deatil/lakego-doak-admin/admin/support/http/code"
)
/**
* 超级管理员检测
*
* @create 2021-9-30
* @author deatil
*/
func Handler() router.HandlerFunc {
return func(ctx *router.Context) {
isSuperAdministrator := checkSuperAdmin(ctx)
if !isSuperAdministrator {
response.Error(ctx, "你没有权限进行该操作", code.AuthError)
} else {
ctx.Next()
}
}
}
// 超级管理员检测
func checkSuperAdmin(ctx *router.Context) bool {
adminInfo, _ := ctx.Get("admin")
if adminInfo == nil {
response.Error(ctx, "你没有访问权限", code.AuthError)
return false
}
isSuperAdministrator := adminInfo.(*admin.Admin).IsSuperAdministrator()
if isSuperAdministrator {
return true
}
return false
}