Files
uPortal/internal/auth/model.go
T

43 lines
852 B
Go
Raw Normal View History

2026-10-15 23:25:46 +03:00
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")
}
2026-10-16 11:34:34 +03:00
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")
}
2026-10-15 23:25:46 +03:00
func (s *Session) IsValid() bool {
2026-10-16 11:34:34 +03:00
return time.Now().UTC().Before(s.ExpiresAt)
2026-10-15 23:25:46 +03:00
}
func (i *Invite) IsValid() bool {
2026-10-16 11:34:34 +03:00
return time.Now().UTC().Before(i.ExpiresAt) && i.Uses > 0
2026-10-15 23:25:46 +03:00
}