FetchLastAccessToken creates a new non-expiring, valid access token for the given userID.
(userID int64)
| 549 | // FetchLastAccessToken creates a new non-expiring, valid access token for the given |
| 550 | // userID. |
| 551 | func (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. |