From d53207e4043351706734e924512fa9f399d040f4 Mon Sep 17 00:00:00 2001 From: rugk Date: Tue, 11 Apr 2017 22:21:30 +0200 Subject: [PATCH] Add password retry feature --- js/privatebin.js | 91 ++++++++++++++++++++++++--- tpl/bootstrap.php | 7 ++- tpl/page.php | 2 +- vendor/composer/autoload_classmap.php | 1 + vendor/composer/autoload_static.php | 1 + 5 files changed, 91 insertions(+), 11 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 2d7ead1..feebec3 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -460,7 +460,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { // file is loaded } - // for all other langauges than English for which this behaviour + // for all other languages than English for which this behaviour // is expected as it is built-in, log error if (language !== null && language !== 'en') { console.error('Missing translation for: \'' + messageId + '\' in language ' + language); @@ -1533,6 +1533,21 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { return password; } + /** + * resets the password to an empty string + * + * @name Prompt.reset + * @function + */ + me.reset = function() + { + // reset internal + password = ''; + + // and also reset UI + $passwordDecrypt.val(''); + } + /** * init status manager * @@ -2510,9 +2525,11 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $password, $passwordInput, $rawTextButton, - $sendButton; + $sendButton, + $retryButton; - var pasteExpiration = '1week'; + var pasteExpiration = '1week', + retryButtonCallback; /** * set the expiration on bootstrap templates in dropdown @@ -2663,6 +2680,19 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { Controller.newPaste(); } + /** + * retrys some callback registered before + * + * @name TopNav.clickRetryButton + * @private + * @function + * @param {Event} event + */ + function clickRetryButton(event) + { + retryButtonCallback(); + } + /** * removes the existing attachment * @@ -2720,8 +2750,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { return; } - $newButton.addClass('hidden'); $cloneButton.addClass('hidden'); + $newButton.addClass('hidden'); $rawTextButton.addClass('hidden'); viewButtonsDisplayed = false; @@ -2752,14 +2782,14 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { return; } - $sendButton.removeClass('hidden'); + $attach.removeClass('hidden'); + $burnAfterReadingOption.removeClass('hidden'); $expiration.removeClass('hidden'); $formatter.removeClass('hidden'); - $burnAfterReadingOption.removeClass('hidden'); - $openDiscussionOption.removeClass('hidden'); $newButton.removeClass('hidden'); + $openDiscussionOption.removeClass('hidden'); $password.removeClass('hidden'); - $attach.removeClass('hidden'); + $sendButton.removeClass('hidden'); createButtonsDisplayed = true; } @@ -2800,6 +2830,28 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $newButton.removeClass('hidden'); } + /** + * only shows the "retry" button + * + * @name TopNav.showRetryButton + * @function + */ + me.showRetryButton = function() + { + $retryButton.removeClass('hidden'); + } + + /** + * hides the "retry" button + * + * @name TopNav.hideRetryButton + * @function + */ + me.hideRetryButton = function() + { + $retryButton.addClass('hidden'); + } + /** * only hides the clone button * @@ -2947,6 +2999,18 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { return $customAttachment; } + /** + * Set a function to call when the retry button is clicked. + * + * @name TopNav.setRetryCallback + * @function + * @param {function} callback + */ + me.setRetryCallback = function(callback) + { + retryButtonCallback = callback; + } + /** * init navigation manager * @@ -2972,6 +3036,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $password = $('#password'); $passwordInput = $('#passwordinput'); $rawTextButton = $('#rawtextbutton'); + $retryButton = $('#retrybutton'); $sendButton = $('#sendbutton'); // bootstrap template drop down @@ -2986,6 +3051,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $sendButton.click(PasteEncrypter.sendPaste); $cloneButton.click(Controller.clonePaste); $rawTextButton.click(rawText); + $retryButton.click(clickRetryButton); $fileRemoveButton.click(removeAttachment); // bootstrap template drop downs @@ -3796,6 +3862,9 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { */ me.run = function(paste) { + // in case the button has been there previously + TopNav.hideRetryButton(); + Alert.hideMessages(); Alert.showLoading('Decrypting paste…', 0, 'cloud-download'); // @TODO icon maybe rotation-lock, but needs full Glyphicons @@ -3845,7 +3914,11 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { // log and show error console.error(err); - Alert.showError('Could not decrypt data (Wrong key?)'); + Alert.showError('Could not decrypt data. Did you enter a wrong password? Retry with the button at the top.'); + // reset password, so it can be re-entered and sow retry button + Prompt.reset(); + TopNav.setRetryCallback(me.run); + TopNav.showRetryButton(); } } diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 6d1214e..2655d0d 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + @@ -125,6 +125,11 @@ endif;
  • + +
  • +
  • diff --git a/tpl/page.php b/tpl/page.php index e4d75f4..0e070ea 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - + diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index ceb98f9..8f36d52 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -23,6 +23,7 @@ return array( 'PrivateBin\\Model\\Comment' => $baseDir . '/lib/Model/Comment.php', 'PrivateBin\\Model\\Paste' => $baseDir . '/lib/Model/Paste.php', 'PrivateBin\\Persistence\\AbstractPersistence' => $baseDir . '/lib/Persistence/AbstractPersistence.php', + 'PrivateBin\\Persistence\\DataStore' => $baseDir . '/lib/Persistence/DataStore.php', 'PrivateBin\\Persistence\\PurgeLimiter' => $baseDir . '/lib/Persistence/PurgeLimiter.php', 'PrivateBin\\Persistence\\ServerSalt' => $baseDir . '/lib/Persistence/ServerSalt.php', 'PrivateBin\\Persistence\\TrafficLimiter' => $baseDir . '/lib/Persistence/TrafficLimiter.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 001a248..bc6ffd2 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -52,6 +52,7 @@ class ComposerStaticInitDontChange 'PrivateBin\\Model\\Comment' => __DIR__ . '/../..' . '/lib/Model/Comment.php', 'PrivateBin\\Model\\Paste' => __DIR__ . '/../..' . '/lib/Model/Paste.php', 'PrivateBin\\Persistence\\AbstractPersistence' => __DIR__ . '/../..' . '/lib/Persistence/AbstractPersistence.php', + 'PrivateBin\\Persistence\\DataStore' => __DIR__ . '/../..' . '/lib/Persistence/DataStore.php', 'PrivateBin\\Persistence\\PurgeLimiter' => __DIR__ . '/../..' . '/lib/Persistence/PurgeLimiter.php', 'PrivateBin\\Persistence\\ServerSalt' => __DIR__ . '/../..' . '/lib/Persistence/ServerSalt.php', 'PrivateBin\\Persistence\\TrafficLimiter' => __DIR__ . '/../..' . '/lib/Persistence/TrafficLimiter.php',