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

36 lines
1.1 KiB
Go
Raw Normal View History

package system
import (
"net/http"
"github.com/astaxie/session"
"github.com/julienschmidt/httprouter"
libapi "dev.sum7.de/sum7/warehost/lib/api"
2016-09-03 16:30:48 +02:00
log "dev.sum7.de/sum7/warehost/lib/log"
)
2016-09-03 10:18:46 +02:00
// 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)
2016-09-03 16:30:48 +02:00
} else {
log.Log.Warn("user not active")
}
2016-09-03 16:30:48 +02:00
} else {
log.Log.Warn("not loggedin")
}
2016-09-03 10:18:46 +02:00
libapi.JSONOutput(w, r, sess, data, err)
}
}