2016-08-17 22:31:58 +02:00
|
|
|
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-08-17 22:31:58 +02:00
|
|
|
)
|
|
|
|
|
2016-09-03 10:18:46 +02:00
|
|
|
// Handle to handle request with session and current logged in user
|
2016-08-17 22:31:58 +02:00
|
|
|
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-08-17 22:31:58 +02:00
|
|
|
}
|
2016-09-03 16:30:48 +02:00
|
|
|
} else {
|
|
|
|
log.Log.Warn("not loggedin")
|
2016-08-17 22:31:58 +02:00
|
|
|
}
|
2016-09-03 10:18:46 +02:00
|
|
|
libapi.JSONOutput(w, r, sess, data, err)
|
2016-08-17 22:31:58 +02:00
|
|
|
}
|
|
|
|
}
|