42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package host
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
"context"
|
|
|
|
libapi "dev.sum7.eu/sum7/warehost/lib/api"
|
|
liblog "dev.sum7.eu/sum7/warehost/lib/log"
|
|
libsystem "dev.sum7.eu/sum7/warehost/system"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
//ProfilHandler for api function to get host.Profil
|
|
func ProfilHandler(h libapi.Handle) libapi.Handle {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
login := ctx.Value("login").(*libsystem.Login)
|
|
|
|
profil := &Profil{LoginID: login.ID}
|
|
|
|
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"})
|
|
return
|
|
}
|
|
ctx = context.WithValue(ctx, "profil", profil)
|
|
r = r.WithContext(ctx)
|
|
h(w, r)
|
|
return
|
|
|
|
}
|
|
}
|