forked from getevo/evo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evo.user.go
92 lines (72 loc) · 1.72 KB
/
evo.user.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
package evo
import "github.com/getevo/evo/v2/lib/generic"
func (r *Request) User() UserInterface {
if r.UserInterface == nil {
var user = (UserInterfaceInstance).FromRequest(r)
if user == nil {
user = DefaultUserInterface{}
}
r.UserInterface = &user
}
return *r.UserInterface
}
type DefaultUserInterface struct{}
type Attributes map[string]any
func (d DefaultUserInterface) Attributes() Attributes {
return Attributes{}
}
var UserInterfaceInstance UserInterface = DefaultUserInterface{}
func SetUserInterface(v UserInterface) {
UserInterfaceInstance = v
}
type UserInterface interface {
GetFirstName() string
GetLastName() string
GetFullName() string
GetEmail() string
UUID() string
ID() uint64
Anonymous() bool
HasPermission(permission string) bool
Attributes() Attributes
Interface() interface{}
FromRequest(request *Request) UserInterface
}
func (d DefaultUserInterface) HasPermission(permission string) bool {
return true
}
func (d DefaultUserInterface) GetFirstName() string {
return ""
}
func (d DefaultUserInterface) GetLastName() string {
return ""
}
func (d DefaultUserInterface) GetFullName() string {
return ""
}
func (d DefaultUserInterface) GetEmail() string {
return ""
}
func (d DefaultUserInterface) UUID() string {
return ""
}
func (d DefaultUserInterface) ID() uint64 {
return 0
}
func (d DefaultUserInterface) Anonymous() bool {
return true
}
func (d DefaultUserInterface) Interface() interface{} {
return d
}
func (d DefaultUserInterface) FromRequest(request *Request) UserInterface {
return DefaultUserInterface{}
}
func (a Attributes) Has(key string) bool {
_, ok := a[key]
return ok
}
func (a Attributes) Get(key string) generic.Value {
v, _ := a[key]
return generic.Parse(v)
}