// MustLoginMiddleware determines whether a user needs to log in to access a given Group page
MustLoginMiddleware determines whether a user needs to log in to access a given Group page
// MustLoginMiddleware determines whether a user needs to log in to access a given Group page
func MustLoginMiddleware(requiredGroup Group, next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		sess := getSession(r)
		user, ok := sess.Values["user"].(Account)
		if ok && user.HasGroupPrivilege(requiredGroup) {
			next.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), "user", user)))
			return
		} else if ok {
			AddErrFlashQuick(w, r, "You do not have permission to view this page.")
			http.Redirect(w, r, "/", http.StatusFound)
			return
		}
		if requiredGroup == GroupRead && config.Users.ReadOpen {
			next.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), "user", OpenUser)))
			return
		}
		if !ok {
			AddErrFlashQuick(w, r, "You do not have permission to view this page. Please login first.")
			http.Redirect(w, r, "/login", http.StatusFound)
			return
		}
	})
}
func MustLoginMiddleware ( requiredGroup Group , next http . Handler ) http . Handler { return http . HandlerFunc ( func ( w http . ResponseWriter , r * http . Request ) { sess := getSession ( r ) user , ok := sess . Values [ " " ] . ( Account ) if ok && user . HasGroupPrivilege ( requiredGroup ) { next . ServeHTTP ( w , r . WithContext ( context . WithValue ( r . Context ( ) , " " , user ) ) ) return } else if ok { AddErrFlashQuick ( w , r , " " ) http . Redirect ( w , r , " " , http . StatusFound ) return } if requiredGroup == GroupRead && config . Users . ReadOpen { next . ServeHTTP ( w , r . WithContext ( context . WithValue ( r . Context ( ) , " " , OpenUser ) ) ) return } if ! ok { AddErrFlashQuick ( w , r , " " ) http . Redirect ( w , r , " " , http . StatusFound ) return } } ) }
MustLoginMiddleware determines whether a user needs to log in to access a given Group page
MustLoginMiddleware determines whether a user needs to log in to access a given Group page
// if read is open, allow access and use a dummy user so the UI doesn't break