This repository has been archived by the owner on Jul 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
models.go
104 lines (94 loc) · 2.02 KB
/
models.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
93
94
95
96
97
98
99
100
101
102
103
104
package hero
import "time"
// User is hero user object.
type User struct {
ID int64
UserName string
Email string
Avatar string
Profile Profile
ProfileID int64
Grants []Grant
Tokens []Token
Clients []Client
Password string
CreatedAt time.Time
UpdatedAt time.Time
}
// Profile is user's profile information
type Profile struct {
ID int64
FirstName string
LastName string
UserName string
Email string
AvatarURL string
CreatedAt time.Time
UpdatedAt time.Time
}
// Token is a hero token object.
type Token struct {
ID int64
Code string
ClientID int64
UserID int64
ExpiresIn int64
CreatedAT time.Time
UpdatedAt time.Time
}
// Client is a hero client object.
type Client struct {
ID int64
UUID string
UserID int64
Name string
Secret string
Grants []Grant
Tokens []Token
RedirectURL string
CreatedAt time.Time
UpdatedAt time.Time
}
// Session stores session data from gorilla/sessions
type Session struct {
ID int64
Key string
Data string `sql:"type:text"`
ExpiresOn time.Time
CreatedAt time.Time
UpdatedAt time.Time
}
// Grant is a hero grant object.
type Grant struct {
ID int64
Code string
Type string
UserID int64
ClientID int64
AccessToken Token
AccessTokenID int64
AuthorizeToken Token
AuthorizeTokenID int64
RefreshToken Token
RefreshTokenID int64
Scope string
State string
RedirectURL string
ExpiresIn int64
CreatedAt time.Time
UpdatedAt time.Time
}
// IsExpired returns true if the grant is expired.
func (g *Grant) IsExpired() bool {
return g.CreatedAt.Add(time.Duration(g.ExpiresIn) * time.Second).Before(time.Now())
}
// TokenGenerator is an interface for generating new tokens.
type TokenGenerator interface {
Generate() string
}
func newToken(code string) Token {
return Token{Code: code}
}
func newGrant(code string) Grant {
return Grant{Code: code}
}