MCPcopy
hub / github.com/writefreely/writefreely / FetchLastAccessToken

Method FetchLastAccessToken

database.go:551–567  ·  view source on GitHub ↗

FetchLastAccessToken creates a new non-expiring, valid access token for the given userID.

(userID int64)

Source from the content-addressed store, hash-verified

549// FetchLastAccessToken creates a new non-expiring, valid access token for the given
550// userID.
551func (db *datastore) FetchLastAccessToken(userID int64) string {
552 var t []byte
553 err := db.QueryRow("SELECT token FROM accesstokens WHERE user_id = ? AND (expires IS NULL OR expires > "+db.now()+") ORDER BY created DESC LIMIT 1", userID).Scan(&t)
554 switch {
555 case err == sql.ErrNoRows:
556 return ""
557 case err != nil:
558 log.Error("Failed selecting from accesstoken: %v", err)
559 return ""
560 }
561
562 u, err := uuid.Parse(t)
563 if err != nil {
564 return ""
565 }
566 return u.String()
567}
568
569// GetAccessToken creates a new non-expiring, valid access token for the given
570// userID.

Callers

nothing calls this directly

Calls 2

nowMethod · 0.95
StringMethod · 0.80

Tested by

no test coverage detected