33 lines
1013 B
Go
33 lines
1013 B
Go
package auth
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"wucher/internal/shared/pkg/uuidv7"
|
|
)
|
|
|
|
type PasswordResetToken struct {
|
|
ID []byte `gorm:"type:binary(16);primaryKey;column:id"`
|
|
UserID []byte `gorm:"type:binary(16);index;not null;column:user_id"`
|
|
TokenHash []byte `gorm:"type:varbinary(32);uniqueIndex;not null;column:token_hash"`
|
|
ExpiresAt time.Time `gorm:"index;not null;column:expires_at"`
|
|
UsedAt *time.Time `gorm:"index;column:used_at"`
|
|
RequestedIP string `gorm:"type:varchar(128);column:requested_ip"`
|
|
UserAgent string `gorm:"type:varchar(255);column:user_agent"`
|
|
CreatedAt time.Time
|
|
CreatedBy []byte `gorm:"type:binary(16);column:created_by"`
|
|
UpdatedAt time.Time
|
|
UpdatedBy []byte `gorm:"type:binary(16);column:updated_by"`
|
|
}
|
|
|
|
func (PasswordResetToken) TableName() string { return "password_reset_tokens" }
|
|
|
|
func (prt *PasswordResetToken) BeforeCreate(tx *gorm.DB) error {
|
|
if len(prt.ID) == 0 {
|
|
prt.ID = uuidv7.MustBytes()
|
|
}
|
|
return nil
|
|
}
|