diff options
-rw-r--r-- | mulkcms.lisp | 3 | ||||
-rw-r--r-- | static-files/js/comment-submission.js | 28 |
2 files changed, 18 insertions, 13 deletions
diff --git a/mulkcms.lisp b/mulkcms.lisp index 40bfc92..8f1e2ce 100644 --- a/mulkcms.lisp +++ b/mulkcms.lisp @@ -30,7 +30,8 @@ (defun hashcash-hash-validp (text) - (let ((digest (ironclad:digest-sequence 'ironclad:sha256 (flexi-streams:string-to-octets text)))) + (let* ((stripped-text (ppcre:regex-replace-all "\\s+" text "")) + (digest (ironclad:digest-sequence 'ironclad:sha256 (flexi-streams:string-to-octets stripped-text :external-format :utf8)))) (every #'zerop (subseq digest 0 2)))) diff --git a/static-files/js/comment-submission.js b/static-files/js/comment-submission.js index 13c3849..59db100 100644 --- a/static-files/js/comment-submission.js +++ b/static-files/js/comment-submission.js @@ -13,28 +13,32 @@ jQuery(function($) { var form_augmented_p = false; $('.comment-form').submit(function() { var form = $(this); - $.ajax({ - url: "/RPC/generate-transaction-key", - dataType: 'json', - success: function(tkey) { - if (!form_augmented_p) { + if (!form_augmented_p) { + $.ajax({ + url: "/RPC/generate-transaction-key", + dataType: 'json', + success: function(tkey) { form.find(':submit').attr("disabled", true); var salt = 0; - var text = form.find('textarea'); + var text = form.find('textarea').val().replace(/\s+/g, ""); while (!acceptable_cashhash(Sha256.hash(text + ":" + tkey + ":" + salt))) { salt++; } form.prepend('<input type="hidden" name="transaction-key" value="' + tkey + '" />'); form.prepend('<input type="hidden" name="salt" value="' + salt + '" />'); form_augmented_p = true; + form.find(':submit').removeAttr("disabled"); + $('.comment-form').submit(); form.submit(); - return false; - } else { - return true; + console.log("tkey = " + tkey); + console.log("salt = " + salt); + console.log("Submitted!"); } - } - }); - return false; + }); + return false; + } else { + return true; + } }); $('.spam-detection-method').text("Hashcash"); $('.irrelevant-for-hashcash').text(''); |