diff options
Diffstat (limited to 'imgs.go')
| -rw-r--r-- | imgs.go | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -17,6 +17,13 @@ const pageSize = 5 func imgs(w http.ResponseWriter, r *http.Request) { u, err := checkSession(w, r) if u != nil && err == nil { + username := u.Username + if u.IsAdmin { + name := r.URL.Query().Get("user") + if name != "" { + username = name + } + } fragment := r.URL.Query().Has("fragment") pageQuery := r.URL.Query().Get("page") if pageQuery == "" { @@ -27,7 +34,7 @@ func imgs(w http.ResponseWriter, r *http.Request) { sendError(w, r, err.Error(), http.StatusInternalServerError) return } - userDocPath := filepath.Join(baseDocDir, u.Username) + userDocPath := filepath.Join(baseDocDir, username) err = os.Mkdir(userDocPath, 0750) if err != nil && !os.IsExist(err) { sendError(w, r, err.Error(), http.StatusInternalServerError) @@ -67,6 +74,7 @@ func imgs(w http.ResponseWriter, r *http.Request) { start = len(imgs) } flasherr := consumeFlash(w, r, "error") + userImpersonation := r.URL.Query().Get("user") data := struct { Imgs []Doc Start int @@ -74,6 +82,7 @@ func imgs(w http.ResponseWriter, r *http.Request) { NbFiles int Page int Error string + UserImpersonation string }{ imgs[start:end], start + 1, @@ -81,6 +90,7 @@ func imgs(w http.ResponseWriter, r *http.Request) { len(imgs), page, flasherr, + userImpersonation, } if fragment { //serveSimple(w, r, data, "templates/imgs_stub.html") @@ -92,7 +102,7 @@ func imgs(w http.ResponseWriter, r *http.Request) { } else if err != nil { log.Println(err) } - sendFlash(w, r, "redirect", "/imgs") + sendFlash(w, r, "redirect", r.URL.String()) http.Redirect(w, r, "/login", http.StatusSeeOther) } |
