From d892cad72c1eb4ae20c1b7f1c5b9451650454c28 Mon Sep 17 00:00:00 2001 From: Ryan Mehri Date: Mon, 11 May 2020 20:41:16 -0600 Subject: Add password check on post hash --- backend/api/routes.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'backend/api/routes.go') diff --git a/backend/api/routes.go b/backend/api/routes.go index 7fb2114..6b9ba43 100644 --- a/backend/api/routes.go +++ b/backend/api/routes.go @@ -52,12 +52,25 @@ func insertFunc(w http.ResponseWriter, r *http.Request) { } func getHashFunc(w http.ResponseWriter, r *http.Request) { + // no password given for get + handleGetHash(w, r, "") +} + +func getHashWithPasswordFunc(w http.ResponseWriter, r *http.Request) { + // get password from form + _ = r.ParseMultipartForm(0) + gotPassword := r.FormValue("password") + + handleGetHash(w, r, gotPassword) + +} +func handleGetHash(w http.ResponseWriter, r *http.Request, gotPassword string) { // Allow CORS w.Header().Set("Access-Control-Allow-Origin", "*") hash := mux.Vars(r)["hash"] - paste, err := cache.C.Get(hash) + paste, err := cache.C.Get(hash, gotPassword) // if hash was not found if err == cache.PasteNotFound { -- cgit v1.2.3 From 5f493fbdabad58412fba14b4c9534709d701192e Mon Sep 17 00:00:00 2001 From: Ryan Mehri Date: Mon, 11 May 2020 20:55:49 -0600 Subject: Rename good --- backend/api/routes.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'backend/api/routes.go') diff --git a/backend/api/routes.go b/backend/api/routes.go index 6b9ba43..f8d2e4f 100644 --- a/backend/api/routes.go +++ b/backend/api/routes.go @@ -51,26 +51,26 @@ func insertFunc(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "%+v", string(jsonData)) } -func getHashFunc(w http.ResponseWriter, r *http.Request) { +func getPasteFunc(w http.ResponseWriter, r *http.Request) { // no password given for get - handleGetHash(w, r, "") + handleGetPaste(w, r, "") } -func getHashWithPasswordFunc(w http.ResponseWriter, r *http.Request) { +func getPasteWithPasswordFunc(w http.ResponseWriter, r *http.Request) { // get password from form _ = r.ParseMultipartForm(0) - gotPassword := r.FormValue("password") + parsedPassword := r.FormValue("password") - handleGetHash(w, r, gotPassword) + handleGetPaste(w, r, parsedPassword) } -func handleGetHash(w http.ResponseWriter, r *http.Request, gotPassword string) { +func handleGetPaste(w http.ResponseWriter, r *http.Request, parsedPassword string) { // Allow CORS w.Header().Set("Access-Control-Allow-Origin", "*") hash := mux.Vars(r)["hash"] - paste, err := cache.C.Get(hash, gotPassword) + paste, err := cache.C.Get(hash, parsedPassword) // if hash was not found if err == cache.PasteNotFound { -- cgit v1.2.3