Merge pull request #11453 from owncloud/enc_visual_improvements

[encryption] some visual improvements
This commit is contained in:
Morris Jobke 2014-10-08 14:36:24 +02:00
commit 6d94a88476
8 changed files with 125 additions and 110 deletions

View File

@ -16,8 +16,28 @@ use OCA\Encryption;
$l = \OC::$server->getL10N('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)));
}

View File

@ -21,6 +21,32 @@ $return = false;
$oldPassword = $_POST['oldPassword'];
$newPassword = $_POST['newPassword'];
$confirmPassword = $_POST['confirmPassword'];
//check if both passwords are the same
if (empty($_POST['oldPassword'])) {
$errorMessage = $l->t('Please provide the old recovery password');
\OCP\JSON::error(array('data' => array('message' => $errorMessage)));
exit();
}
if (empty($_POST['newPassword'])) {
$errorMessage = $l->t('Please provide a new recovery password');
\OCP\JSON::error(array('data' => array('message' => $errorMessage)));
exit();
}
if (empty($_POST['confirmPassword'])) {
$errorMessage = $l->t('Please repeat the new recovery password');
\OCP\JSON::error(array('data' => array('message' => $errorMessage)));
exit();
}
if ($_POST['newPassword'] !== $_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();
}
$view = new \OC\Files\View('/');
$util = new \OCA\Encryption\Util(new \OC\Files\View('/'), \OCP\User::getUser());

View File

@ -13,6 +13,8 @@ use OCA\Encryption;
\OCP\JSON::checkAppEnabled('files_encryption');
\OCP\JSON::callCheck();
$l = \OC::$server->getL10N('files_encryption');
if (
isset($_POST['userEnableRecovery'])
&& (0 == $_POST['userEnableRecovery'] || '1' === $_POST['userEnableRecovery'])
@ -38,4 +40,8 @@ if (
}
// Return success or failure
($return) ? \OCP\JSON::success() : \OCP\JSON::error();
if ($return) {
\OCP\JSON::success(array('data' => array('message' => $l->t('File recovery settings updated'))));
} else {
\OCP\JSON::error(array('data' => array('message' => $l->t('Could not update file recovery'))));
}

View File

@ -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,33 +38,17 @@ $(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();
OC.msg.startSaving('#encryption .msg');
var confirmNewPassword = $('#repeatedNewEncryptionRecoveryPassword').val();
OC.msg.startSaving('#encryptionChangeRecoveryKey .msg');
$.post(
OC.filePath( 'files_encryption', 'ajax', 'changeRecoveryPassword.php' )
, { oldPassword: oldRecoveryPassword, newPassword: newRecoveryPassword }
, { oldPassword: oldRecoveryPassword, newPassword: newRecoveryPassword, confirmPassword: confirmNewPassword }
, function( data ) {
if (data.status == "error") {
OC.msg.finishedSaving('#encryption .msg', data);
} else {
OC.msg.finishedSaving('#encryption .msg', data);
OC.msg.finishedSaving('#encryptionChangeRecoveryKey .msg', data);
}
}
);
});

View File

