From 9b39fe78ba3fcf723202d96adec96ef7ff95b7f3 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sun, 21 Aug 2016 19:14:52 +0100 Subject: [PATCH] Add current user --- directory/file.go | 22 ++++++++++++++++++++++ page/page.go | 1 + 2 files changed, 23 insertions(+) diff --git a/directory/file.go b/directory/file.go index 726116c8..04146622 100644 --- a/directory/file.go +++ b/directory/file.go @@ -170,6 +170,17 @@ func (i *Info) serveSingleFile(w http.ResponseWriter, r *http.Request, c *config }, } + // Set the current User + user, _, ok := r.BasicAuth() + + if !ok { + page.Info.User = c.UserConfig + } + + if _, ok := c.Users[user]; ok { + page.Info.User = c.Users[user] + } + if CanBeEdited(i.Name) { editor, err := i.GetEditor() @@ -250,6 +261,17 @@ func (i *Info) serveListing(w http.ResponseWriter, r *http.Request, c *config.Co }, } + // Set the current User + user, _, ok := r.BasicAuth() + + if !ok { + page.Info.User = c.UserConfig + } + + if _, ok := c.Users[user]; ok { + page.Info.User = c.Users[user] + } + if r.Header.Get("Minimal") == "true" { page.Minimal = true } diff --git a/page/page.go b/page/page.go index 21ae4804..0da95214 100644 --- a/page/page.go +++ b/page/page.go @@ -25,6 +25,7 @@ type Info struct { Path string IsDir bool Config *config.Config + User *config.UserConfig Data interface{} }