2016-08-17 22:31:58 +02:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/astaxie/session"
|
2016-10-11 20:16:24 +02:00
|
|
|
"golang.org/x/net/context"
|
2016-08-17 22:31:58 +02:00
|
|
|
|
2016-10-11 20:16:24 +02:00
|
|
|
libapi "dev.sum7.eu/sum7/warehost/lib/api"
|
|
|
|
liblog "dev.sum7.eu/sum7/warehost/lib/log"
|
2016-08-17 22:31:58 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
//LoginHandler for api function to Verifie User ist loggedin
|
2016-10-11 20:16:24 +02:00
|
|
|
func LoginHandler(h libapi.Handle) libapi.Handle {
|
|
|
|
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
|
|
|
sess := ctx.Value("session").(session.Session)
|
|
|
|
returndata = false
|
2016-08-17 22:31:58 +02:00
|
|
|
|
|
|
|
if login := sess.Get("login"); login != nil {
|
|
|
|
if loginObj := login.(Login); loginObj.Active {
|
2016-10-11 20:16:24 +02:00
|
|
|
ctx = context.WithValue(ctx, "login", &loginObj)
|
|
|
|
returndata, returnerr = h(ctx, w, r)
|
2016-08-17 22:31:58 +02:00
|
|
|
}
|
2016-10-11 20:16:24 +02:00
|
|
|
returnerr = &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not active user"}
|
|
|
|
liblog.Log.Warn("user not active")
|
|
|
|
return
|
2016-08-17 22:31:58 +02:00
|
|
|
}
|
2016-10-11 20:16:24 +02:00
|
|
|
returnerr = &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not logged in"}
|
|
|
|
liblog.Log.Warn("not loggedin")
|
|
|
|
return
|
2016-08-17 22:31:58 +02:00
|
|
|
}
|
|
|
|
}
|