diff --git a/main.go b/main.go index 8a9b7ccc5ddf4fbeb080adb4a8d308dcc5e968dd..1cf5c77649c179c0abb0c3ea4c68cb585c8f1dd2 100644 --- a/main.go +++ b/main.go @@ -8,16 +8,6 @@ import ( "fmt" ) -func headerWrapper(handler http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - println(r.URL.Path) - for key, value := range r.Header { - fmt.Printf("%s: %s\n", key, value) - } - handler.ServeHTTP(w, r) - }) -} - func main() { config := NewConfigFromEnv() diff --git a/templates/_navigation.html b/templates/_navigation.html index d0aba7d92c23c6670081e7e66308880e6d6c176f..d5d31c99f7da0359b4cef44b5785c68f514a1d37 100644 --- a/templates/_navigation.html +++ b/templates/_navigation.html @@ -2,14 +2,16 @@ <nav> <ul> <li class="title"><a href="/">i.k8r</a></li> - {{if .Id}} + {{if .hasRole "imghost:user" }} <li><a href="/upload">Upload</a></li> {{end}} <li class="spacer"></li> - {{if .Id}} + {{if .hasRole "imghost:user" }} <li><a href="/me/images">My Images</a></li> <li><a href="/me/albums">My Albums</a></li> <li class="me"><a href="https://accounts.kuschku.de/profile">{{.Name}}</a></li> + {{else if .Id }} + <li class="me"><a href="https://accounts.kuschku.de/profile">{{.Name}}</a></li> {{else}} <li><a href="/me/images">Login</a></li> {{end}} diff --git a/util.go b/util.go index 54521cebdf2c987cf035c1ce2ae30fda42c196a2..f8b9c376ff6698ce844a3d1aaed6a6a928ff8dfe 100644 --- a/util.go +++ b/util.go @@ -13,6 +13,16 @@ type UserInfo struct { Id string Name string Email string + Roles []string +} + +func (info *UserInfo) hasRole(role string) bool { + for _, r := range info.Roles { + if r == role { + return true + } + } + return false } type PageContext struct { @@ -43,6 +53,7 @@ func parseUser(r *http.Request) UserInfo { r.Header.Get("X-Auth-Subject"), r.Header.Get("X-Auth-Username"), r.Header.Get("X-Auth-Email"), + r.Header.Get("X-Auth-Roles"), } }