diff --git a/flag.go b/flag.go index 2f52e1b..6cb3fef 100644 --- a/flag.go +++ b/flag.go @@ -8,7 +8,6 @@ import ( "path/filepath" "github.com/bouncepaw/mycorrhiza/assets" - "github.com/bouncepaw/mycorrhiza/user" "github.com/bouncepaw/mycorrhiza/util" ) @@ -55,5 +54,4 @@ func parseCliArgs() { util.HomePage = util.CanonicalName(util.HomePage) util.UserHypha = util.CanonicalName(util.UserHypha) util.HeaderLinksHypha = util.CanonicalName(util.HeaderLinksHypha) - user.AuthUsed = util.UseFixedAuth || util.UseRegistration } diff --git a/main.go b/main.go index ad9008c..cb05d60 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ package main import ( "fmt" - "github.com/bouncepaw/mycorrhiza/files" "io/ioutil" "log" "math/rand" @@ -15,6 +14,7 @@ import ( "strings" "github.com/bouncepaw/mycorrhiza/assets" + "github.com/bouncepaw/mycorrhiza/files" "github.com/bouncepaw/mycorrhiza/history" "github.com/bouncepaw/mycorrhiza/hyphae" "github.com/bouncepaw/mycorrhiza/shroom" @@ -193,9 +193,9 @@ func main() { hyphae.Index(WikiDir) log.Println("Indexed", hyphae.Count(), "hyphae") - if user.AuthUsed && (util.FixedCredentialsPath != "" || util.RegistrationCredentialsPath != "") { - user.ReadUsersFromFilesystem() - } + // Initialize user database + user.InitUserDatabase() + history.Start(WikiDir) shroom.SetHeaderLinks() diff --git a/user/files.go b/user/files.go index f434f6e..c1f0172 100644 --- a/user/files.go +++ b/user/files.go @@ -2,14 +2,25 @@ package user import ( "encoding/json" - "github.com/bouncepaw/mycorrhiza/files" - "github.com/bouncepaw/mycorrhiza/util" "io/ioutil" "log" "os" + + "github.com/bouncepaw/mycorrhiza/files" + "github.com/bouncepaw/mycorrhiza/util" ) -// ReadUsersFromFilesystem reads all user information from filesystem and stores it internally. Call it during initialization. +// InitUserDatabase checks the configuration for auth methods and loads users +// if necessary. Call it during initialization. +func InitUserDatabase() { + AuthUsed = util.UseFixedAuth || util.UseRegistration + + if AuthUsed && (util.FixedCredentialsPath != "" || util.RegistrationCredentialsPath != "") { + ReadUsersFromFilesystem() + } +} + +// ReadUsersFromFilesystem reads all user information from filesystem and stores it internally. func ReadUsersFromFilesystem() { if util.UseFixedAuth { rememberUsers(usersFromFixedCredentials())