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.0 KiB
Go

package system
import (
"context"
"net/http"
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(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
sess := ctx.Value("session").(libsession.Session)
if login := sess.Get("login"); login != nil {
if loginObj := login.(*Login); loginObj.Active {
ctx = context.WithValue(ctx, "login", loginObj)
r = r.WithContext(ctx)
h(w, r)
return
}
liblog.Log.Warn("user not active")
w.WriteHeader(http.StatusUnauthorized)
libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not active user"})
return
}
liblog.Log.Warn("not loggedin")
w.WriteHeader(http.StatusUnauthorized)
libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not logged in"})
return
}
}