diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-10-07 00:24:53 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-10-07 00:24:53 -0700 |
commit | b2e4fd9372f27d3202f07a329a5077b93a4b7390 (patch) | |
tree | 7a00e7753fdf3b4b8f8976e35fb4dd4c564c45a9 /system/admin/handlers.go | |
parent | b5f028f0a720f1d23d2ce79d3e885fcb524bb79a (diff) |
adding cache control and etags to responses for static assets + moved handlers/helper upload func
Diffstat (limited to 'system/admin/handlers.go')
-rw-r--r-- | system/admin/handlers.go | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 3ef0e7d..1e8ba4f 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -5,7 +5,10 @@ import ( "encoding/base64" "encoding/json" "fmt" + "log" "net/http" + "os" + "path/filepath" "strings" "time" @@ -71,7 +74,7 @@ func initHandler(res http.ResponseWriter, req *http.Request) { return } - email := req.FormValue("email") + email := strings.ToLower(req.FormValue("email")) password := req.FormValue("password") usr := user.NewUser(email, password) @@ -216,7 +219,7 @@ func loginHandler(res http.ResponseWriter, req *http.Request) { } // check email & password - j, err := db.User(req.FormValue("email")) + j, err := db.User(strings.ToLower(req.FormValue("email"))) if err != nil { fmt.Println(err) http.Redirect(res, req, req.URL.String(), http.StatusFound) @@ -587,3 +590,35 @@ func searchHandler(res http.ResponseWriter, req *http.Request) { res.Header().Set("Content-Type", "text/html") res.Write(adminView) } + +func staticAssetHandler(res http.ResponseWriter, req *http.Request) { + path := req.URL.Path + pathParts := strings.Split(path, "/")[1:] + pwd, err := os.Getwd() + if err != nil { + log.Fatal("Coudln't get current directory to set static asset source.") + } + + filePathParts := make([]string, len(pathParts)+2, len(pathParts)+2) + filePathParts = append(filePathParts, pwd) + filePathParts = append(filePathParts, "system") + filePathParts = append(filePathParts, pathParts...) + + http.ServeFile(res, req, filepath.Join(filePathParts...)) +} + +func staticUploadHandler(res http.ResponseWriter, req *http.Request) { + path := req.URL.Path + pathParts := strings.Split(path, "/")[2:] + + pwd, err := os.Getwd() + if err != nil { + log.Fatal("Coudln't get current directory to set static asset source.") + } + + filePathParts := make([]string, len(pathParts)+1, len(pathParts)+1) + filePathParts = append(filePathParts, pwd) + filePathParts = append(filePathParts, pathParts...) + + http.ServeFile(res, req, filepath.Join(filePathParts...)) +} |