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

package system
import (
"net/http"
"golang.org/x/net/context"
libapi "dev.sum7.eu/sum7/warehost/lib/api"
liblog "dev.sum7.eu/sum7/warehost/lib/log"
libsession "dev.sum7.eu/sum7/warehost/lib/session"
)
//LoginHandler for api function to Verifie User ist loggedin
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").(libsession.Session)
returndata = false
if login := sess.Get("login"); login != nil {
if loginObj := login.(*Login); loginObj.Active {
ctx = context.WithValue(ctx, "login", loginObj)
returndata, returnerr = h(ctx, w, r)
return
}
returnerr = &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not active user"}
w.WriteHeader(http.StatusUnauthorized)
liblog.Log.Warn("user not active")
return
}
w.WriteHeader(http.StatusUnauthorized)
returnerr = &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not logged in"}
liblog.Log.Warn("not loggedin")
return
}
}