summaryrefslogtreecommitdiffstats
path: root/apps/encryption/js
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-05-04 11:44:15 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-05-04 11:44:15 +0200
commit0f7b8dd33814a036b98727a7a9d82deaae061785 (patch)
tree12f0414038ec635c3ba42691c1aea21c14b9a80b /apps/encryption/js
parent7376ea9b269af6cd6355ed9bf386097121c10c77 (diff)
parent8c0856779bccb41014f677c5ebdec79aec0a5602 (diff)
downloadnextcloud-server-0f7b8dd33814a036b98727a7a9d82deaae061785.tar.gz
nextcloud-server-0f7b8dd33814a036b98727a7a9d82deaae061785.zip
Merge pull request #15752 from owncloud/feature/fix-encryption-return-values
[enc2] fixing return values and adding tests
Diffstat (limited to 'apps/encryption/js')
-rw-r--r--apps/encryption/js/settings-admin.js65
-rw-r--r--apps/encryption/js/settings-personal.js48
2 files changed, 64 insertions, 49 deletions
diff --git a/apps/encryption/js/settings-admin.js b/apps/encryption/js/settings-admin.js
index bb539f6a4e2..fdc53c52152 100644
--- a/apps/encryption/js/settings-admin.js
+++ b/apps/encryption/js/settings-admin.js
@@ -7,52 +7,59 @@
* See the COPYING-README file.
*/
-$(document).ready(function(){
+$(document).ready(function () {
- $( 'input:radio[name="adminEnableRecovery"]' ).change(
- function() {
- var recoveryStatus = $( this ).val();
- var oldStatus = (1+parseInt(recoveryStatus, 10)) % 2;
- var recoveryPassword = $( '#encryptionRecoveryPassword' ).val();
- var confirmPassword = $( '#repeatEncryptionRecoveryPassword' ).val();
+ $('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.generateUrl('/apps/encryption/ajax/adminRecovery'),
- { adminEnableRecovery: recoveryStatus,
+ {
+ adminEnableRecovery: recoveryStatus,
recoveryPassword: recoveryPassword,
- confirmPassword: confirmPassword },
- function( result ) {
- OC.msg.finishedSaving('#encryptionSetRecoveryKey .msg', result);
- if (result.status === "error") {
- $('input:radio[name="adminEnableRecovery"][value="'+oldStatus.toString()+'"]')
- .attr("checked", "true");
+ confirmPassword: confirmPassword
+ }
+ ).done(function (data) {
+ OC.msg.finishedSuccess('#encryptionSetRecoveryKey .msg', data.data.message);
+
+ if (recoveryStatus === "0") {
+ $('p[name="changeRecoveryPasswordBlock"]').addClass("hidden");
} else {
- if (recoveryStatus === "0") {
- $('p[name="changeRecoveryPasswordBlock"]').addClass("hidden");
- } else {
- $('input:password[name="changeRecoveryPassword"]').val("");
- $('p[name="changeRecoveryPasswordBlock"]').removeClass("hidden");
- }
+ $('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
- $('button:button[name="submitChangeRecoveryKey"]').click(function() {
+ $('button:button[name="submitChangeRecoveryKey"]').click(function () {
var oldRecoveryPassword = $('#oldEncryptionRecoveryPassword').val();
var newRecoveryPassword = $('#newEncryptionRecoveryPassword').val();
var confirmNewPassword = $('#repeatedNewEncryptionRecoveryPassword').val();
OC.msg.startSaving('#encryptionChangeRecoveryKey .msg');
$.post(
- OC.generateUrl('/apps/encryption/ajax/changeRecoveryPassword'),
- { oldPassword: oldRecoveryPassword, newPassword: newRecoveryPassword, confirmPassword: confirmNewPassword },
- function( data ) {
- OC.msg.finishedSaving('#encryptionChangeRecoveryKey .msg', data);
- }
- );
+ OC.generateUrl('/apps/encryption/ajax/changeRecoveryPassword'),
+ {
+ oldPassword: oldRecoveryPassword,
+ 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);
+ });
});
});
diff --git a/apps/encryption/js/settings-personal.js b/apps/encryption/js/settings-personal.js
index e36f10a244e..658ba2a86ec 100644
--- a/apps/encryption/js/settings-personal.js
+++ b/apps/encryption/js/settings-personal.js
@@ -9,35 +9,43 @@ if (!OC.Encryption) {
}
OC.Encryption = {
- updatePrivateKeyPassword: function() {
+ updatePrivateKeyPassword: function () {
var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val();
var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val();
OC.msg.startSaving('#encryption .msg');
$.post(
OC.generateUrl('/apps/encryption/ajax/updatePrivateKeyPassword'),
- {oldPassword: oldPrivateKeyPassword, newPassword: newPrivateKeyPassword}
- ).success(function (response) {
- OC.msg.finishedSuccess('#encryption .msg', response.message);
- }).fail(function (response) {
- OC.msg.finishedError('#encryption .msg', response.responseJSON.message);
- });
+ {
+ oldPassword: oldPrivateKeyPassword,
+ newPassword: newPrivateKeyPassword
+ }
+ ).done(function (data) {
+ OC.msg.finishedSuccess('#encryption .msg', data.message);
+ })
+ .fail(function (jqXHR) {
+ OC.msg.finishedError('#encryption .msg', JSON.parse(jqXHR.responseText).message);
+ });
}
};
-$(document).ready(function(){
+$(document).ready(function () {
// Trigger ajax on recoveryAdmin status change
- $( 'input:radio[name="userEnableRecovery"]' ).change(
- function() {
- var recoveryStatus = $( this ).val();
+ $('input:radio[name="userEnableRecovery"]').change(
+ function () {
+ var recoveryStatus = $(this).val();
OC.msg.startAction('#userEnableRecovery .msg', 'Updating recovery keys. This can take some time...');
$.post(
- OC.generateUrl('/apps/encryption/ajax/userSetRecovery'),
- { userEnableRecovery: recoveryStatus },
- function( data ) {
- OC.msg.finishedAction('#userEnableRecovery .msg', data);
+ OC.generateUrl('/apps/encryption/ajax/userSetRecovery'),
+ {
+ userEnableRecovery: recoveryStatus
}
- );
+ ).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
return false;
}
@@ -45,12 +53,12 @@ $(document).ready(function(){
// 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 newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val();
- if (newPrivateKeyPassword !== '' && oldPrivateKeyPassword !== '' ) {
+ if (newPrivateKeyPassword !== '' && oldPrivateKeyPassword !== '') {
$('button:button[name="submitChangePrivateKeyPassword"]').removeAttr("disabled");
- if(event.which === 13) {
+ if (event.which === 13) {
OC.Encryption.updatePrivateKeyPassword();
}
} else {
@@ -58,7 +66,7 @@ $(document).ready(function(){
}
});
- $('button:button[name="submitChangePrivateKeyPassword"]').click(function() {
+ $('button:button[name="submitChangePrivateKeyPassword"]').click(function () {
OC.Encryption.updatePrivateKeyPassword();
});