Files

54 lines
2.1 KiB
Go

package fbhttp
import (
"github.com/filebrowser/filebrowser/v2/users"
"net/http"
)
type userInfo struct {
SessionState string `json:"sessionState,omitempty"`
AuthMode string `json:"authMode,omitempty"`
ID uint `json:"id"`
Locale string `json:"locale"`
ViewMode users.ViewMode `json:"viewMode"`
SingleClick bool `json:"singleClick"`
RedirectAfterCopyMove bool `json:"redirectAfterCopyMove"`
Perm users.Permissions `json:"perm"`
Commands []string `json:"commands"`
LockPassword bool `json:"lockPassword"`
HideDotfiles bool `json:"hideDotfiles"`
HidePreviews bool `json:"hidePreviews"`
Dicom3D users.Dicom3DSettings `json:"dicom3D"`
DateFormat bool `json:"dateFormat"`
Username string `json:"username"`
ProfileName string `json:"profileName,omitempty"`
Email string `json:"email,omitempty"`
Picture string `json:"picture,omitempty"`
AceEditorTheme string `json:"aceEditorTheme"`
}
func withUser(fn handleFunc) handleFunc {
return func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
identity, ok := r.Context().Value(identityKey{}).(sessionIdentity)
if !ok {
return http.StatusUnauthorized, nil
}
var err error
d.user, err = d.store.Users.Get(d.server.Root, d.server.FollowExternalSymlinks, identity.ID)
if err != nil {
return http.StatusUnauthorized, nil
}
applySSOIdentity(d.user, identity)
canonicalizeRequestPath(r)
return fn(w, r, d)
}
}
func withAdmin(fn handleFunc) handleFunc {
return withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
if !d.user.Perm.Admin {
return http.StatusForbidden, nil
}
return fn(w, r, d)
})
}