Skip to content

Commit

Permalink
Merge pull request #2 from DesmondANIMUS/Dev
Browse files Browse the repository at this point in the history
reverted
  • Loading branch information
Gaurav Gogia committed Aug 9, 2017
2 parents 3879090 + b50f369 commit cc5d8d6
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions kazi.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"fmt"
"io"

"encoding/base32"
"encoding/hex"

"golang.org/x/crypto/nacl/secretbox"
Expand All @@ -38,24 +37,13 @@ func init() {
r := mux.NewRouter()

r.HandleFunc("/", index)
r.HandleFunc("/submitMessage", submitMessage)
r.HandleFunc("/msg/", message)

csrf.Protect([]byte(randgen(20)))(r)
csrf.Protect([]byte("32-byte-long-auth-key"))(r)
}

// create a message
func index(w http.ResponseWriter, r *http.Request) {
err := tpl.ExecuteTemplate(w, "index.html", map[string]interface{}{
csrf.TemplateTag: csrf.TemplateField(r),
})

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func submitMessage(w http.ResponseWriter, r *http.Request) {
ctx := appengine.NewContext(r)
var keySystem msgAndSecretKeys

Expand Down Expand Up @@ -83,6 +71,14 @@ func submitMessage(w http.ResponseWriter, r *http.Request) {

err = tpl.ExecuteTemplate(w, "secret.html", keySystem)

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

} else {
err := tpl.ExecuteTemplate(w, "index.html", nil)

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down Expand Up @@ -175,11 +171,3 @@ func generatePassword() [32]byte {

return password
}
func randgen(length int) string {
randomBytes := make([]byte, 32)
_, err := rand.Read(randomBytes)
if err != nil {
panic(err)
}
return base32.StdEncoding.EncodeToString(randomBytes)[:length]
}

0 comments on commit cc5d8d6

Please sign in to comment.