MCPcopy Index your code
hub / github.com/writefreely/writefreely / GetTemporaryOneTimeAccessToken

Method GetTemporaryOneTimeAccessToken

database.go:586–608  ·  view source on GitHub ↗

GetTemporaryOneTimeAccessToken creates a new valid access token for the given userID that remains valid for the given time in seconds and can only be used once if oneTime is true. If validSecs is 0, the access token doesn't automatically expire.

(userID int64, validSecs int, oneTime bool)

Source from the content-addressed store, hash-verified

584// once if oneTime is true. If validSecs is 0, the access token doesn't
585// automatically expire.
586func (db *datastore) GetTemporaryOneTimeAccessToken(userID int64, validSecs int, oneTime bool) (string, error) {
587 u, err := uuid.NewV4()
588 if err != nil {
589 log.Error("Unable to generate token: %v", err)
590 return "", err
591 }
592
593 // Insert UUID to `accesstokens`
594 binTok := u[:]
595
596 expirationVal := "NULL"
597 if validSecs > 0 {
598 expirationVal = db.dateAdd(validSecs, "SECOND")
599 }
600
601 _, err = db.Exec("INSERT INTO accesstokens (token, user_id, one_time, expires) VALUES (?, ?, ?, "+expirationVal+")", string(binTok), userID, oneTime)
602 if err != nil {
603 log.Error("Couldn't INSERT accesstoken: %v", err)
604 return "", err
605 }
606
607 return u.String(), nil
608}
609
610func (db *datastore) CreatePasswordResetToken(userID int64) (string, error) {
611 t := id.Generate62RandomString(32)

Callers 2

GetAccessTokenMethod · 0.95

Calls 2

dateAddMethod · 0.95
StringMethod · 0.80

Tested by

no test coverage detected