Add password retry feature

This commit is contained in:
rugk 2017-04-11 22:21:30 +02:00
parent 183ebe518b
commit d53207e404
No known key found for this signature in database
GPG Key ID: 05D40A636AFAB34D
5 changed files with 91 additions and 11 deletions

View File

@ -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();
}
}

View File

@ -69,7 +69,7 @@ if ($MARKDOWN):
<?php
endif;
?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-TCwmpH2nrRe3mLYIsGG90FGOFAqZal8SUQVNp16iA7K1B80I//RXp8mYxXdyyk/eluKilwCNY5wo9MYC4vdEoQ==" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-tGE0CigbTPqWg1xkIeJrdAT3U9QsTTI2k/8qviRyBVbyuevBiyM3XBlmpARRjHwv075QSK4h4TuI8TlU9ScS2Q==" crossorigin="anonymous"></script>
<!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]-->
@ -125,6 +125,11 @@ endif;
<?php echo I18n::_('Loading…'), PHP_EOL; ?>
</li>
<li>
<button id="retrybutton" type="button" class="reloadlink hidden btn btn-<?php echo $isDark ? 'warning' : 'primary'; ?> navbar-btn">
<span class="glyphicon glyphicon-repeat" aria-hidden="true"></span> <?php echo I18n::_('Retry'), PHP_EOL; ?>
</button>
</li>
<li>
<?php
if ($isPage):
?>

View File

@ -47,7 +47,7 @@ if ($MARKDOWN):
<?php
endif;
?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-TCwmpH2nrRe3mLYIsGG90FGOFAqZal8SUQVNp16iA7K1B80I//RXp8mYxXdyyk/eluKilwCNY5wo9MYC4vdEoQ==" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-tGE0CigbTPqWg1xkIeJrdAT3U9QsTTI2k/8qviRyBVbyuevBiyM3XBlmpARRjHwv075QSK4h4TuI8TlU9ScS2Q==" crossorigin="anonymous"></script>
<!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]-->

View File

@ -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',

View File

@ -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',