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

48 lines
1.5 KiB
Go

package web
import (
"net/http"
"strconv"
"github.com/astaxie/session"
"goji.io/pat"
"golang.org/x/net/context"
libapi "dev.sum7.eu/sum7/warehost/lib/api"
liblog "dev.sum7.eu/sum7/warehost/lib/log"
libsystem "dev.sum7.eu/sum7/warehost/system"
)
//InvolveWebsiteHandler for api function to Verifie User ist libloggedin
func InvolveWebsiteHandler(h libapi.Handle) libapi.Handle {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
sess := ctx.Value("session").(session.Session)
returnerr = &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not liblogged in"}
returndata = false
if login := sess.Get("login"); login != nil {
if loginObj := login.(libsystem.Login); loginObj.Active {
id, err := strconv.ParseInt(pat.Param(ctx, "websiteid"), 10, 64)
if err == nil {
res := dbconnection.Where(map[string]int64{"website": id, "login": loginObj.ID}).Find(&Manager{})
if !res.RecordNotFound() {
ctx = context.WithValue(ctx, "websiteid", id)
returndata, returnerr = h(ctx, w, r)
return
}
returnerr = &libapi.ErrorResult{Fields: []string{"permission"}, Message: "No permission"}
liblog.Log.Info("no Permissions")
return
}
returnerr = &libapi.ErrorResult{Fields: []string{"websiteid"}, Message: "Not a valid websiteid"}
liblog.Log.Warn("invalid websiteid, no integer")
return
}
liblog.Log.Warn("user not active")
return
}
liblog.Log.Warn("not libloggedin")
return
}
}