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

33 lines
982 B
Go
Raw Normal View History

package system
import (
"net/http"
"github.com/astaxie/session"
2016-10-11 20:16:24 +02:00
"golang.org/x/net/context"
2016-10-11 20:16:24 +02:00
libapi "dev.sum7.eu/sum7/warehost/lib/api"
liblog "dev.sum7.eu/sum7/warehost/lib/log"
)
//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
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-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-10-11 20:16:24 +02:00
returnerr = &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not logged in"}
liblog.Log.Warn("not loggedin")
return
}
}