Skip to content

Commit

Permalink
sytle: further comment auth relative
Browse files Browse the repository at this point in the history
  • Loading branch information
lovehunter9 committed Feb 27, 2025
1 parent 7f4ef73 commit f0fb2c7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 76 deletions.
18 changes: 6 additions & 12 deletions packages/backend/auth/auth.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package auth

import (
"github.com/filebrowser/filebrowser/v2/settings"
"github.com/filebrowser/filebrowser/v2/users"
"net/http"
)

// Auther is the authentication interface.
type Auther interface {
// Auth is called to authenticate a request.
Auth(r *http.Request, usr users.Store, stg *settings.Settings, srv *settings.Server) (*users.User, error)
// LoginPage indicates if this auther needs a login page.
LoginPage() bool
}
//type Auther interface {
// // Auth is called to authenticate a request.
// Auth(r *http.Request, usr users.Store, stg *settings.Settings, srv *settings.Server) (*users.User, error)
// // LoginPage indicates if this auther needs a login page.
// LoginPage() bool
//}
34 changes: 14 additions & 20 deletions packages/backend/auth/none.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package auth

import (
"github.com/filebrowser/filebrowser/v2/settings"
"github.com/filebrowser/filebrowser/v2/users"
"net/http"
)

// MethodNoAuth is used to identify no auth.
const MethodNoAuth settings.AuthMethod = "noauth"

// NoAuth is no auth implementation of auther.
type NoAuth struct{}

// Auth uses authenticates user 1.
func (a NoAuth) Auth(r *http.Request, usr users.Store, stg *settings.Settings, srv *settings.Server) (*users.User, error) {
return usr.Get(srv.Root, uint(1))
}

// LoginPage tells that no auth doesn't require a login page.
func (a NoAuth) LoginPage() bool {
return false
}
//const MethodNoAuth settings.AuthMethod = "noauth"
//
//// NoAuth is no auth implementation of auther.
//type NoAuth struct{}
//
//// Auth uses authenticates user 1.
//func (a NoAuth) Auth(r *http.Request, usr users.Store, stg *settings.Settings, srv *settings.Server) (*users.User, error) {
// return usr.Get(srv.Root, uint(1))
//}
//
//// LoginPage tells that no auth doesn't require a login page.
//func (a NoAuth) LoginPage() bool {
// return false
//}
58 changes: 27 additions & 31 deletions packages/backend/auth/storage.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
package auth

import (
"github.com/filebrowser/filebrowser/v2/settings"
"github.com/filebrowser/filebrowser/v2/users"
)

// StorageBackend is a storage backend for auth storage.
type StorageBackend interface {
Get(settings.AuthMethod) (Auther, error)
Save(Auther) error
}

// Storage is a auth storage.
type Storage struct {
back StorageBackend
users *users.Storage
}

// NewStorage creates a auth storage from a backend.
func NewStorage(back StorageBackend, userStore *users.Storage) *Storage {
return &Storage{back: back, users: userStore}
}

// Get wraps a StorageBackend.Get.
func (s *Storage) Get(t settings.AuthMethod) (Auther, error) {
return s.back.Get(t)
}

// Save wraps a StorageBackend.Save.
func (s *Storage) Save(a Auther) error {
return s.back.Save(a)
}
//
//// StorageBackend is a storage backend for auth storage.
//type StorageBackend interface {
// Get(settings.AuthMethod) (Auther, error)
// Save(Auther) error
//}
//
//// Storage is a auth storage.
//type Storage struct {
// back StorageBackend
// users *users.Storage
//}
//
//// NewStorage creates a auth storage from a backend.
//func NewStorage(back StorageBackend, userStore *users.Storage) *Storage {
// return &Storage{back: back, users: userStore}
//}
//
//// Get wraps a StorageBackend.Get.
//func (s *Storage) Get(t settings.AuthMethod) (Auther, error) {
// return s.back.Get(t)
//}
//
//// Save wraps a StorageBackend.Save.
//func (s *Storage) Save(a Auther) error {
// return s.back.Save(a)
//}
19 changes: 9 additions & 10 deletions packages/backend/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/tls"
"errors"
"fmt"
"github.com/filebrowser/filebrowser/v2/auth"
"github.com/filebrowser/filebrowser/v2/common"
"github.com/filebrowser/filebrowser/v2/my_redis"
"io"
Expand Down Expand Up @@ -438,15 +437,15 @@ func quickSetup(flags *pflag.FlagSet, d pythonData) {
}

var err error
if _, noauth := getParamB(flags, "noauth"); noauth {
set.AuthMethod = auth.MethodNoAuth
err = d.store.Auth.Save(&auth.NoAuth{})
} else {
//set.AuthMethod = auth.MethodJSONAuth
//err = d.store.Auth.Save(&auth.JSONAuth{})
}

checkErr(err)
//if _, noauth := getParamB(flags, "noauth"); noauth {
// set.AuthMethod = auth.MethodNoAuth
// err = d.store.Auth.Save(&auth.NoAuth{})
//} else {
// //set.AuthMethod = auth.MethodJSONAuth
// //err = d.store.Auth.Save(&auth.JSONAuth{})
//}

//checkErr(err)
err = d.store.Settings.Save(set)
checkErr(err)

Expand Down
5 changes: 2 additions & 3 deletions packages/backend/storage/storage.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package storage

import (
"github.com/filebrowser/filebrowser/v2/auth"
"github.com/filebrowser/filebrowser/v2/settings"
"github.com/filebrowser/filebrowser/v2/users"
)

// Storage is a storage powered by a Backend which makes the necessary
// verifications when fetching and saving data to ensure consistency.
type Storage struct {
Users users.Store
Auth *auth.Storage
Users users.Store
//Auth *auth.Storage
Settings *settings.Storage
}

0 comments on commit f0fb2c7

Please sign in to comment.