Archived
Template
1
0
This repository has been archived on 2023-12-20. You can view files and clone it, but cannot push or open issues or pull requests.
Files
golang-base-project/models/token.go

29 lines
710 B
Go
Raw Normal View History

2021-12-12 14:56:13 +01:00
package models
import (
"gorm.io/gorm"
"time"
)
2021-12-12 14:56:13 +01:00
2022-01-09 14:22:43 +01:00
// Token holds tokens typically used for user activation and password resets
2021-12-12 14:56:13 +01:00
type Token struct {
gorm.Model
Value string
Type string
ModelID int
ModelType string
ExpiresAt time.Time
}
2022-01-09 14:22:43 +01:00
// HasExpired is a helper function that checks if the current time is after the token expiration time
func (t Token) HasExpired() bool {
return t.ExpiresAt.Before(time.Now())
2021-12-12 14:56:13 +01:00
}
const (
2022-01-09 14:22:43 +01:00
// TokenUserActivation is a constant used to identify tokens used for user activation
2021-12-12 14:56:13 +01:00
TokenUserActivation string = "user_activation"
2022-01-09 14:22:43 +01:00
// TokenPasswordReset is a constant used to identify tokens used for password resets
TokenPasswordReset string = "password_reset"
2021-12-12 14:56:13 +01:00
)