aboutsummaryrefslogtreecommitdiff
path: root/backend/api
diff options
context:
space:
mode:
authorRyan Mehri <[email protected]>2020-05-10 17:00:46 -0600
committerRyan Mehri <[email protected]>2020-05-10 17:00:46 -0600
commitddbf4935b9b9adffa5f2939e56cb49cbd5139dd1 (patch)
tree1d80075cd661b978ebeb681043b3ad110cdbed7a /backend/api
parentMerge pull request #11 from jackyzha0/pass_and_expiry (diff)
downloadctrl-v-ddbf4935b9b9adffa5f2939e56cb49cbd5139dd1.tar.xz
ctrl-v-ddbf4935b9b9adffa5f2939e56cb49cbd5139dd1.zip
Update post to return hash and password
Diffstat (limited to 'backend/api')
-rw-r--r--backend/api/routes.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/backend/api/routes.go b/backend/api/routes.go
index a65c886..3b08781 100644
--- a/backend/api/routes.go
+++ b/backend/api/routes.go
@@ -23,6 +23,7 @@ func insertFunc(w http.ResponseWriter, r *http.Request) {
expiry := r.FormValue("expiry")
content := r.FormValue("content")
title := r.FormValue("title")
+ password := r.FormValue("password")
// get ip
ip := getIP(r)
@@ -30,11 +31,21 @@ func insertFunc(w http.ResponseWriter, r *http.Request) {
log.Infof("got content '%s' and ip '%s'", content, ip)
// insert content
- err := db.New(ip, content, expiry, title)
+ paste, err := db.New(ip, content, expiry, title, password)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "got err: %s", err.Error())
}
+
+ // if successful return paste hash
+ w.Header().Set("Content-Type", "application/json")
+ pasteMap := map[string]interface{}{
+ "hash": paste.Hash,
+ "password": paste.Password,
+ }
+
+ jsonData, _ := json.Marshal(pasteMap)
+ fmt.Fprintf(w, "%+v", string(jsonData))
}
func getHashFunc(w http.ResponseWriter, r *http.Request) {