Require directory membership to view the directory

This commit is contained in:
Ian Gulliver
2026-08-16 11:27:00 -07:00
parent 366e3bb8a2
commit 4d70d6c2a8
4 changed files with 25 additions and 2 deletions
+14
View File
@@ -28,6 +28,20 @@ type app struct {
mapsKey string
}
func MemberGate(cache *Cache, next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/auth/login" || r.URL.Path == "/auth/logout" || strings.HasPrefix(r.URL.Path, "/static/") {
next.ServeHTTP(w, r)
return
}
if !cache.Model().Member(strings.ToLower(auth.Email(r))) {
http.Error(w, "account is not in the directory", http.StatusForbidden)
return
}
next.ServeHTTP(w, r)
})
}
func Register(mux *http.ServeMux, cache *Cache, mapsKey string) {
a := app{cache: cache, mapsKey: mapsKey}
for _, section := range sections {
+9
View File
@@ -58,6 +58,15 @@ type Grade struct {
NextBand string `json:"nextBand,omitempty"`
}
func (m *Model) Member(email string) bool {
for _, p := range m.People {
if p.Email == email {
return true
}
}
return false
}
func (m *Model) DisplayName(email string) string {
for _, p := range m.People {
if p.Email == email {