44 lines
852 B
Go
44 lines
852 B
Go
package auth
|
|
|
|
import "time"
|
|
|
|
type Session struct {
|
|
Token string
|
|
UserId int64
|
|
Device string
|
|
Address string
|
|
CreatedAt time.Time
|
|
ExpiresAt time.Time
|
|
}
|
|
|
|
type Invite struct {
|
|
Token string
|
|
Uses int64
|
|
CreatedAt time.Time
|
|
ExpiresAt time.Time
|
|
}
|
|
|
|
func (s *Session) CreatedAtLocal() string {
|
|
return s.CreatedAt.Local().Format("2006-01-02 15:04")
|
|
}
|
|
|
|
func (s *Session) ExpiresAtLocal() string {
|
|
return s.ExpiresAt.Local().Format("2006-01-02 15:04")
|
|
}
|
|
|
|
func (i *Invite) CreatedAtLocal() string {
|
|
return i.CreatedAt.Local().Format("2006-01-02 15:04")
|
|
}
|
|
|
|
func (i *Invite) ExpiresAtLocal() string {
|
|
return i.ExpiresAt.Local().Format("2006-01-02 15:04")
|
|
}
|
|
|
|
func (s *Session) IsValid() bool {
|
|
return time.Now().UTC().Before(s.ExpiresAt)
|
|
}
|
|
|
|
func (i *Invite) IsValid() bool {
|
|
return time.Now().UTC().Before(i.ExpiresAt) && i.Uses > 0
|
|
}
|