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/modul/host/lib.go

31 lines
785 B
Go
Raw Normal View History

2016-10-16 19:00:53 +02:00
package host
import (
"net/http"
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"
)
//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}
2016-10-17 11:54:35 +02:00
dbconnection.Where("login = ?", login.ID).Find(profil)
if profil.ID > 0 {
2016-10-16 19:00:53 +02:00
ctx = context.WithValue(ctx, "profil", profil)
2016-12-19 12:24:18 +01:00
r = r.WithContext(ctx)
h(w, r)
2016-10-16 19:00:53 +02:00
return
}
liblog.Log.Warn("no profil found")
2016-12-19 12:24:18 +01:00
libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Fields: []string{"session"}, Message: "no profil found"})
2016-10-16 19:00:53 +02:00
}
}