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
Raw Normal View History

package system
import (
2016-12-19 12:52:43 +01:00
"context"
"net/http"
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-10-12 08:14:06 +02:00
libsession "dev.sum7.eu/sum7/warehost/lib/session"
)
//LoginHandler for api function to Verifie User ist loggedin
2016-10-11 20:16:24 +02:00
func LoginHandler(h libapi.Handle) libapi.Handle {
2016-12-19 12:24:18 +01:00
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
2016-10-12 08:14:06 +02:00
sess := ctx.Value("session").(libsession.Session)
if login := sess.Get("login"); login != nil {
2016-10-12 22:28:10 +02:00
if loginObj := login.(*Login); loginObj.Active {
ctx = context.WithValue(ctx, "login", loginObj)
2016-12-19 12:24:18 +01:00
r = r.WithContext(ctx)
h(w, r)
2016-10-12 08:14:06 +02:00
return
}
2016-10-11 20:16:24 +02:00
liblog.Log.Warn("user not active")
2016-12-19 12:24:18 +01:00
w.WriteHeader(http.StatusUnauthorized)
libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not active user"})
2016-10-11 20:16:24 +02:00
return
}
2016-10-11 20:16:24 +02:00
liblog.Log.Warn("not loggedin")
2016-12-19 12:24:18 +01:00
w.WriteHeader(http.StatusUnauthorized)
libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not logged in"})
2016-10-11 20:16:24 +02:00
return
}
}