2016-08-17 22:31:58 +02:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
2016-12-19 12:52:43 +01:00
|
|
|
"context"
|
2016-08-17 22:31:58 +02:00
|
|
|
"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"
|
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 {
|
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)
|
2016-08-17 22:31:58 +02:00
|
|
|
|
|
|
|
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-08-17 22:31:58 +02:00
|
|
|
}
|
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-08-17 22:31:58 +02:00
|
|
|
}
|
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
|
2016-08-17 22:31:58 +02:00
|
|
|
}
|
|
|
|
}
|