diff options
Diffstat (limited to 'nexus/models/session.go')
| -rw-r--r-- | nexus/models/session.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/nexus/models/session.go b/nexus/models/session.go new file mode 100644 index 0000000..0adbba2 --- /dev/null +++ b/nexus/models/session.go @@ -0,0 +1,36 @@ +package models
+
+import (
+ "time"
+
+ "github.com/google/uuid"
+ "gorm.io/gorm"
+)
+
+type Session struct {
+ gorm.Model
+ ID uuid.UUID `gorm:"type:uuid;primaryKey"`
+ AccountID uuid.UUID `gorm:"type:uuid;not null;index"`
+ AuthToken string `gorm:"uniqueIndex;not null"`
+ RefreshToken string `gorm:"uniqueIndex;not null"`
+ AuthExpiry time.Time `gorm:"not null"`
+ RefreshExpiry time.Time `gorm:"not null"`
+ IPAddress string
+ UserAgent string
+ Account Account `gorm:"foreignKey:AccountID"`
+}
+
+func (self *Session) BeforeCreate(tx *gorm.DB) error {
+ if self.ID == uuid.Nil {
+ self.ID = uuid.New()
+ }
+ return nil
+}
+
+func (self *Session) IsAuthExpired() bool {
+ return time.Now().After(self.AuthExpiry)
+}
+
+func (self *Session) IsRefreshExpired() bool {
+ return time.Now().After(self.RefreshExpiry)
+}
|
