From 3a18af50e6ad0edf812b2f6aab9f7da3084fcf31 Mon Sep 17 00:00:00 2001 From: Miles Matthias <miles.matthias@gmail.com> Date: Tue, 7 Jan 2014 10:02:19 -0700 Subject: [PATCH 1/3] ignore swap files --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp From 4f7ac6849e0969d622683f009e57c5e0f56dfff6 Mon Sep 17 00:00:00 2001 From: Miles Matthias <miles.matthias@gmail.com> Date: Tue, 7 Jan 2014 10:02:29 -0700 Subject: [PATCH 2/3] added support for configuring cookie expiration --- README.md | 4 ++++ lib/middleman-gibberish.rb | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ce58fb7..156153a 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,10 @@ USAGE # encrypt at set of pages with a different password gibberish.encrypt 'kayne/**/**', 'i can hold my liquor' + + # choose how many days the cookie is good for + + gibberish.cookie_days = 7 end ``` diff --git a/lib/middleman-gibberish.rb b/lib/middleman-gibberish.rb index ff2e456..95682f6 100644 --- a/lib/middleman-gibberish.rb +++ b/lib/middleman-gibberish.rb @@ -56,6 +56,17 @@ def password=(password) @password = password.to_s end + def cookie_days(*cookie_days) + unless cookie_days.empty? + @cookie_days = cookie_days.first.to_i + end + @cookie_days ||= 1 + end + + def cookie_days=(cookie_days) + @cookie_days = cookie_days.to_i + end + def encrypt(glob, password = nil) @to_encrypt.push([glob, password]) end @@ -154,7 +165,7 @@ def script_for(glob, path, encrypted) document.write(decrypted); try{ - jQuery.cookie(cookie, password, {expires: 1}); + jQuery.cookie(cookie, password, {expires: #{ @cookie_days }}); } catch(e) { }; From 6be499ac56a11addf11173e4afb51c93bc8ffc14 Mon Sep 17 00:00:00 2001 From: Miles Matthias <miles.matthias@gmail.com> Date: Wed, 8 Jan 2014 16:59:00 -0700 Subject: [PATCH 3/3] what if the password changed and your cookie has the old password. yuppers. --- lib/middleman-gibberish.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/middleman-gibberish.rb b/lib/middleman-gibberish.rb index 95682f6..9a95950 100644 --- a/lib/middleman-gibberish.rb +++ b/lib/middleman-gibberish.rb @@ -157,7 +157,8 @@ def script_for(glob, path, encrypted) var cookie = #{ glob.to_json }; while(true){ - var password = (jQuery.cookie(cookie) || prompt('PLEASE ENTER THE PASSWORD')); + var cookie_password = jQuery.cookie(cookie), + password = (cookie_password || prompt('PLEASE ENTER THE PASSWORD')); try{ var decrypted = GibberishAES.dec(encrypted, password); @@ -171,7 +172,9 @@ def script_for(glob, path, encrypted) break; } catch(e) { - if(confirm('BLARGH - WRONG PASSWORD! TRY AGAIN?')){ + if (cookie_password) { + jquery.removeCookie(cookie); // and try again + } else if(confirm('BLARGH - WRONG PASSWORD! TRY AGAIN?')){ 42; } else { break