1
0

security_password.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* global OC */
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2011-2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. window.addEventListener('DOMContentLoaded', function () {
  8. if($('#pass2').length) {
  9. $('#pass2').showPassword().keyup();
  10. }
  11. var removeloader = function () {
  12. setTimeout(function(){
  13. if ($('.password-state').length > 0) {
  14. $('.password-state').remove();
  15. }
  16. }, 5000)
  17. };
  18. $("#passwordbutton").click(function () {
  19. if ($('#pass1').val() !== '' && $('#pass2').val() !== '') {
  20. // Serialize the data
  21. var post = $("#passwordform").serialize();
  22. $('#passwordchanged').hide();
  23. $('#passworderror').hide();
  24. $("#passwordbutton").attr('disabled', 'disabled');
  25. $("#passwordbutton").after("<span class='password-loading icon icon-loading-small-dark password-state'></span>");
  26. $(".personal-show-label").hide();
  27. // Ajax foo
  28. $.post(OC.generateUrl('/settings/personal/changepassword'), post, function (data) {
  29. if (data.status === "success") {
  30. $("#passwordbutton").after("<span class='checkmark icon icon-checkmark password-state'></span>");
  31. removeloader();
  32. $('#pass1').val('');
  33. $('#pass2').val('').change();
  34. }
  35. if (typeof(data.data) !== "undefined") {
  36. OC.msg.finishedSaving('#password-error-msg', data);
  37. } else {
  38. OC.msg.finishedSaving('#password-error-msg',
  39. {
  40. 'status' : 'error',
  41. 'data' : {
  42. 'message' : t('settings', 'Unable to change password')
  43. }
  44. }
  45. );
  46. }
  47. $(".personal-show-label").show();
  48. $(".password-loading").remove();
  49. $("#passwordbutton").removeAttr('disabled');
  50. });
  51. return false;
  52. } else {
  53. OC.msg.finishedSaving('#password-error-msg',
  54. {
  55. 'status' : 'error',
  56. 'data' : {
  57. 'message' : t('settings', 'Unable to change password')
  58. }
  59. }
  60. );
  61. return false;
  62. }
  63. });
  64. $('#pass2').strengthify({
  65. zxcvbn: OC.linkTo('core','vendor/zxcvbn/dist/zxcvbn.js'),
  66. titles: [
  67. t('settings', 'Very weak password'),
  68. t('settings', 'Weak password'),
  69. t('settings', 'So-so password'),
  70. t('settings', 'Good password'),
  71. t('settings', 'Strong password')
  72. ],
  73. drawTitles: true,
  74. $addAfter: $('input[name="newpassword-clone"]'),
  75. nonce: btoa(OC.requestToken),
  76. });
  77. });