-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_auth.go
40 lines (33 loc) · 853 Bytes
/
admin_auth.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
package auth
import (
"fmt"
"net/http"
"github.com/qor/admin"
"github.com/qor/qor"
"github.com/qor/roles"
"github.com/requaos/qorfun/models/users"
)
func init() {
roles.Register("admin", func(req *http.Request, currentUser interface{}) bool {
return currentUser != nil && currentUser.(*users.User).Role == "Admin"
})
}
type AdminAuth struct {
}
func (AdminAuth) LoginURL(c *admin.Context) string {
return "/auth/login"
}
func (AdminAuth) LogoutURL(c *admin.Context) string {
return "/auth/logout"
}
func (AdminAuth) GetCurrentUser(c *admin.Context) qor.CurrentUser {
currentUser := Auth.GetCurrentUser(c.Request)
if currentUser != nil {
qorCurrentUser, ok := currentUser.(qor.CurrentUser)
if !ok {
fmt.Printf("User %#v haven't implement qor.CurrentUser interface\n", currentUser)
}
return qorCurrentUser
}
return nil
}