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" }}
+{{$isSubscriber := .Claims|isSubscriber}} + {{$update := .Options.Get "update"}} -{{if $update}} +{{if not $isSubscriber}} +{{if $update}} {{template "breadcrumb" toSlice "Scuole" (all "School") (.Data|string) (.Data.ID|show "School") "Aggiorna" "current"}} {{else}} {{template "breadcrumb" toSlice "Scuole" (all "School") "Aggiungi" "current"}} {{end}} +{{end}} + +{{if $isSubscriber}} +{{template "add_update_header" dict "update" $update "addTitle" "Iscrivi scuola" "updateTitle" (printf "Aggiorna scuola %s" (.Data|string))}} +{{else}} {{template "add_update_header" dict "update" $update "addTitle" "Crea nuova scuola" "updateTitle" (printf "Aggiorna scuola %s" (.Data|string))}} +{{end}} {{$form := "form_add_update"}}
- + {{if .Claims|isSubscriber}} +

+ Grazie per aver iscritto la scuola {{.Data.Name}} + alle Olimpiadi di Economia e Finanza. +

+

+ Una mail con le credenziali di accesso è stata inviata + all'indirizzo {{.Data.Email}}. +

+

+ Ora è possibile uscire da questa sessione e + utilizzare le credenziali ricevute per iscrivere gli studenti alla + competizione. +

+ + {{else}} {{template "breadcrumb" toSlice "Scuole" (all "School") (.Data|string|trim) "current"}} {{template "show_header" dict "title" (.Data|string|trim) "updatePath" (.Data.ID|update "School") "deletePath" (.Data.ID|delete "School")}} @@ -26,7 +41,7 @@
- + {{end}} {{ end }}