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/web/lib.go

39 lines
1.2 KiB
Go
Raw Normal View History

2016-09-01 22:19:39 +02:00
package web
2016-09-03 16:30:48 +02:00
import (
"net/http"
"strconv"
2016-10-11 20:16:24 +02:00
"goji.io/pat"
"golang.org/x/net/context"
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
)
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 {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
2016-10-16 19:00:53 +02:00
login := ctx.Value("login").(libsystem.Login)
returnerr = &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not logged in"}
2016-10-11 20:16:24 +02:00
returndata = false
2016-09-03 16:30:48 +02:00
2016-10-16 19:00:53 +02:00
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)
2016-10-11 20:16:24 +02:00
return
2016-09-03 16:30:48 +02:00
}
2016-10-16 19:00:53 +02:00
returnerr = &libapi.ErrorResult{Fields: []string{"permission"}, Message: "No permission"}
liblog.Log.Info("no Permissions")
2016-10-11 20:16:24 +02:00
return
2016-09-03 16:30:48 +02:00
}
2016-10-16 19:00:53 +02:00
returnerr = &libapi.ErrorResult{Fields: []string{"websiteid"}, Message: "Not a valid websiteid"}
liblog.Log.Warn("invalid websiteid, no integer")
2016-10-11 20:16:24 +02:00
return
2016-09-03 16:30:48 +02:00
}
}