2016-09-01 22:19:39 +02:00
|
|
|
package web
|
2016-09-03 16:30:48 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
2017-02-20 18:58:53 +01:00
|
|
|
"strings"
|
2016-09-03 16:30:48 +02:00
|
|
|
|
2016-12-19 12:24:18 +01:00
|
|
|
"context"
|
2017-02-20 18:58:53 +01:00
|
|
|
|
2016-10-11 20:16:24 +02:00
|
|
|
"goji.io/pat"
|
2016-09-03 16:30:48 +02:00
|
|
|
|
2016-10-11 20:16:24 +02:00
|
|
|
libapi "dev.sum7.eu/sum7/warehost/lib/api"
|
|
|
|
liblog "dev.sum7.eu/sum7/warehost/lib/log"
|
|
|
|
libsystem "dev.sum7.eu/sum7/warehost/system"
|
2016-09-03 16:30:48 +02:00
|
|
|
)
|
|
|
|
|
2017-02-20 18:58:53 +01:00
|
|
|
func FixPath(path string) string {
|
|
|
|
return strings.ToLower(strings.Trim(path, "/ "))
|
|
|
|
}
|
|
|
|
|
2016-10-16 19:00:53 +02:00
|
|
|
//InvolveWebsiteHandler for api function to Verifie User ist loggedin
|
2016-10-11 20:16:24 +02:00
|
|
|
func InvolveWebsiteHandler(h libapi.Handle) libapi.Handle {
|
2016-12-19 12:24:18 +01:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := r.Context()
|
2016-10-18 19:28:57 +02:00
|
|
|
login := ctx.Value("login").(*libsystem.Login)
|
2016-09-03 16:30:48 +02:00
|
|
|
|
2016-12-19 12:24:18 +01:00
|
|
|
id, err := strconv.ParseInt(pat.Param(r, "websiteid"), 10, 64)
|
2016-10-16 19:00:53 +02:00
|
|
|
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)
|
2016-12-19 12:24:18 +01:00
|
|
|
r = r.WithContext(ctx)
|
|
|
|
h(w, r)
|
2016-10-11 20:16:24 +02:00
|
|
|
return
|
2016-09-03 16:30:48 +02:00
|
|
|
}
|
2016-12-19 12:24:18 +01:00
|
|
|
libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Fields: []string{"permission"}, Message: "No permission"})
|
2016-10-16 19:00:53 +02:00
|
|
|
liblog.Log.Info("no Permissions")
|
2016-10-11 20:16:24 +02:00
|
|
|
return
|
2016-09-03 16:30:48 +02:00
|
|
|
}
|
2016-12-19 12:24:18 +01:00
|
|
|
libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Fields: []string{"websiteid"}, Message: "Not a valid websiteid"})
|
2016-10-16 19:00:53 +02:00
|
|
|
liblog.Log.Warn("invalid websiteid, no integer")
|
2016-10-11 20:16:24 +02:00
|
|
|
return
|
2016-09-03 16:30:48 +02:00
|
|
|
}
|
|
|
|
}
|