31 lines
872 B
Go
31 lines
872 B
Go
package host
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
libapi "dev.sum7.eu/sum7/warehost/lib/api"
|
|
liblog "dev.sum7.eu/sum7/warehost/lib/log"
|
|
libsystem "dev.sum7.eu/sum7/warehost/system"
|
|
)
|
|
|
|
//ProfilHandler for api function to get host.Profil
|
|
func ProfilHandler(h libapi.Handle) libapi.Handle {
|
|
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
|
login := ctx.Value("login").(*libsystem.Login)
|
|
returnerr = &libapi.ErrorResult{Fields: []string{"session"}, Message: "no profil found"}
|
|
returndata = false
|
|
|
|
profil := &Profil{LoginID: login.ID}
|
|
dbconnection.Where("login = ?", login.ID).Find(profil)
|
|
if profil.ID > 0 {
|
|
ctx = context.WithValue(ctx, "profil", profil)
|
|
returndata, returnerr = h(ctx, w, r)
|
|
return
|
|
}
|
|
liblog.Log.Warn("no profil found")
|
|
return
|
|
}
|
|
}
|