package host import ( "net/http" "strconv" "goji.io/pat" libapi "dev.sum7.eu/sum7/warehost/lib/api" system "dev.sum7.eu/sum7/warehost/system" ) func profilList(w http.ResponseWriter, r *http.Request) { ctx := r.Context() login := ctx.Value("login").(*system.Login) logger := log.GetLog(r, "toggleReseller") if !login.Superadmin { logger.Warn("not a superadmin") w.WriteHeader(http.StatusUnauthorized) libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Fields: []string{"session"}, Message: "not a superadmin"}) return } var profils []*Profil dbconnection.Preload("Login").Find(&profils) libapi.JSONWrite(w, r, profils, nil) } func toggleReseller(w http.ResponseWriter, r *http.Request) { ctx := r.Context() login := ctx.Value("login").(*system.Login) logger := log.GetLog(r, "toggleReseller") if !login.Superadmin { logger.Warn("not a superadmin") w.WriteHeader(http.StatusUnauthorized) libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Fields: []string{"session"}, Message: "not a superadmin"}) return } id, err := strconv.ParseInt(pat.Param(r, "id"), 10, 64) if err != nil { logger.Warn("invalid userinput, no integer") libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Message: "Error invalid input"}) return } logger = logger.WithField("id", id) var profil = Profil{ID: id} dbconnection.Where("id = ?", profil.ID).First(&profil) profil.Reseller = !profil.Reseller if err := dbconnection.Save(profil).Error; err != nil { logger.Error("database: during modify host profil: ", err) w.WriteHeader(http.StatusInternalServerError) libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Message: "Internal Database Error with Database"}) return } libapi.JSONWrite(w, r, true, nil) }