security_password.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* global OC */
  2. /**
  3. * Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
  4. * 2013, Morris Jobke <morris.jobke@gmail.com>
  5. * 2016, Christoph Wurst <christoph@owncloud.com>
  6. * 2017, Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * 2017, Thomas Citharel <tcit@tcit.fr>
  8. * This file is licensed under the Affero General Public License version 3 or later.
  9. * See the COPYING-README file.
  10. */
  11. $(document).ready(function () {
  12. if($('#pass2').length) {
  13. $('#pass2').showPassword().keyup();
  14. }
  15. var removeloader = function () {
  16. setTimeout(function(){
  17. if ($('.password-state').length > 0) {
  18. $('.password-state').remove();
  19. }
  20. }, 5000)
  21. };
  22. $("#passwordbutton").click(function () {
  23. if ($('#pass1').val() !== '' && $('#pass2').val() !== '') {
  24. // Serialize the data
  25. var post = $("#passwordform").serialize();
  26. $('#passwordchanged').hide();
  27. $('#passworderror').hide();
  28. $("#passwordbutton").attr('disabled', 'disabled');
  29. $("#passwordbutton").after("<span class='password-loading icon icon-loading-small-dark password-state'></span>");
  30. $(".personal-show-label").hide();
  31. // Ajax foo
  32. $.post(OC.generateUrl('/settings/personal/changepassword'), post, function (data) {
  33. if (data.status === "success") {
  34. $("#passwordbutton").after("<span class='checkmark icon icon-checkmark password-state'></span>");
  35. removeloader();
  36. $('#pass1').val('');
  37. $('#pass2').val('').change();
  38. }
  39. if (typeof(data.data) !== "undefined") {
  40. OC.msg.finishedSaving('#password-error-msg', data);
  41. } else {
  42. OC.msg.finishedSaving('#password-error-msg',
  43. {
  44. 'status' : 'error',
  45. 'data' : {
  46. 'message' : t('settings', 'Unable to change password')
  47. }
  48. }
  49. );
  50. }
  51. $(".personal-show-label").show();
  52. $(".password-loading").remove();
  53. $("#passwordbutton").removeAttr('disabled');
  54. });
  55. return false;
  56. } else {
  57. OC.msg.finishedSaving('#password-error-msg',
  58. {
  59. 'status' : 'error',
  60. 'data' : {
  61. 'message' : t('settings', 'Unable to change password')
  62. }
  63. }
  64. );
  65. return false;
  66. }
  67. });
  68. $('#pass2').strengthify({
  69. zxcvbn: OC.linkTo('core','vendor/zxcvbn/dist/zxcvbn.js'),
  70. titles: [
  71. t('settings', 'Very weak password'),
  72. t('settings', 'Weak password'),
  73. t('settings', 'So-so password'),
  74. t('settings', 'Good password'),
  75. t('settings', 'Strong password')
  76. ],
  77. drawTitles: true,
  78. $addAfter: $('input[name="newpassword-clone"]'),
  79. });
  80. });