24 lines
412 B
Go
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
|
|
}
|