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/apiprofil.go

59 lines
1.8 KiB
Go
Raw Normal View History

package host
import (
"net/http"
"strconv"
"goji.io/pat"
"golang.org/x/net/context"
libapi "dev.sum7.eu/sum7/warehost/lib/api"
system "dev.sum7.eu/sum7/warehost/system"
)
func profilList(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
login := ctx.Value("login").(*system.Login)
returndata = false
logger := log.GetLog(r, "toggleReseller")
if !login.Superadmin {
returnerr = &libapi.ErrorResult{Fields: []string{"session"}, Message: "not a superadmin"}
w.WriteHeader(http.StatusUnauthorized)
logger.Warn("not a superadmin")
return
}
var profils []*Profil
dbconnection.Preload("Login").Find(&profils)
returndata = profils
return
}
func toggleReseller(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
login := ctx.Value("login").(*system.Login)
returndata = false
logger := log.GetLog(r, "toggleReseller")
if !login.Superadmin {
returnerr = &libapi.ErrorResult{Fields: []string{"session"}, Message: "not a superadmin"}
w.WriteHeader(http.StatusUnauthorized)
logger.Warn("not a superadmin")
return
}
id, err := strconv.ParseInt(pat.Param(ctx, "id"), 10, 64)
if err != nil {
returnerr = &libapi.ErrorResult{Message: "Error invalid input"}
logger.Warn("invalid userinput, no integer")
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)
returnerr = &libapi.ErrorResult{Message: "Internal Database Error with Database"}
return
}
returndata = true
return
}