package system import ( "net/http" "github.com/astaxie/session" "golang.org/x/net/context" libapi "dev.sum7.eu/sum7/warehost/lib/api" liblog "dev.sum7.eu/sum7/warehost/lib/log" ) //LoginHandler for api function to Verifie User ist loggedin func LoginHandler(h libapi.Handle) libapi.Handle { return func(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) { sess := ctx.Value("session").(session.Session) returndata = false if login := sess.Get("login"); login != nil { if loginObj := login.(Login); loginObj.Active { ctx = context.WithValue(ctx, "login", &loginObj) returndata, returnerr = h(ctx, w, r) } returnerr = &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not active user"} liblog.Log.Warn("user not active") return } returnerr = &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not logged in"} liblog.Log.Warn("not loggedin") return } }