@ -26,36 +26,27 @@ $(document).ready(function(){
// Trigger ajax on recoveryAdmin status change
$( 'input:radio[name="userEnableRecovery"]' ).change(
function() {
// Hide feedback messages in case they're already visible
$('#recoveryEnabledSuccess').hide();
$('#recoveryEnabledError').hide();
var recoveryStatus = $( this ).val();
OC.msg.startAction('#userEnableRecovery .msg', 'Updating recovery keys. This can take some time...');
$.post(
OC.filePath( 'files_encryption', 'ajax', 'userrecovery.php' )
, { userEnableRecovery: recoveryStatus }
, function( data ) {
if ( data.status == "success" ) {
$('#recoveryEnabledSuccess').show();
} else {
$('#recoveryEnabledError').show();
}
OC.msg.finishedAction('#userEnableRecovery .msg', data);
}
);
// Ensure page is not reloaded on form submit
return false;
}
);
$("#encryptAll").click(
function(){
// Hide feedback messages in case they're already visible
$('#encryptAllSuccess').hide();
$('#encryptAllError').hide();
var userPassword = $( '#userPassword' ).val();
var encryptAll = $( '#encryptAll' ).val();
@ -73,7 +64,7 @@ $(document).ready(function(){
// Ensure page is not reloaded on form submit
return false;
}
);
// update private key password

View File

@ -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"/>
@ -19,7 +20,7 @@
id='adminEnableRecovery'
name='adminEnableRecovery'
value='1'
<?php echo($_["recoveryEnabled"] === '1' ? 'checked="checked"' : 'disabled'); ?> />
<?php echo($_["recoveryEnabled"] === '1' ? 'checked="checked"' : ''); ?> />
<label for="adminEnableRecovery"><?php p($l->t("Enabled")); ?></label>
<br/>
@ -28,13 +29,14 @@
id='adminDisableRecovery'
name='adminEnableRecovery'
value='0'
<?php echo($_["recoveryEnabled"] === '0' ? 'checked="checked"' : 'disabled'); ?> />
<?php echo($_["recoveryEnabled"] === '0' ? 'checked="checked"' : ''); ?> />
<label for="adminDisableRecovery"><?php p($l->t("Disabled")); ?></label>
</p>
<br/><br/>
<p name="changeRecoveryPasswordBlock" <?php if ($_['recoveryEnabled'] === '0') print_unescaped('class="hidden"');?>>
<p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if ($_['recoveryEnabled'] === '0') print_unescaped('class="hidden"');?>>
<strong><?php p($l->t("Change recovery key password:")); ?></strong>
<span class="msg"></span>
<br/><br/>
<input
type="password"
@ -57,10 +59,9 @@
<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>
<?php endif; ?>
</form>

View File

@ -39,8 +39,9 @@
<?php elseif ( $_["recoveryEnabled"] && $_["privateKeySet"] && $_["initialized"] === \OCA\Encryption\Session::INIT_SUCCESSFUL ): ?>
<br />
<p>
<p id="userEnableRecovery">
<label for="userEnableRecovery"><?php p( $l->t( "Enable password recovery:" ) ); ?></label>
<span class="msg"></span>
<br />
<em><?php p( $l->t( "Enabling this option will allow you to reobtain access to your encrypted files in case of password loss" ) ); ?></em>
<br />
@ -60,8 +61,6 @@
value='0'
<?php echo ( $_["recoveryEnabledForUser"] === false ? 'checked="checked"' : '' ); ?> />
<label for="userDisableRecovery"><?php p( $l->t( "Disabled" ) ); ?></label>
<div id="recoveryEnabledSuccess"><?php p( $l->t( 'File recovery settings updated' ) ); ?></div>
<div id="recoveryEnabledError"><?php p( $l->t( 'Could not update file recovery' ) ); ?></div>
</p>
<?php endif; ?>
</form>

View File

@ -198,7 +198,7 @@ var OC={
linkTo:function(app,file){
return OC.filePath(app,'',file);
},
/**
* Creates a relative url for remote use
* @param {string} service id
@ -300,7 +300,7 @@ var OC={
}
return link;
},
/**
* Redirect to the target URL, can also be used for downloads.
* @param {string} targetURL URL to redirect to
@ -308,10 +308,10 @@ var OC={
redirect: function(targetURL) {
window.location = targetURL;
},
/**
* get the absolute path to an image file
* if no extension is given for the image, it will automatically decide
* if no extension is given for the image, it will automatically decide
* between .png and .svg based on what the browser supports
* @param {string} app the app id to which the image belongs
* @param {string} file the name of the image file
@ -323,9 +323,9 @@ var OC={
}
return OC.filePath(app,'img',file);
},
/**
* Load a script for the server and load it. If the script is already loaded,
* Load a script for the server and load it. If the script is already loaded,
* the event handler will be called directly
* @param {string} app the app id to which the script belongs
* @param {string} script the filename of the script
@ -364,21 +364,21 @@ var OC={
}
}
},
/**
* @todo Write the documentation
*/
basename: function(path) {
return path.replace(/\\/g,'/').replace( /.*\//, '' );
},
/**
* @todo Write the documentation
*/
dirname: function(path) {
return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
},
/**
* Do a search query and display the results
* @param {string} query the search query
@ -393,7 +393,7 @@ var OC={
}
}, 500),
dialogs:OCdialogs,
/**
* Parses a URL query string into a JS map
* @param {string} queryString query string in the format param1=1234&param2=abcde&param3=xyz
@ -604,7 +604,7 @@ OC.msg={
startSaving:function(selector){
OC.msg.startAction(selector, t('core', 'Saving...'));
},
/**
* @param selector
* @param data
@ -613,7 +613,7 @@ OC.msg={
finishedSaving:function(selector, data){
OC.msg.finishedAction(selector, data);
},
/**
* @param selector
* @param {string} message Message to display
@ -627,7 +627,7 @@ OC.msg={
.stop(true, true)
.show();
},
/**
* @param selector
* @param data
@ -636,12 +636,17 @@ OC.msg={
finishedAction:function(selector, data){
if( data.status === "success" ){
$(selector).html( data.data.message )
.addClass('success')
.stop(true, true)
.delay(3000)
.fadeOut(900);
.addClass('success')
.removeClass('error')
.stop(true, true)
.delay(3000)
.fadeOut(900)
.show();
}else{
$(selector).html( data.data.message ).addClass('error');
$(selector).html( data.data.message )
.addClass('error')
.removeClass('success')
.show();
}
}
};
@ -652,7 +657,7 @@ OC.msg={
OC.Notification={
queuedNotifications: [],
getDefaultNotificationFunction: null,
/**
* @param callback
* @todo Write documentation
@ -660,7 +665,7 @@ OC.Notification={
setDefault: function(callback) {
OC.Notification.getDefaultNotificationFunction = callback;
},
/**
* Hides a notification
* @param callback
@ -683,7 +688,7 @@ OC.Notification={
}
});
},
/**
* Shows a notification as HTML without being sanitized before.
* If you pass unsanitized user input this may lead to a XSS vulnerability.
@ -699,7 +704,7 @@ OC.Notification={
OC.Notification.queuedNotifications.push(html);
}
},
/**
* Shows a sanitized notification
* @param {string} text Message to display
@ -713,9 +718,9 @@ OC.Notification={
OC.Notification.queuedNotifications.push($('<div/>').text(text).html());
}
},
/**
* Returns whether a notification is hidden.
* Returns whether a notification is hidden.
* @return {boolean}
*/
isHidden: function() {
@ -779,7 +784,7 @@ OC.Breadcrumb={
this._push(container, leafname, leaflink);
}
},
/**
* @todo Write documentation
* @param {string} name
@ -809,7 +814,7 @@ OC.Breadcrumb={
}
return crumb;
},
/**
* @todo Write documentation
*/
@ -820,7 +825,7 @@ OC.Breadcrumb={
this.container.find('div.crumb').last().remove();
this.container.find('div.crumb').last().addClass('last');
},
/**
* @todo Write documentation
*/
@ -841,7 +846,7 @@ if(typeof localStorage !=='undefined' && localStorage !== null){
*/
OC.localStorage={
namespace:'oc_'+OC.currentUser+'_'+OC.webroot+'_',
/**
* Whether the storage contains items
* @param {string} name
@ -850,7 +855,7 @@ if(typeof localStorage !=='undefined' && localStorage !== null){
hasItem:function(name){
return OC.localStorage.getItem(name)!==null;
},
/**
* Add an item to the storage
* @param {string} name
@ -859,7 +864,7 @@ if(typeof localStorage !=='undefined' && localStorage !== null){
setItem:function(name,item){
return localStorage.setItem(OC.localStorage.namespace+name,JSON.stringify(item));
},
/**
* Removes an item from the storage
* @param {string} name
@ -868,7 +873,7 @@ if(typeof localStorage !=='undefined' && localStorage !== null){
removeItem:function(name,item){
return localStorage.removeItem(OC.localStorage.namespace+name);
},
/**
* Get an item from the storage
* @param {string} name
@ -1248,7 +1253,7 @@ function formatDate(timestamp){
return OC.Util.formatDate(timestamp);
}
//
//
/**
* Get the value of a URL parameter
* @link http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery