Planner/apis/extract.go
Manuel Forcén Muñoz cf4b8e0119 Completed db rewrite
2025-04-16 23:24:23 +02:00

24 lines
412 B
Go

package apis
import (
"database/sql"
"net/http"
"planner/core"
"github.com/gin-gonic/gin"
)
func extractUser(orm *sql.DB, c *gin.Context) *core.User {
username, _, ok := c.Request.BasicAuth()
if !ok {
c.Status(http.StatusUnauthorized)
return nil
}
u, err := core.UserGet(db, username)
if err != nil {
c.String(http.StatusNotFound, "Unable to find user "+username)
return nil
}
return &u
}