Skip to content

Commit

Permalink
Merge pull request #5 from DesmondANIMUS/Dev
Browse files Browse the repository at this point in the history
removed
  • Loading branch information
Gaurav Gogia committed Aug 9, 2017
2 parents a4d54c2 + 7f6244b commit 53bff58
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
3 changes: 1 addition & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<!Doctype html>
<html>
<body>
<form method="POST">
{{ .csrfField }}
<form method="POST">
<label> Message: <textarea name="umsg"> </textarea> </label>
<input type="submit" name="send-msg" value="Send Message"/>
</form>
Expand Down
24 changes: 3 additions & 21 deletions kazi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ import (
"net/http"
"time"

"github.com/gorilla/csrf"

"github.com/gorilla/mux"
uuid "github.com/nu7hatch/gouuid"

"strings"

"fmt"
"io"

"encoding/base32"
"encoding/hex"

"golang.org/x/crypto/nacl/secretbox"
Expand All @@ -35,12 +31,8 @@ var tpl *template.Template
func init() {
tpl = template.Must(template.ParseGlob("./*.html"))

r := mux.NewRouter()

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

csrf.Protect([]byte(randgen(20)))(r)
http.HandleFunc("/", index)
http.HandleFunc("/msg/", message)
}

// create a message
Expand Down Expand Up @@ -77,9 +69,7 @@ func index(w http.ResponseWriter, r *http.Request) {
return
}
} else {
err := tpl.ExecuteTemplate(w, "index.html", map[string]interface{}{
csrf.TemplateTag: csrf.TemplateField(r),
})
err := tpl.ExecuteTemplate(w, "index.html", nil)

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down Expand Up @@ -173,11 +163,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 53bff58

Please sign in to comment.