From ec757286c5a85f383d58b24dac487606e69636ca Mon Sep 17 00:00:00 2001
From: ByteDream <63594396+ByteDream@users.noreply.github.com>
Date: Wed, 24 May 2023 12:04:02 +0200
Subject: [PATCH] Hide user settings if login is disabled (#356) (#361)

---
 main.go             | 3 ++-
 router/router.go    | 4 ++--
 templates/base.html | 2 ++
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/main.go b/main.go
index 2fb2d03..a6c147f 100644
--- a/main.go
+++ b/main.go
@@ -128,10 +128,11 @@ func main() {
 		panic(err)
 	}
 	// set app extra data
-	extraData := make(map[string]string)
+	extraData := make(map[string]interface{})
 	extraData["appVersion"] = appVersion
 	extraData["gitCommit"] = gitCommit
 	extraData["basePath"] = util.BasePath
+	extraData["loginDisabled"] = flagDisableLogin
 
 	// strip the "templates/" prefix from the embedded directory so files can be read by their direct name (e.g.
 	// "base.html" instead of "templates/base.html")
diff --git a/router/router.go b/router/router.go
index c2d1943..569ebaf 100644
--- a/router/router.go
+++ b/router/router.go
@@ -19,7 +19,7 @@ import (
 // TemplateRegistry is a custom html/template renderer for Echo framework
 type TemplateRegistry struct {
 	templates map[string]*template.Template
-	extraData map[string]string
+	extraData map[string]interface{}
 }
 
 // Render e.Renderer interface
@@ -48,7 +48,7 @@ func (t *TemplateRegistry) Render(w io.Writer, name string, data interface{}, c
 }
 
 // New function
-func New(tmplDir fs.FS, extraData map[string]string, secret []byte) *echo.Echo {
+func New(tmplDir fs.FS, extraData map[string]interface{}, secret []byte) *echo.Echo {
 	e := echo.New()
 	e.Use(session.Middleware(sessions.NewCookieStore(secret)))
 
diff --git a/templates/base.html b/templates/base.html
index 181049d..0865ff3 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -145,6 +145,7 @@
                                 </p>
                             </a>
                         </li>
+                        {{if not .loginDisabled}}
                         <li class="nav-item">
                             <a href="{{.basePath}}/users-settings" class="nav-link {{if eq .baseData.Active "users-settings" }}active{{end}}">
                             <i class="nav-icon fas fa-cog"></i>
@@ -154,6 +155,7 @@
                             </a>
                         </li>
                         {{end}}
+                        {{end}}
 
                         <li class="nav-header">UTILITIES</li>
                         <li class="nav-item">