forked from Nixius/authelia
41 lines
999 B
Go
41 lines
999 B
Go
package handlers
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
func (a *App) handleDashboard(w http.ResponseWriter, r *http.Request) {
|
|
remoteUser := r.Header.Get("Remote-User")
|
|
remoteEmail := r.Header.Get("Remote-Email")
|
|
remoteGroups := r.Header.Get("Remote-Groups")
|
|
|
|
data := map[string]any{
|
|
"AppURL": a.cfg.AppURL,
|
|
"AutheliaURL": a.cfg.AutheliaURL,
|
|
"User": remoteUser,
|
|
"Email": remoteEmail,
|
|
"Groups": remoteGroups,
|
|
"Domain": a.cfg.TraefikDomain,
|
|
"IsSubscribed": remoteGroups != "" && contains(remoteGroups, "customers"),
|
|
}
|
|
|
|
if err := a.tmpl.ExecuteTemplate(w, "dashboard.html", data); err != nil {
|
|
log.Printf("template error: %v", err)
|
|
http.Error(w, "internal error", http.StatusInternalServerError)
|
|
}
|
|
}
|
|
|
|
func contains(s, substr string) bool {
|
|
return len(s) >= len(substr) && searchString(s, substr)
|
|
}
|
|
|
|
func searchString(s, sub string) bool {
|
|
for i := 0; i <= len(s)-len(sub); i++ {
|
|
if s[i:i+len(sub)] == sub {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|