mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-26 05:59:21 -06:00
37 lines
764 B
Go
37 lines
764 B
Go
package auth
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/shroff/phylum/server/internal/core/errors"
|
|
"github.com/shroff/phylum/server/internal/core/fs"
|
|
"github.com/shroff/phylum/server/internal/core/user"
|
|
)
|
|
|
|
const keyUser = "user"
|
|
const keyFileSystem = "filesystem"
|
|
|
|
var ErrRequired = errors.NewError(http.StatusUnauthorized, "auth_required", "authorization required")
|
|
|
|
func Set(c *gin.Context, u user.User, f fs.FileSystem) {
|
|
c.Set(keyUser, u)
|
|
c.Set(keyFileSystem, f)
|
|
}
|
|
|
|
func GetUser(c *gin.Context) user.User {
|
|
val, ok := c.Get(keyUser)
|
|
if !ok {
|
|
return user.User{}
|
|
}
|
|
return val.(user.User)
|
|
}
|
|
|
|
func GetFileSystem(c *gin.Context) fs.FileSystem {
|
|
val, ok := c.Get(keyFileSystem)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return val.(fs.FileSystem)
|
|
}
|