diff --git a/boardvoting.go b/boardvoting.go index 3b62116..93b1532 100644 --- a/boardvoting.go +++ b/boardvoting.go @@ -18,6 +18,7 @@ import ( "io/ioutil" "net/http" "os" + "sort" "strconv" "strings" "time" @@ -61,11 +62,14 @@ const ( ) func authenticateRequest(w http.ResponseWriter, r *http.Request, handler func(http.ResponseWriter, *http.Request)) { + emailsTried := make(map[string]bool) for _, cert := range r.TLS.PeerCertificates { for _, extKeyUsage := range cert.ExtKeyUsage { if extKeyUsage == x509.ExtKeyUsageClientAuth { for _, emailAddress := range cert.EmailAddresses { - voter, err := FindVoterByAddress(emailAddress) + emailLower := strings.ToLower(emailAddress) + emailsTried[emailLower] = true + voter, err := FindVoterByAddress(emailLower) if err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return @@ -82,8 +86,18 @@ func authenticateRequest(w http.ResponseWriter, r *http.Request, handler func(ht } needsAuth, ok := r.Context().Value(ctxNeedsAuth).(bool) if ok && needsAuth { + var templateContext struct { + PageTitle string + Voter *Voter + Flashes interface{} + Emails []string + } + for k := range emailsTried { + templateContext.Emails = append(templateContext.Emails, k) + } + sort.Strings(templateContext.Emails) w.WriteHeader(http.StatusForbidden) - renderTemplate(w, []string{"denied.html", "header.html", "footer.html"}, nil) + renderTemplate(w, []string{"denied.html", "header.html", "footer.html"}, templateContext) return } handler(w, r) diff --git a/templates/denied.html b/templates/denied.html index b8d8a3e..398a36f 100644 --- a/templates/denied.html +++ b/templates/denied.html @@ -4,6 +4,14 @@
You are not authorized to act here!

If you think this is in error, please contact the administrator.

If you don't know who that is, it is definitely not an error ;)

+ {{ if .Emails }} +

The following addresses were present in your certificate:

+

+ {{ end }} {{ template "footer" . }} \ No newline at end of file diff --git a/templates/header.html b/templates/header.html index 69ba7d2..db55d97 100644 --- a/templates/header.html +++ b/templates/header.html @@ -10,7 +10,7 @@
-

{{ template "pagetitle" . }}

+

{{ template "pagetitle" . }}{{ if .Voter }}
Authenticated as {{ .Voter.Name }} <{{ .Voter.Reminder }}>
{{ end }}

{{ with .Flashes }}