go-urlsh/internal/db/cookie.go

28 lines
549 B
Go
Raw Permalink Normal View History

2023-04-27 12:34:24 +02:00
package db
import (
"codeberg.org/lauralani/go-urlsh/models"
"context"
"log"
)
// IsCookieValid checks the database if Cookie val is valid.
//
// Returns true if it's valid, false if not.
func IsCookieValid(val string) bool {
if val == "" {
return false
}
2023-06-16 14:30:27 +02:00
count, err := models.DB.NewSelect().Model((*models.Session)(nil)).Where("cookie = ?", val).Count(context.Background())
2023-04-27 12:34:24 +02:00
if err != nil {
log.Printf("Error checking cookie validity for cookie %v\n", val)
return false
}
if count < 1 {
return false
} else {
return true
}
}