[Pkg-owncloud-commits] [owncloud] 208/258: improved visual feedback if recovery key gets enabled/disabled

David Prévot taffit at moszumanska.debian.org
Sat Oct 11 17:22:37 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit bdfd3ca2bf95ce5c0deda59b5325ee39152ad0c8
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Tue Oct 7 12:06:46 2014 +0200

    improved visual feedback if recovery key gets enabled/disabled
---
 apps/files_encryption/ajax/adminrecovery.php       | 48 ++++++++++++++--------
 apps/files_encryption/js/settings-admin.js         | 32 ++-------------
 apps/files_encryption/templates/settings-admin.php | 11 ++---
 3 files changed, 41 insertions(+), 50 deletions(-)

diff --git a/apps/files_encryption/ajax/adminrecovery.php b/apps/files_encryption/ajax/adminrecovery.php
index 303ba0e..326b17f 100644
--- a/apps/files_encryption/ajax/adminrecovery.php
+++ b/apps/files_encryption/ajax/adminrecovery.php
@@ -16,8 +16,28 @@ use OCA\Encryption;
 $l = OC_L10N::get('files_encryption');
 
 $return = false;
-// Enable recoveryAdmin
+$errorMessage = $l->t("Unknown error");
+
+//check if both passwords are the same
+if (empty($_POST['recoveryPassword'])) {
+	$errorMessage = $l->t('Missing recovery key password');
+	\OCP\JSON::error(array('data' => array('message' => $errorMessage)));
+	exit();
+}
 
