2016-10-16 19:00:53 +02:00
|
|
|
package host
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2017-10-04 12:32:07 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-06-02 10:15:09 +02:00
|
|
|
|
2016-12-19 12:24:18 +01:00
|
|
|
"context"
|
2016-10-16 19:00:53 +02:00
|
|
|
|
|
|
|
libapi "dev.sum7.eu/sum7/warehost/lib/api"
|
|
|
|
liblog "dev.sum7.eu/sum7/warehost/lib/log"
|
|
|
|
libsystem "dev.sum7.eu/sum7/warehost/system"
|
|
|
|
)
|
|
|
|
|
2017-06-02 10:15:09 +02:00
|
|
|
func setProfilLog(r *http.Request, logger *logrus.Entry) *logrus.Entry {
|
|
|
|
ctx := r.Context()
|
|
|
|
profil := ctx.Value("profil").(*Profil)
|
|
|
|
logger = logger.WithField("pID", profil.ID)
|
|
|
|
return logger
|
|
|
|
}
|
|
|
|
|
2016-10-16 19:00:53 +02:00
|
|
|
//ProfilHandler for api function to get host.Profil
|
|
|
|
func ProfilHandler(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-16 19:00:53 +02:00
|
|
|
login := ctx.Value("login").(*libsystem.Login)
|
|
|
|
|
|
|
|
profil := &Profil{LoginID: login.ID}
|
2017-06-02 10:15:09 +02:00
|
|
|
|
|
|
|
if dbconnection.Where("login = ?", login.ID).First(profil).RecordNotFound() {
|
|
|
|
liblog.Log.Warn("no profil found")
|
|
|
|
libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Fields: []string{"session"}, Message: "no profil found"})
|
2016-10-16 19:00:53 +02:00
|
|
|
return
|
|
|
|
}
|
2017-06-02 10:15:09 +02:00
|
|
|
ctx = context.WithValue(ctx, "profil", profil)
|
|
|
|
r = r.WithContext(ctx)
|
|
|
|
h(w, r)
|
|
|
|
return
|
|
|
|
|
2016-10-16 19:00:53 +02:00
|
|
|
}
|
|
|
|
}
|