45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package web
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"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"
|
|
)
|
|
|
|
func FixPath(path string) string {
|
|
return strings.ToLower(strings.Trim(path, "/ "))
|
|
}
|
|
|
|
//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
|
|
}
|
|
}
|