package web import ( "net/http" "strconv" "goji.io/pat" "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" ) //InvolveWebsiteHandler for api function to Verifie User ist loggedin func InvolveWebsiteHandler(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: "Not logged in"} returndata = false id, err := strconv.ParseInt(pat.Param(ctx, "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) returndata, returnerr = h(ctx, w, r) return } returnerr = &libapi.ErrorResult{Fields: []string{"permission"}, Message: "No permission"} liblog.Log.Info("no Permissions") return } returnerr = &libapi.ErrorResult{Fields: []string{"websiteid"}, Message: "Not a valid websiteid"} liblog.Log.Warn("invalid websiteid, no integer") return } }