fix (home): user would redirect to the homepath without considering the path in the config

This commit is contained in:
Mickael KERJEAN
2018-11-21 19:32:24 +11:00
parent 0ed846f5f3
commit b0f4310d7d
2 changed files with 13 additions and 6 deletions
+2 -2
View File
@@ -23,7 +23,7 @@ func SessionGet(ctx App, res http.ResponseWriter, req *http.Request) {
SendSuccessResult(res, r)
return
}
home, err := model.GetHome(ctx.Backend)
home, err := model.GetHome(ctx.Backend, ctx.Session["path"])
if err != nil {
SendSuccessResult(res, r)
return
@@ -58,7 +58,7 @@ func SessionAuthenticate(ctx App, res http.ResponseWriter, req *http.Request) {
}
}
home, err := model.GetHome(backend)
home, err := model.GetHome(backend, ctx.Session["path"])
if err != nil {
SendErrorResult(res, err)
return
+11 -4
View File
@@ -4,6 +4,7 @@ import (
"fmt"
. "github.com/mickael-kerjean/nuage/server/common"
_ "github.com/mickael-kerjean/nuage/server/model/backend"
"strings"
)
func NewBackend(ctx *App, conn map[string]string) (IBackend, error) {
@@ -36,13 +37,19 @@ func NewBackend(ctx *App, conn map[string]string) (IBackend, error) {
return Backend.Get(conn["type"]).Init(conn, ctx)
}
func GetHome(b IBackend) (string, error) {
func GetHome(b IBackend, base string) (string, error) {
if obj, ok := b.(interface{ Home() (string, error) }); ok {
return obj.Home()
absolute, err := obj.Home()
if err != nil {
return "", err
}
if strings.HasPrefix(absolute, base) == false {
return "", nil
}
return absolute[len(base):], nil
}
_, err := b.Ls("/")
return "", err
return base, err
}