Fix key clash for username

This commit is contained in:
Jan Eitzinger 2022-02-03 11:00:59 +01:00
parent efc3e1735b
commit 178c8ccce6
3 changed files with 7 additions and 6 deletions

View File

@ -35,10 +35,10 @@ func setupRoutes(router *mux.Router, routes []Route) {
} }
if user := auth.GetUser(r.Context()); user != nil { if user := auth.GetUser(r.Context()); user != nil {
infos["username"] = user.Username infos["loginId"] = user.Username
infos["admin"] = user.HasRole(auth.RoleAdmin) infos["admin"] = user.HasRole(auth.RoleAdmin)
} else { } else {
infos["username"] = false infos["loginId"] = false
infos["admin"] = false infos["admin"] = false
} }

View File

@ -133,6 +133,7 @@ func setupJobRoute(i InfoType, r *http.Request) InfoType {
func setupUserRoute(i InfoType, r *http.Request) InfoType { func setupUserRoute(i InfoType, r *http.Request) InfoType {
i["id"] = mux.Vars(r)["id"] i["id"] = mux.Vars(r)["id"]
i["username"] = mux.Vars(r)["id"]
return i return i
} }
@ -359,10 +360,10 @@ func main() {
} }
if user := auth.GetUser(r.Context()); user != nil { if user := auth.GetUser(r.Context()); user != nil {
infos["username"] = user.Username infos["loginId"] = user.Username
infos["admin"] = user.HasRole(auth.RoleAdmin) infos["admin"] = user.HasRole(auth.RoleAdmin)
} else { } else {
infos["username"] = false infos["loginId"] = false
infos["admin"] = false infos["admin"] = false
} }

View File

@ -69,13 +69,13 @@
{{end}} {{end}}
{{end}} {{end}}
</ul> </ul>
{{if .Infos.username }} {{if .Infos.loginId }}
<div class="d-flex align-items-end"> <div class="d-flex align-items-end">
<ul class="navbar-nav ml-auto"> <ul class="navbar-nav ml-auto">
<li class="nav-item"> <li class="nav-item">
<form method="post" action="/logout"> <form method="post" action="/logout">
<button type="submit" class="btn btn-link nav-link fs-5"> <button type="submit" class="btn btn-link nav-link fs-5">
<span class="cc-nav-text">{{ .Infos.username }} Logout</span> <span class="cc-nav-text">{{ .Infos.loginId }} Logout</span>
<i class="bi-box-arrow-right"></i> <i class="bi-box-arrow-right"></i>
</button> </button>
</form> </form>