mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 08:22:24 +01:00
feature (plg_backend_local): home calculation and additional options for authentication
This commit is contained in:
parent
08c9e5116c
commit
763201eaa6
1 changed files with 14 additions and 8 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"golang.org/x/crypto/bcrypt"
|
||||
"io"
|
||||
"os"
|
||||
"os/user"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
@ -14,13 +15,16 @@ func init() {
|
|||
type Local struct{}
|
||||
|
||||
func (this Local) Init(params map[string]string, app *App) (IBackend, error) {
|
||||
if err := bcrypt.CompareHashAndPassword(
|
||||
backend := Local{}
|
||||
if params["password"] == Config.Get("general.secret_key").String() {
|
||||
return backend, nil
|
||||
} else if err := bcrypt.CompareHashAndPassword(
|
||||
[]byte(Config.Get("auth.admin").String()),
|
||||
[]byte(params["password"]),
|
||||
); err != nil {
|
||||
return nil, ErrAuthenticationFailed
|
||||
); err == nil {
|
||||
return backend, nil
|
||||
}
|
||||
return Local{}, nil
|
||||
return nil, ErrAuthenticationFailed
|
||||
}
|
||||
|
||||
func (this Local) LoginForm() Form {
|
||||
|
|
@ -46,11 +50,13 @@ func (this Local) LoginForm() Form {
|
|||
}
|
||||
|
||||
func (this Local) Home() (string, error) {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "/", nil
|
||||
if home, err := os.UserHomeDir(); err == nil {
|
||||
return home, nil
|
||||
}
|
||||
return home, nil
|
||||
if currentUser, err := user.Current(); err == nil && currentUser.HomeDir != "" {
|
||||
return currentUser.HomeDir, nil
|
||||
}
|
||||
return "/", nil
|
||||
}
|
||||
|
||||
func (this Local) Ls(path string) ([]os.FileInfo, error) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue