sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
warehost/system/lib.go

30 lines
881 B
Go

package system
import (
"net/http"
"github.com/astaxie/session"
"github.com/julienschmidt/httprouter"
libapi "dev.sum7.de/sum7/warehost/lib/api"
)
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)
}
}
libapi.JsonOutput(w, r, sess, data, err)
}
}