package web import ( "net/http" "strconv" "context" "goji.io/pat" libapi "dev.sum7.eu/sum7/warehost/lib/api" liblog "dev.sum7.eu/sum7/warehost/lib/log" libsystem "dev.sum7.eu/sum7/warehost/system" ) //InvolveWebsiteHandler for api function to Verifie User ist loggedin func InvolveWebsiteHandler(h libapi.Handle) libapi.Handle { return func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() login := ctx.Value("login").(*libsystem.Login) id, err := strconv.ParseInt(pat.Param(r, "websiteid"), 10, 64) if err == nil { res := dbconnection.Where(map[string]int64{"website": id, "login": login.ID}).Find(&Manager{}) if !res.RecordNotFound() { ctx = context.WithValue(ctx, "websiteid", id) r = r.WithContext(ctx) h(w, r) return } libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Fields: []string{"permission"}, Message: "No permission"}) liblog.Log.Info("no Permissions") return } libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Fields: []string{"websiteid"}, Message: "Not a valid websiteid"}) liblog.Log.Warn("invalid websiteid, no integer") return } }