lostpassword.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. OC.Lostpassword = {
  2. sendErrorMsg : t('core', 'Couldn\'t send reset email. Please contact your administrator.'),
  3. sendSuccessMsg : t('core', 'The link to reset your password has been sent to your email. If you do not receive it within a reasonable amount of time, check your spam/junk folders.<br>If it is not there ask your local administrator.'),
  4. encryptedMsg : t('core', "Your files are encrypted. There will be no way to get your data back after your password is reset.<br />If you are not sure what to do, please contact your administrator before you continue. <br />Do you really want to continue?")
  5. + ('<br /><input type="checkbox" id="encrypted-continue" value="Yes" />')
  6. + '<label for="encrypted-continue">'
  7. + t('core', 'I know what I\'m doing')
  8. + '</label><br />',
  9. resetErrorMsg : t('core', 'Password can not be changed. Please contact your administrator.'),
  10. init : function() {
  11. $('#lost-password').click(OC.Lostpassword.resetLink);
  12. $('#reset-password #submit').click(OC.Lostpassword.resetPassword);
  13. },
  14. resetLink : function(event){
  15. event.preventDefault();
  16. if (!$('#user').val().length){
  17. $('#submit').trigger('click');
  18. } else {
  19. if (OC.config.lost_password_link === 'disabled') {
  20. return;
  21. } else if (OC.config.lost_password_link) {
  22. window.location = OC.config.lost_password_link;
  23. } else {
  24. $.post(
  25. OC.generateUrl('/lostpassword/email'),
  26. {
  27. user : $('#user').val()
  28. },
  29. OC.Lostpassword.sendLinkDone
  30. ).fail(function() {
  31. OC.Lostpassword.sendLinkError(OC.Lostpassword.sendErrorMsg);
  32. });
  33. }
  34. }
  35. },
  36. sendLinkDone : function(result){
  37. var sendErrorMsg;
  38. if (result && result.status === 'success'){
  39. OC.Lostpassword.sendLinkSuccess();
  40. } else {
  41. if (result && result.msg){
  42. sendErrorMsg = result.msg;
  43. } else {
  44. sendErrorMsg = OC.Lostpassword.sendErrorMsg;
  45. }
  46. OC.Lostpassword.sendLinkError(sendErrorMsg);
  47. }
  48. },
  49. sendLinkSuccess : function(msg){
  50. var node = OC.Lostpassword.getSendStatusNode();
  51. // update is the better success message styling
  52. node.addClass('update').css({width:'auto'});
  53. node.html(OC.Lostpassword.sendSuccessMsg);
  54. },
  55. sendLinkError : function(msg){
  56. var node = OC.Lostpassword.getSendStatusNode();
  57. node.addClass('warning');
  58. node.html(msg);
  59. OC.Lostpassword.init();
  60. },
  61. getSendStatusNode : function(){
  62. if (!$('#lost-password').length){
  63. $('<p id="lost-password"></p>').insertBefore($('#remember_login'));
  64. } else {
  65. $('#lost-password').replaceWith($('<p id="lost-password"></p>'));
  66. }
  67. return $('#lost-password');
  68. },
  69. resetPassword : function(event){
  70. event.preventDefault();
  71. if ($('#password').val()){
  72. $.post(
  73. $('#password').parents('form').attr('action'),
  74. {
  75. password : $('#password').val(),
  76. proceed: $('#encrypted-continue').is(':checked') ? 'true' : 'false'
  77. },
  78. OC.Lostpassword.resetDone
  79. );
  80. }
  81. if($('#encrypted-continue').is(':checked')) {
  82. $('#reset-password #submit').hide();
  83. $('#reset-password #float-spinner').removeClass('hidden');
  84. }
  85. },
  86. resetDone : function(result){
  87. var resetErrorMsg;
  88. if (result && result.status === 'success'){
  89. $.post(
  90. OC.webroot + '/',
  91. {
  92. user : window.location.href.split('/').pop(),
  93. password : $('#password').val()
  94. },
  95. OC.Lostpassword.redirect
  96. );
  97. } else {
  98. if (result && result.msg){
  99. resetErrorMsg = result.msg;
  100. } else if (result && result.encryption) {
  101. resetErrorMsg = OC.Lostpassword.encryptedMsg;
  102. } else {
  103. resetErrorMsg = OC.Lostpassword.resetErrorMsg;
  104. }
  105. OC.Lostpassword.resetError(resetErrorMsg);
  106. }
  107. },
  108. redirect : function(msg){
  109. if(OC.webroot !== '') {
  110. window.location = OC.webroot;
  111. } else {
  112. window.location = '/';
  113. }
  114. },
  115. resetError : function(msg){
  116. var node = OC.Lostpassword.getResetStatusNode();
  117. node.addClass('warning');
  118. node.html(msg);
  119. },
  120. getResetStatusNode : function (){
  121. if (!$('#lost-password').length){
  122. $('<p id="lost-password"></p>').insertBefore($('#reset-password fieldset'));
  123. } else {
  124. $('#lost-password').replaceWith($('<p id="lost-password"></p>'));
  125. }
  126. return $('#lost-password');
  127. }
  128. };
  129. $(document).ready(OC.Lostpassword.init);