This commit is contained in:
lbenedar
2026-03-20 17:46:24 +03:00
parent e47eda4cda
commit efb58d7c15
5 changed files with 83 additions and 9 deletions

View File

@@ -12,15 +12,16 @@ import (
)
const (
ScopeActivation = "activation"
ScopeActivation = "activation"
ScopeAuthentication = "authentication"
)
type Token struct {
Plaintext string
Hash []byte
UserID int64
Expiry time.Time
Scope string
Plaintext string `json:"token"`
Hash []byte `json:"-"`
UserID int64 `json:"-"`
Expiry time.Time `json:"expiry"`
Scope string `json:"-"`
}
func generateToken(userID int64, ttl time.Duration, scope string) (*Token, error) {
@@ -66,7 +67,7 @@ func (m TokenModel) New(userID int64, ttl time.Duration, scope string) (*Token,
func (m TokenModel) Insert(token *Token) error {
query := `
INSERT INTO tokens (hash, user_id, expirt, scope)
INSERT INTO tokens (hash, user_id, expiry, scope)
VALUES ($1, $2, $3, $4)`
args := []any{token.Hash, token.UserID, token.Expiry, token.Scope}