Add access token check to auth
This commit is contained in:
parent
8f53e8a967
commit
6a2b213787
4 changed files with 34 additions and 7 deletions
|
@ -6,6 +6,7 @@ package dbgen
|
|||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
||||
"gorm.io/gorm"
|
||||
|
@ -435,6 +436,25 @@ type IAccessTokenDo interface {
|
|||
Returning(value interface{}, columns ...string) IAccessTokenDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
|
||||
GetTokenIfValid(token string) (result *models.AccessToken, err error)
|
||||
}
|
||||
|
||||
// Get the data for a token if it hasn't expired yet
|
||||
//
|
||||
// SELECT * FROM @@table WHERE token = @token AND expires_at < NOW() LIMIT 1
|
||||
func (a accessTokenDo) GetTokenIfValid(token string) (result *models.AccessToken, err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, token)
|
||||
generateSQL.WriteString("SELECT * FROM access_tokens WHERE token = ? AND expires_at < NOW() LIMIT 1 ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = a.UnderlyingDB().Raw(generateSQL.String(), params...).Take(&result) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (a accessTokenDo) Debug() IAccessTokenDo {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue