forked from uadmin/uadmin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
session.go
53 lines (46 loc) · 931 Bytes
/
session.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
package uadmin
import (
"time"
)
// Session !
type Session struct {
Model
Key string
User User `uadmin:"filter"`
UserID uint
LoginTime time.Time
LastLogin time.Time
Active bool `uadmin:"filter"`
IP string `uadmin:"filter"`
PendingOTP bool `uadmin:"filter"`
ExpiresOn *time.Time
}
// String return string
func (s Session) String() string {
return s.Key
}
// Save !
func (s *Session) Save() {
Save(s)
}
// GenerateKey !
func (s *Session) GenerateKey() {
session := Session{}
for {
// TODO: Increase the session length to 124 and add 4 bytes for User.ID
s.Key = GenerateBase64(24)
Get(&session, "`key` = ?", s.Key)
if session.ID == 0 {
break
}
}
}
// Logout deactivates a session
func (s *Session) Logout() {
s.Active = false
Save(s)
}
// HideInDashboard to return false and auto hide this from dashboard
func (Session) HideInDashboard() bool {
return true
}