mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-08 00:02:49 +01:00
Improve user info (#47)
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/arangodb/go-driver"
|
||||
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
"github.com/SecurityBrewery/catalyst/database/busdb"
|
||||
"github.com/SecurityBrewery/catalyst/generated/api"
|
||||
"github.com/SecurityBrewery/catalyst/generated/model"
|
||||
"github.com/SecurityBrewery/catalyst/generated/pointer"
|
||||
"github.com/SecurityBrewery/catalyst/hooks"
|
||||
"github.com/SecurityBrewery/catalyst/role"
|
||||
"github.com/SecurityBrewery/catalyst/test"
|
||||
@@ -39,12 +41,35 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, _ = theCatalyst.DB.UserCreate(context.Background(), &model.UserForm{ID: "eve", Roles: []string{"admin"}})
|
||||
_ = theCatalyst.DB.UserDataCreate(context.Background(), "eve", &model.UserData{
|
||||
Name: pointer.String("Eve"),
|
||||
Email: pointer.String("eve@example.com"),
|
||||
Image: &avatarEve,
|
||||
})
|
||||
_, _ = theCatalyst.DB.UserCreate(context.Background(), &model.UserForm{ID: "kevin", Roles: []string{"admin"}})
|
||||
_ = theCatalyst.DB.UserDataCreate(context.Background(), "kevin", &model.UserData{
|
||||
Name: pointer.String("Kevin"),
|
||||
Email: pointer.String("kevin@example.com"),
|
||||
Image: &avatarKevin,
|
||||
})
|
||||
|
||||
// proxy static requests
|
||||
middlewares := []func(next http.Handler) http.Handler{
|
||||
catalyst.Authenticate(theCatalyst.DB, config.Auth),
|
||||
catalyst.AuthorizeBlockedUser(),
|
||||
}
|
||||
theCatalyst.Server.With(middlewares...).NotFound(api.Proxy("http://localhost:8080"))
|
||||
theCatalyst.Server.With(middlewares...).NotFound(func(writer http.ResponseWriter, request *http.Request) {
|
||||
var handler http.Handler = http.HandlerFunc(api.Proxy("http://localhost:8080/static/"))
|
||||
|
||||
if strings.HasPrefix(request.URL.Path, "/static/") {
|
||||
handler = http.StripPrefix("/static/", handler)
|
||||
} else {
|
||||
request.URL.Path = "/"
|
||||
}
|
||||
|
||||
handler.ServeHTTP(writer, request)
|
||||
})
|
||||
|
||||
if err := http.ListenAndServe(":8000", theCatalyst.Server); err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user