You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
458 B
Go
21 lines
458 B
Go
package db
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
)
|
|
|
|
func GetAccountInfoFromToken(token []byte) (string, error) {
|
|
var username string
|
|
err := handle.QueryRow("SELECT username FROM accounts WHERE uuid IN (SELECT uuid FROM sessions WHERE token = ? AND expire > UTC_TIMESTAMP())").Scan(&username)
|
|
if err != nil {
|
|
if err == sql.ErrNoRows {
|
|
return "", fmt.Errorf("invalid token")
|
|
}
|
|
|
|
return "", fmt.Errorf("query failed: %s", err)
|
|
}
|
|
|
|
return username, nil
|
|
}
|