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)
| 584 | // once if oneTime is true. If validSecs is 0, the access token doesn't |
| 585 | // automatically expire. |
| 586 | func (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 | |
| 610 | func (db *datastore) CreatePasswordResetToken(userID int64) (string, error) { |
| 611 | t := id.Generate62RandomString(32) |
no test coverage detected