Planner/apis/extract.go

25 lines
412 B
Go
Raw Normal View History

2025-02-12 19:29:00 +01:00
package apis
2024-11-09 19:35:44 +01:00
import (
2025-04-16 23:24:23 +02:00
"database/sql"
2024-11-09 19:35:44 +01:00
"net/http"
2025-02-12 19:29:00 +01:00
"planner/core"
2025-04-16 23:24:23 +02:00
"github.com/gin-gonic/gin"
2024-11-09 19:35:44 +01:00
)
2025-04-16 23:24:23 +02:00
func extractUser(orm *sql.DB, c *gin.Context) *core.User {
2024-11-09 19:35:44 +01:00
username, _, ok := c.Request.BasicAuth()
if !ok {
c.Status(http.StatusUnauthorized)
return nil
}
2025-04-16 23:24:23 +02:00
u, err := core.UserGet(db, username)
if err != nil {
2024-11-09 19:35:44 +01:00
c.String(http.StatusNotFound, "Unable to find user "+username)
return nil
}
return &u
}