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