30 lines
881 B
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)
|
||
|
}
|
||
|
}
|