allow to set default user with env vars (#591)

pull/596/head
1138-4EB 2019-01-01 03:18:58 +01:00 committed by GitHub
parent 7394f6b9bb
commit 0b66d700e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

11
lib/filebrowser.go Normal file → Executable file
View File

@ -19,6 +19,7 @@ import (
"github.com/hacdias/fileutils" "github.com/hacdias/fileutils"
"github.com/mholt/caddy" "github.com/mholt/caddy"
"github.com/robfig/cron" "github.com/robfig/cron"
"github.com/spf13/viper"
) )
const ( const (
@ -205,14 +206,18 @@ func (m *FileBrowser) Setup() error {
// If there are no users in the database, it creates a new one // If there are no users in the database, it creates a new one
// based on 'base' User that must be provided by the function caller. // based on 'base' User that must be provided by the function caller.
if len(users) == 0 { if len(users) == 0 {
u := *m.DefaultUser viper.SetDefault("DEFAULT_USERNAME", "admin")
u.Username = "admin"
// Hashes the password. // Hashes the password.
u.Password, err = HashPassword("admin") defaultPassword, err := HashPassword("admin")
if err != nil { if err != nil {
return err return err
} }
viper.SetDefault("DEFAULT_PASSWORD_HASH", defaultPassword)
u := *m.DefaultUser
u.Username = viper.GetString("DEFAULT_USERNAME")
u.Password = viper.GetString("DEFAULT_PASSWORD_HASH")
// The first user must be an administrator. // The first user must be an administrator.
u.Admin = true u.Admin = true