diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/README.md b/README.md index d147496..a838f21 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,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..9a95950 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 @@ -146,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); @@ -154,13 +166,15 @@ 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) { }; 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