package system import ( "net/http" "github.com/astaxie/session" "github.com/julienschmidt/httprouter" libapi "dev.sum7.de/sum7/warehost/lib/api" log "dev.sum7.de/sum7/warehost/lib/log" ) // Handle to handle request with session and current logged in user type Handle func(w http.ResponseWriter, r *http.Request, ps httprouter.Params, sess session.Session, login *Login) (interface{}, *libapi.ErrorResult) //LoginHandler for api function to Verifie User ist loggedin func LoginHandler(h Handle, sessions *session.Manager) httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { sess := sessions.SessionStart(w, r) err := &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not logged in"} var data interface{} data = false if login := sess.Get("login"); login != nil { if loginObj := login.(Login); loginObj.Active { data, err = h(w, r, ps, sess, &loginObj) } else { log.Log.Warn("user not active") } } else { log.Log.Warn("not loggedin") } libapi.JSONOutput(w, r, sess, data, err) } }