settings-admin.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-FileCopyrightText: 2013-2015 ownCloud, Inc.
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. window.addEventListener('DOMContentLoaded', function () {
  7. $('input:button[name="enableRecoveryKey"]').click(function () {
  8. var recoveryStatus = $(this).attr('status');
  9. var newRecoveryStatus = (1 + parseInt(recoveryStatus)) % 2;
  10. var buttonValue = $(this).attr('value');
  11. var recoveryPassword = $('#encryptionRecoveryPassword').val();
  12. var confirmPassword = $('#repeatEncryptionRecoveryPassword').val();
  13. OC.msg.startSaving('#encryptionSetRecoveryKey .msg');
  14. $.post(
  15. OC.generateUrl('/apps/encryption/ajax/adminRecovery'),
  16. {
  17. adminEnableRecovery: newRecoveryStatus,
  18. recoveryPassword: recoveryPassword,
  19. confirmPassword: confirmPassword
  20. }
  21. ).done(function (data) {
  22. OC.msg.finishedSuccess('#encryptionSetRecoveryKey .msg', data.data.message);
  23. if (newRecoveryStatus === 0) {
  24. $('p[name="changeRecoveryPasswordBlock"]').addClass("hidden");
  25. $('input:button[name="enableRecoveryKey"]').attr('value', 'Enable recovery key');
  26. $('input:button[name="enableRecoveryKey"]').attr('status', '0');
  27. } else {
  28. $('input:password[name="changeRecoveryPassword"]').val("");
  29. $('p[name="changeRecoveryPasswordBlock"]').removeClass("hidden");
  30. $('input:button[name="enableRecoveryKey"]').attr('value', 'Disable recovery key');
  31. $('input:button[name="enableRecoveryKey"]').attr('status', '1');
  32. }
  33. })
  34. .fail(function (jqXHR) {
  35. $('input:button[name="enableRecoveryKey"]').attr('value', buttonValue);
  36. $('input:button[name="enableRecoveryKey"]').attr('status', recoveryStatus);
  37. OC.msg.finishedError('#encryptionSetRecoveryKey .msg', JSON.parse(jqXHR.responseText).data.message);
  38. });
  39. });
  40. $("#repeatEncryptionRecoveryPassword").keyup(function (event) {
  41. if (event.keyCode == 13) {
  42. $("#enableRecoveryKey").click();
  43. }
  44. });
  45. // change recovery password
  46. $('button:button[name="submitChangeRecoveryKey"]').click(function () {
  47. var oldRecoveryPassword = $('#oldEncryptionRecoveryPassword').val();
  48. var newRecoveryPassword = $('#newEncryptionRecoveryPassword').val();
  49. var confirmNewPassword = $('#repeatedNewEncryptionRecoveryPassword').val();
  50. OC.msg.startSaving('#encryptionChangeRecoveryKey .msg');
  51. $.post(
  52. OC.generateUrl('/apps/encryption/ajax/changeRecoveryPassword'),
  53. {
  54. oldPassword: oldRecoveryPassword,
  55. newPassword: newRecoveryPassword,
  56. confirmPassword: confirmNewPassword
  57. }
  58. ).done(function (data) {
  59. OC.msg.finishedSuccess('#encryptionChangeRecoveryKey .msg', data.data.message);
  60. })
  61. .fail(function (jqXHR) {
  62. OC.msg.finishedError('#encryptionChangeRecoveryKey .msg', JSON.parse(jqXHR.responseText).data.message);
  63. });
  64. });
  65. $('#encryptHomeStorage').change(function() {
  66. $.post(
  67. OC.generateUrl('/apps/encryption/ajax/setEncryptHomeStorage'),
  68. {
  69. encryptHomeStorage: this.checked
  70. }
  71. );
  72. });
  73. });