package models import "time" // BackendLinkRequest is a one-shot request an administrator starts to link // their account to a frontend user (golem15_user_backend_link_requests). // Only the SHA-256 of the code is stored; the plain code travels once, in // the site URL the administrator opens. type BackendLinkRequest struct { ID uint `gorm:"column:id;primaryKey"` CodeHash string `gorm:"column:code_hash" json:"-"` BackendUserID uint `gorm:"column:backend_user_id"` ExpiresAt time.Time `gorm:"column:expires_at"` UsedAt *time.Time `gorm:"column:used_at"` CreatedAt time.Time `gorm:"column:created_at"` } func (BackendLinkRequest) TableName() string { return "golem15_user_backend_link_requests" } func (BackendLinkRequest) Fillable() []string { return []string{"code_hash", "backend_user_id", "expires_at", "used_at"} } func (BackendLinkRequest) Hidden() []string { return []string{"code_hash"} } // IsUsableAt is false once the request was used or has expired. func (r BackendLinkRequest) IsUsableAt(now time.Time) bool { return r.UsedAt == nil && r.ExpiresAt.After(now) } func init() { Register(BackendLinkRequest{}) }