From 901dc2c160c2ee8c69edcb15c3e18647caabf55c Mon Sep 17 00:00:00 2001 From: 1138-4EB <1138-4EB@users.noreply.github.com> Date: Tue, 1 Jan 2019 03:18:58 +0100 Subject: [PATCH] allow to set default user with env vars (#591) Former-commit-id: e0e798642757d7a5017fccf0edd4d65a4181359f [formerly b354327fac46e7b721e2baf6fef5877944afb400] [formerly 3ef64ca1637c2145fd4a776f26afbd1b426d5098 [formerly 0b66d700e8e2fac3bf7b707494228a7a27d65e5b]] Former-commit-id: 192b543db9d3707eedd8745833020d603fe64c21 [formerly b7b034bd96ff63d185ccf9cd20cbc7673eed7de1] Former-commit-id: 4fca72efa7aac242fec991da5330e78ef455d12e --- lib/filebrowser.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) mode change 100644 => 100755 lib/filebrowser.go diff --git a/lib/filebrowser.go b/lib/filebrowser.go old mode 100644 new mode 100755 index caad4357..9d2b7601 --- a/lib/filebrowser.go +++ b/lib/filebrowser.go @@ -19,6 +19,7 @@ import ( "github.com/hacdias/fileutils" "github.com/mholt/caddy" "github.com/robfig/cron" + "github.com/spf13/viper" ) const ( @@ -205,14 +206,18 @@ func (m *FileBrowser) Setup() error { // 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. if len(users) == 0 { - u := *m.DefaultUser - u.Username = "admin" + viper.SetDefault("DEFAULT_USERNAME", "admin") // Hashes the password. - u.Password, err = HashPassword("admin") + defaultPassword, err := HashPassword("admin") if err != nil { 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. u.Admin = true