ch16.2
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user