diff --git a/renderer/funcmap.go b/renderer/funcmap.go index 32fa91ea..619a0cd9 100644 --- a/renderer/funcmap.go +++ b/renderer/funcmap.go @@ -50,6 +50,7 @@ var ( "username": username, "isAdmin": isAdmin, "isParticipant": isParticipant, + "isSubscriber": isSubscriber, } ) @@ -58,13 +59,17 @@ func username(claims jwt.MapClaims) string { } func isAdmin(claims jwt.MapClaims) bool { - return claims["admin"].(bool) + return claims["role"].(string) == "administrator" } func isParticipant(claims jwt.MapClaims) bool { return claims["role"].(string) == "participant" } +func isSubscriber(claims jwt.MapClaims) bool { + return claims["role"].(string) == "subscriber" +} + func trim(text string) string { if len(text) > MaxTextLength { return text[0:MaxTextLength] + "…" diff --git a/renderer/renderer.go b/renderer/renderer.go index 0361e8ec..d570097b 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -252,36 +252,36 @@ func (rend *HTMLRenderer) Render(w http.ResponseWriter, r *http.Request, data in if data != nil && isErrorType(data) { session, err := store.Get(r, "flash-session") if err != nil { - rend.writeError(w, r, &htmlTemplateData{err, nil, nil, nil}) + rend.writeError(w, r, &htmlTemplateData{err, nil, claims, nil}) } fm := session.Flashes() err = session.Save(r, w) if err != nil { - rend.writeError(w, r, &htmlTemplateData{err, nil, nil, nil}) + rend.writeError(w, r, &htmlTemplateData{err, nil, claims, fm}) } rend.writeError(w, r, &htmlTemplateData{data.(error), nil, claims, fm}) } else { t, ok := rend.templates[options[0]["tpl_content"][0]] if !ok { err := fmt.Errorf("Template %s not found", options[0]["tpl_content"][0]) - rend.writeError(w, r, &htmlTemplateData{err, nil, nil, nil}) + rend.writeError(w, r, &htmlTemplateData{err, nil, claims, nil}) } w.Header().Set("Content-Type", "text/html; charset=utf-8") session, err := store.Get(r, "flash-session") if err != nil { - rend.writeError(w, r, &htmlTemplateData{err, nil, nil, nil}) + rend.writeError(w, r, &htmlTemplateData{err, nil, claims, nil}) } fm := session.Flashes() err = session.Save(r, w) if err != nil { - rend.writeError(w, r, &htmlTemplateData{err, nil, nil, nil}) + rend.writeError(w, r, &htmlTemplateData{err, nil, claims, fm}) } err = t.ExecuteTemplate(w, options[0]["tpl_layout"][0], &htmlTemplateData{data, options[0], claims, fm}) if err != nil { - rend.writeError(w, r, &htmlTemplateData{err, nil, nil, nil}) + rend.writeError(w, r, &htmlTemplateData{err, nil, claims, fm}) } } } diff --git a/templates/layout/base.html.tpl b/templates/layout/base.html.tpl index daf19fbc..3bccf7bc 100644 --- a/templates/layout/base.html.tpl +++ b/templates/layout/base.html.tpl @@ -32,7 +32,11 @@
diff --git a/templates/schools_add_update.html.tpl b/templates/schools_add_update.html.tpl index e7d0f942..6c8a8ffc 100644 --- a/templates/schools_add_update.html.tpl +++ b/templates/schools_add_update.html.tpl @@ -1,16 +1,25 @@ {{ define "content" }}