remove status's and adjust js

This commit is contained in:
Clark Tomlinson 2015-04-22 10:41:47 -04:00
parent 1747117edf
commit e3ec1a8bb8
3 changed files with 89 additions and 68 deletions

View File

@ -91,14 +91,14 @@ class RecoveryController extends Controller {
if (isset($adminEnableRecovery) && $adminEnableRecovery === '1') { if (isset($adminEnableRecovery) && $adminEnableRecovery === '1') {
if ($this->recovery->enableAdminRecovery($recoveryPassword)) { if ($this->recovery->enableAdminRecovery($recoveryPassword)) {
return new DataResponse(['status' => 'success', 'data' => array('message' => (string)$this->l->t('Recovery key successfully enabled'))]); return new DataResponse(['data' => ['message' => (string)$this->l->t('Recovery key successfully enabled')]]);
} }
return new DataResponse(['data' => array('message' => (string)$this->l->t('Could not enable recovery key. Please check your recovery key password!'))], 500); return new DataResponse(['data' => ['message' => (string)$this->l->t('Could not enable recovery key. Please check your recovery key password!')]], 500);
} elseif (isset($adminEnableRecovery) && $adminEnableRecovery === '0') { } elseif (isset($adminEnableRecovery) && $adminEnableRecovery === '0') {
if ($this->recovery->disableAdminRecovery($recoveryPassword)) { if ($this->recovery->disableAdminRecovery($recoveryPassword)) {
return new DataResponse(['data' => array('message' => (string)$this->l->t('Recovery key successfully disabled'))]); return new DataResponse(['data' => ['message' => (string)$this->l->t('Recovery key successfully disabled')]]);
} }
return new DataResponse(['data' => array('message' => (string)$this->l->t('Could not disable recovery key. Please check your recovery key password!'))], 500); return new DataResponse(['data' => ['message' => (string)$this->l->t('Could not disable recovery key. Please check your recovery key password!')]], 500);
} }
// this response should never be sent but just in case. // this response should never be sent but just in case.
return new DataResponse(['data' => ['message' => (string)$this->l->t('Missing parameters')]], 500); return new DataResponse(['data' => ['message' => (string)$this->l->t('Missing parameters')]], 500);
@ -114,22 +114,22 @@ class RecoveryController extends Controller {
//check if both passwords are the same //check if both passwords are the same
if (empty($oldPassword)) { if (empty($oldPassword)) {
$errorMessage = (string)$this->l->t('Please provide the old recovery password'); $errorMessage = (string)$this->l->t('Please provide the old recovery password');
return new DataResponse(array('data' => array('message' => $errorMessage)), 500); return new DataResponse(['data' => ['message' => $errorMessage]], 500);
} }
if (empty($newPassword)) { if (empty($newPassword)) {
$errorMessage = (string)$this->l->t('Please provide a new recovery password'); $errorMessage = (string)$this->l->t('Please provide a new recovery password');
return new DataResponse (array('data' => array('message' => $errorMessage)), 500); return new DataResponse (['data' => ['message' => $errorMessage]], 500);
} }
if (empty($confirmPassword)) { if (empty($confirmPassword)) {
$errorMessage = (string)$this->l->t('Please repeat the new recovery password'); $errorMessage = (string)$this->l->t('Please repeat the new recovery password');
return new DataResponse(array('data' => array('message' => $errorMessage)), 500); return new DataResponse(['data' => ['message' => $errorMessage]], 500);
} }
if ($newPassword !== $confirmPassword) { if ($newPassword !== $confirmPassword) {
$errorMessage = (string)$this->l->t('Repeated recovery key password does not match the provided recovery key password'); $errorMessage = (string)$this->l->t('Repeated recovery key password does not match the provided recovery key password');
return new DataResponse(array('data' => array('message' => $errorMessage)), 500); return new DataResponse(['data' => ['message' => $errorMessage]], 500);
} }
$result = $this->recovery->changeRecoveryKeyPassword($newPassword, $result = $this->recovery->changeRecoveryKeyPassword($newPassword,
@ -137,19 +137,18 @@ class RecoveryController extends Controller {
if ($result) { if ($result) {
return new DataResponse( return new DataResponse(
array( [
'status' => 'success',
'data' => [ 'data' => [
'message' => (string)$this->l->t('Password successfully changed.')] 'message' => (string)$this->l->t('Password successfully changed.')]
) ]
); );
} }
return new DataResponse( return new DataResponse(
array( [
'data' => [ 'data' => [
'message' => (string)$this->l->t('Could not change the password. Maybe the old password was not correct.') 'message' => (string)$this->l->t('Could not change the password. Maybe the old password was not correct.')
] ]
), 500); ], 500);
} }
/** /**
@ -164,22 +163,29 @@ class RecoveryController extends Controller {
$result = $this->recovery->setRecoveryForUser($userEnableRecovery); $result = $this->recovery->setRecoveryForUser($userEnableRecovery);
if ($result) { if ($result) {
if ($userEnableRecovery === '0') {
return new DataResponse(
[
'data' => [
'message' => (string)$this->l->t('Recovery Key disabled')]
]
);
}
return new DataResponse( return new DataResponse(
array( [
'status' => 'success',
'data' => [ 'data' => [
'message' => (string)$this->l->t('Recovery Key enabled')] 'message' => (string)$this->l->t('Recovery Key enabled')]
) ]
); );
} }
} }
return new DataResponse( return new DataResponse(
array( [
'data' => [ 'data' => [
'message' => (string)$this->l->t('Could not enable the recovery key, please try again or contact your administrator') 'message' => (string)$this->l->t('Could not enable the recovery key, please try again or contact your administrator')
] ]
), 500); ], 500);
} }
} }

View File

@ -7,52 +7,59 @@
* See the COPYING-README file. * See the COPYING-README file.
*/ */
$(document).ready(function(){ $(document).ready(function () {
$( 'input:radio[name="adminEnableRecovery"]' ).change( $('input:radio[name="adminEnableRecovery"]').change(
function() { function () {
var recoveryStatus = $( this ).val(); var recoveryStatus = $(this).val();
var oldStatus = (1+parseInt(recoveryStatus, 10)) % 2; var oldStatus = (1 + parseInt(recoveryStatus)) % 2;
var recoveryPassword = $( '#encryptionRecoveryPassword' ).val(); var recoveryPassword = $('#encryptionRecoveryPassword').val();
var confirmPassword = $( '#repeatEncryptionRecoveryPassword' ).val(); var confirmPassword = $('#repeatEncryptionRecoveryPassword').val();
OC.msg.startSaving('#encryptionSetRecoveryKey .msg'); OC.msg.startSaving('#encryptionSetRecoveryKey .msg');
$.post( $.post(
OC.generateUrl('/apps/encryption/ajax/adminRecovery'), OC.generateUrl('/apps/encryption/ajax/adminRecovery'),
{ adminEnableRecovery: recoveryStatus, {
adminEnableRecovery: recoveryStatus,
recoveryPassword: recoveryPassword, recoveryPassword: recoveryPassword,
confirmPassword: confirmPassword }, confirmPassword: confirmPassword
function( result ) {
OC.msg.finishedSaving('#encryptionSetRecoveryKey .msg', result);
if (result.status === "error") {
$('input:radio[name="adminEnableRecovery"][value="'+oldStatus.toString()+'"]')
.attr("checked", "true");
} else {
if (recoveryStatus === "0") {
$('p[name="changeRecoveryPasswordBlock"]').addClass("hidden");
} else {
$('input:password[name="changeRecoveryPassword"]').val("");
$('p[name="changeRecoveryPasswordBlock"]').removeClass("hidden");
}
}
} }
); ).done(function (data) {
OC.msg.finishedSuccess('#encryptionSetRecoveryKey .msg', data.data.message);
if (recoveryStatus === "0") {
$('p[name="changeRecoveryPasswordBlock"]').addClass("hidden");
} else {
$('input:password[name="changeRecoveryPassword"]').val("");
$('p[name="changeRecoveryPasswordBlock"]').removeClass("hidden");
}
})
.fail(function (jqXHR) {
$('input:radio[name="adminEnableRecovery"][value="' + oldStatus.toString() + '"]').attr("checked", "true");
OC.msg.finishedError('#encryptionSetRecoveryKey .msg', JSON.parse(jqXHR.responseText).data.message);
});
} }
); );
// change recovery password // change recovery password
$('button:button[name="submitChangeRecoveryKey"]').click(function() { $('button:button[name="submitChangeRecoveryKey"]').click(function () {
var oldRecoveryPassword = $('#oldEncryptionRecoveryPassword').val(); var oldRecoveryPassword = $('#oldEncryptionRecoveryPassword').val();
var newRecoveryPassword = $('#newEncryptionRecoveryPassword').val(); var newRecoveryPassword = $('#newEncryptionRecoveryPassword').val();
var confirmNewPassword = $('#repeatedNewEncryptionRecoveryPassword').val(); var confirmNewPassword = $('#repeatedNewEncryptionRecoveryPassword').val();
OC.msg.startSaving('#encryptionChangeRecoveryKey .msg'); OC.msg.startSaving('#encryptionChangeRecoveryKey .msg');
$.post( $.post(
OC.generateUrl('/apps/encryption/ajax/changeRecoveryPassword'), OC.generateUrl('/apps/encryption/ajax/changeRecoveryPassword'),
{ oldPassword: oldRecoveryPassword, newPassword: newRecoveryPassword, confirmPassword: confirmNewPassword }, {
function( data ) { oldPassword: oldRecoveryPassword,
OC.msg.finishedSaving('#encryptionChangeRecoveryKey .msg', data); newPassword: newRecoveryPassword,
} confirmPassword: confirmNewPassword
); }
).done(function (data) {
OC.msg.finishedSuccess('#encryptionChangeRecoveryKey .msg', data.data.message);
})
.fail(function (jqXHR) {
OC.msg.finishedError('#encryptionChangeRecoveryKey .msg', JSON.parse(jqXHR.responseText).data.message);
});
}); });
}); });

View File

@ -9,35 +9,43 @@ if (!OC.Encryption) {
} }
OC.Encryption = { OC.Encryption = {
updatePrivateKeyPassword: function() { updatePrivateKeyPassword: function () {
var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val(); var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val();
var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val(); var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val();
OC.msg.startSaving('#encryption .msg'); OC.msg.startSaving('#encryption .msg');
$.post( $.post(
OC.generateUrl('/apps/encryption/ajax/updatePrivateKeyPassword'), OC.generateUrl('/apps/encryption/ajax/updatePrivateKeyPassword'),
{oldPassword: oldPrivateKeyPassword, newPassword: newPrivateKeyPassword} {
).success(function (response) { oldPassword: oldPrivateKeyPassword,
OC.msg.finishedSuccess('#encryption .msg', response.message); newPassword: newPrivateKeyPassword
}).fail(function (response) { }
OC.msg.finishedError('#encryption .msg', response.responseJSON.message); ).done(function (data) {
}); OC.msg.finishedSuccess('#encryption .msg', data.data.message);
})
.fail(function (jqXHR) {
OC.msg.finishedError('#encryption .msg', JSON.parse(jqXHR.responseText).data.message);
});
} }
}; };
$(document).ready(function(){ $(document).ready(function () {
// Trigger ajax on recoveryAdmin status change // Trigger ajax on recoveryAdmin status change
$( 'input:radio[name="userEnableRecovery"]' ).change( $('input:radio[name="userEnableRecovery"]').change(
function() { function () {
var recoveryStatus = $( this ).val(); var recoveryStatus = $(this).val();
OC.msg.startAction('#userEnableRecovery .msg', 'Updating recovery keys. This can take some time...'); OC.msg.startAction('#userEnableRecovery .msg', 'Updating recovery keys. This can take some time...');
$.post( $.post(
OC.generateUrl('/apps/encryption/ajax/userSetRecovery'), OC.generateUrl('/apps/encryption/ajax/userSetRecovery'),
{ userEnableRecovery: recoveryStatus }, {
function( data ) { userEnableRecovery: recoveryStatus
OC.msg.finishedAction('#userEnableRecovery .msg', data);
} }
); ).done(function (data) {
OC.msg.finishedSuccess('#userEnableRecovery .msg', data.data.message);
})
.fail(function (jqXHR) {
OC.msg.finishedError('#userEnableRecovery .msg', JSON.parse(jqXHR.responseText).data.message);
});
// Ensure page is not reloaded on form submit // Ensure page is not reloaded on form submit
return false; return false;
} }
@ -45,12 +53,12 @@ $(document).ready(function(){
// update private key password // update private key password
$('input:password[name="changePrivateKeyPassword"]').keyup(function(event) { $('input:password[name="changePrivateKeyPassword"]').keyup(function (event) {
var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val(); var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val();
var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val(); var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val();
if (newPrivateKeyPassword !== '' && oldPrivateKeyPassword !== '' ) { if (newPrivateKeyPassword !== '' && oldPrivateKeyPassword !== '') {
$('button:button[name="submitChangePrivateKeyPassword"]').removeAttr("disabled"); $('button:button[name="submitChangePrivateKeyPassword"]').removeAttr("disabled");
if(event.which === 13) { if (event.which === 13) {
OC.Encryption.updatePrivateKeyPassword(); OC.Encryption.updatePrivateKeyPassword();
} }
} else { } else {
@ -58,7 +66,7 @@ $(document).ready(function(){
} }
}); });
$('button:button[name="submitChangePrivateKeyPassword"]').click(function() { $('button:button[name="submitChangePrivateKeyPassword"]').click(function () {
OC.Encryption.updatePrivateKeyPassword(); OC.Encryption.updatePrivateKeyPassword();
}); });