Commit 3427f712 authored by Janne Koschinski's avatar Janne Koschinski

Improved handling of user roles

parent d8ae97ca
......@@ -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()
......
......@@ -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}}
......
......@@ -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"),
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment