Skip to content

Commit ec75728

Browse files
authored
Hide user settings if login is disabled (ngoduykhanh#356) (ngoduykhanh#361)
1 parent cfbdae7 commit ec75728

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ func main() {
128128
panic(err)
129129
}
130130
// set app extra data
131-
extraData := make(map[string]string)
131+
extraData := make(map[string]interface{})
132132
extraData["appVersion"] = appVersion
133133
extraData["gitCommit"] = gitCommit
134134
extraData["basePath"] = util.BasePath
135+
extraData["loginDisabled"] = flagDisableLogin
135136

136137
// strip the "templates/" prefix from the embedded directory so files can be read by their direct name (e.g.
137138
// "base.html" instead of "templates/base.html")

router/router.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
// TemplateRegistry is a custom html/template renderer for Echo framework
2020
type TemplateRegistry struct {
2121
templates map[string]*template.Template
22-
extraData map[string]string
22+
extraData map[string]interface{}
2323
}
2424

2525
// Render e.Renderer interface
@@ -48,7 +48,7 @@ func (t *TemplateRegistry) Render(w io.Writer, name string, data interface{}, c
4848
}
4949

5050
// New function
51-
func New(tmplDir fs.FS, extraData map[string]string, secret []byte) *echo.Echo {
51+
func New(tmplDir fs.FS, extraData map[string]interface{}, secret []byte) *echo.Echo {
5252
e := echo.New()
5353
e.Use(session.Middleware(sessions.NewCookieStore(secret)))
5454

templates/base.html

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
</p>
146146
</a>
147147
</li>
148+
{{if not .loginDisabled}}
148149
<li class="nav-item">
149150
<a href="{{.basePath}}/users-settings" class="nav-link {{if eq .baseData.Active "users-settings" }}active{{end}}">
150151
<i class="nav-icon fas fa-cog"></i>
@@ -154,6 +155,7 @@
154155
</a>
155156
</li>
156157
{{end}}
158+
{{end}}
157159

158160
<li class="nav-header">UTILITIES</li>
159161
<li class="nav-item">

0 commit comments

Comments
 (0)