+if (empty($_POST['confirmPassword'])) {
+	$errorMessage = $l->t('Please repeat the recovery key password');
+	\OCP\JSON::error(array('data' => array('message' => $errorMessage)));
+	exit();
+}
+
+if ($_POST['recoveryPassword'] !== $_POST['confirmPassword']) {
+	$errorMessage = $l->t('Repeated recovery key password does not match the provided recovery key password');
+	\OCP\JSON::error(array('data' => array('message' => $errorMessage)));
+	exit();
+}
+
+// Enable recoveryAdmin
 $recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId');
 
 if (isset($_POST['adminEnableRecovery']) && $_POST['adminEnableRecovery'] === '1') {
@@ -26,14 +46,9 @@ if (isset($_POST['adminEnableRecovery']) && $_POST['adminEnableRecovery'] === '1
 
 	// Return success or failure
 	if ($return) {
-		\OCP\JSON::success(array('data' => array('message' => $l->t('Recovery key successfully enabled'))));
+		$successMessage = $l->t('Recovery key successfully enabled');
 	} else {
-		\OCP\JSON::error(array(
-							  'data' => array(
-								  'message' => $l->t(
-									  'Could not enable recovery key. Please check your recovery key password!')
-							  )
-						 ));
+		$errorMessage = $l->t('Could not disable recovery key. Please check your recovery key password!');
 	}
 
 // Disable recoveryAdmin
@@ -43,17 +58,16 @@ if (isset($_POST['adminEnableRecovery']) && $_POST['adminEnableRecovery'] === '1
 ) {
 	$return = \OCA\Encryption\Helper::adminDisableRecovery($_POST['recoveryPassword']);
 
-	// Return success or failure
 	if ($return) {
-		\OCP\JSON::success(array('data' => array('message' => $l->t('Recovery key successfully disabled'))));
+		$successMessage = $l->t('Recovery key successfully disabled');
 	} else {
-		\OCP\JSON::error(array(
-							  'data' => array(
-								  'message' => $l->t(
-									  'Could not disable recovery key. Please check your recovery key password!')
-							  )
-						 ));
+		$errorMessage = $l->t('Could not disable recovery key. Please check your recovery key password!');
 	}
 }
 
-
+// Return success or failure
+if ($return) {
+	\OCP\JSON::success(array('data' => array('message' => $successMessage)));
+} else {
+	\OCP\JSON::error(array('data' => array('message' => $errorMessage)));
+}
diff --git a/apps/files_encryption/js/settings-admin.js b/apps/files_encryption/js/settings-admin.js
index 4c6b1ba..38a5cd1 100644
--- a/apps/files_encryption/js/settings-admin.js
+++ b/apps/files_encryption/js/settings-admin.js
@@ -9,32 +9,21 @@
 
 $(document).ready(function(){
 
-	$('input:password[name="encryptionRecoveryPassword"]').keyup(function(event) {
-		var recoveryPassword = $( '#encryptionRecoveryPassword' ).val();
-		var recoveryPasswordRepeated = $( '#repeatEncryptionRecoveryPassword' ).val();
-		var checkedButton = $('input:radio[name="adminEnableRecovery"]:checked').val();
-		var uncheckedValue = (1+parseInt(checkedButton)) % 2;
-		if (recoveryPassword !== '' && recoveryPassword === recoveryPasswordRepeated) {
-			$('input:radio[name="adminEnableRecovery"][value="'+uncheckedValue.toString()+'"]').removeAttr("disabled");
-		} else {
-			$('input:radio[name="adminEnableRecovery"][value="'+uncheckedValue.toString()+'"]').attr("disabled", "true");
-		}
-	});
-
 	$( 'input:radio[name="adminEnableRecovery"]' ).change(
 		function() {
 			var recoveryStatus = $( this ).val();
 			var oldStatus = (1+parseInt(recoveryStatus)) % 2;
 			var recoveryPassword = $( '#encryptionRecoveryPassword' ).val();
+			var confirmPassword = $( '#repeatEncryptionRecoveryPassword' ).val();
+			OC.msg.startSaving('#encryptionSetRecoveryKey .msg');
 			$.post(
 				OC.filePath( 'files_encryption', 'ajax', 'adminrecovery.php' )
-				, { adminEnableRecovery: recoveryStatus, recoveryPassword: recoveryPassword }
+				, { adminEnableRecovery: recoveryStatus, recoveryPassword: recoveryPassword, confirmPassword: confirmPassword }
 				,  function( result ) {
+					OC.msg.finishedSaving('#encryptionSetRecoveryKey .msg', result);
 					if (result.status === "error") {
-						OC.Notification.show(t('admin', result.data.message));
 						$('input:radio[name="adminEnableRecovery"][value="'+oldStatus.toString()+'"]').attr("checked", "true");
 					} else {
-						OC.Notification.hide();
 						if (recoveryStatus === "0") {
 							$('p[name="changeRecoveryPasswordBlock"]').addClass("hidden");
 						} else {
@@ -49,19 +38,6 @@ $(document).ready(function(){
 
 	// change recovery password
 
-	$('input:password[name="changeRecoveryPassword"]').keyup(function(event) {
-		var oldRecoveryPassword = $('#oldEncryptionRecoveryPassword').val();
-		var newRecoveryPassword = $('#newEncryptionRecoveryPassword').val();
-		var newRecoveryPasswordRepeated = $('#repeatedNewEncryptionRecoveryPassword').val();
-
-		if (newRecoveryPassword !== '' && oldRecoveryPassword !== '' && newRecoveryPassword === newRecoveryPasswordRepeated) {
-			$('button:button[name="submitChangeRecoveryKey"]').removeAttr("disabled");
-		} else {
-			$('button:button[name="submitChangeRecoveryKey"]').attr("disabled", "true");
-		}
-	});
-
-
 	$('button:button[name="submitChangeRecoveryKey"]').click(function() {
 		var oldRecoveryPassword = $('#oldEncryptionRecoveryPassword').val();
 		var newRecoveryPassword = $('#newEncryptionRecoveryPassword').val();
diff --git a/apps/files_encryption/templates/settings-admin.php b/apps/files_encryption/templates/settings-admin.php
index a97261d..acb2671 100644
--- a/apps/files_encryption/templates/settings-admin.php
+++ b/apps/files_encryption/templates/settings-admin.php
@@ -4,8 +4,9 @@
 	<?php if($_["initStatus"] === \OCA\Encryption\Session::NOT_INITIALIZED): ?>
 		<?php p($l->t("Encryption App is enabled but your keys are not initialized, please log-out and log-in again")); ?>
 	<?php else: ?>
-	<p>
+	<p id="encryptionSetRecoveryKey">
 		<?php p($l->t("Enable recovery key (allow to recover users files in case of password loss):")); ?>
+		<span class="msg"></span>
 		<br/>
 		<br/>
 		<input type="password" name="encryptionRecoveryPassword" id="encryptionRecoveryPassword"/>
@@ -18,7 +19,7 @@
 			type='radio'
 			name='adminEnableRecovery'
 			value='1'
-			<?php echo($_["recoveryEnabled"] === '1' ? 'checked="checked"' : 'disabled'); ?> />
+			<?php echo($_["recoveryEnabled"] === '1' ? 'checked="checked"' : ''); ?> />
 		<?php p($l->t("Enabled")); ?>
 		<br/>
 
@@ -26,7 +27,7 @@
 			type='radio'
 			name='adminEnableRecovery'
 			value='0'
-			<?php echo($_["recoveryEnabled"] === '0' ? 'checked="checked"' : 'disabled'); ?> />
+			<?php echo($_["recoveryEnabled"] === '0' ? 'checked="checked"' : ''); ?> />
 		<?php p($l->t("Disabled")); ?>
 	</p>
 	<br/><br/>
@@ -55,8 +56,8 @@
 		<br/>
 		<button
 			type="button"
-			name="submitChangeRecoveryKey"
-			disabled><?php p($l->t("Change Password")); ?>
+			name="submitChangeRecoveryKey">
+				<?php p($l->t("Change Password")); ?>
 		</button>
 		<span class="msg"></span>
 	</p>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list