lostpassword.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. If you haven't enabled the recovery key, 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']) {
  20. window.location = OC.config['lost_password_link'];
  21. } else {
  22. $.post(
  23. OC.generateUrl('/lostpassword/email'),
  24. {
  25. user : $('#user').val()
  26. },
  27. OC.Lostpassword.sendLinkDone
  28. );
  29. }
  30. }
  31. },
  32. sendLinkDone : function(result){
  33. var sendErrorMsg;
  34. if (result && result.status === 'success'){
  35. OC.Lostpassword.sendLinkSuccess();
  36. } else {
  37. if (result && result.msg){
  38. sendErrorMsg = result.msg;
  39. } else {
  40. sendErrorMsg = OC.Lostpassword.sendErrorMsg;
  41. }
  42. OC.Lostpassword.sendLinkError(sendErrorMsg);
  43. }
  44. },
  45. sendLinkSuccess : function(msg){
  46. var node = OC.Lostpassword.getSendStatusNode();
  47. // update is the better success message styling
  48. node.addClass('update').css({width:'auto'});
  49. node.html(OC.Lostpassword.sendSuccessMsg);
  50. },
  51. sendLinkError : function(msg){
  52. var node = OC.Lostpassword.getSendStatusNode();
  53. node.addClass('warning');
  54. node.html(msg);
  55. OC.Lostpassword.init();
  56. },
  57. getSendStatusNode : function(){
  58. if (!$('#lost-password').length){
  59. $('<p id="lost-password"></p>').insertBefore($('#remember_login'));
  60. } else {
  61. $('#lost-password').replaceWith($('<p id="lost-password"></p>'));
  62. }
  63. return $('#lost-password');
  64. },
  65. resetPassword : function(event){
  66. event.preventDefault();
  67. if ($('#password').val()){
  68. $.post(
  69. $('#password').parents('form').attr('action'),
  70. {
  71. password : $('#password').val(),
  72. proceed: $('#encrypted-continue').is(':checked') ? 'true' : 'false'
  73. },
  74. OC.Lostpassword.resetDone
  75. );
  76. }
  77. if($('#encrypted-continue').is(':checked')) {
  78. $('#reset-password #submit').hide();
  79. $('#reset-password #float-spinner').removeClass('hidden');
  80. }
  81. },
  82. resetDone : function(result){
  83. var resetErrorMsg;
  84. if (result && result.status === 'success'){
  85. $.post(
  86. OC.webroot + '/',
  87. {
  88. user : window.location.href.split('/').pop(),
  89. password : $('#password').val()
  90. },
  91. OC.Lostpassword.redirect
  92. );
  93. } else {
  94. if (result && result.msg){
  95. resetErrorMsg = result.msg;
  96. } else if (result && result.encryption) {
  97. resetErrorMsg = OC.Lostpassword.encryptedMsg;
  98. } else {
  99. resetErrorMsg = OC.Lostpassword.resetErrorMsg;
  100. }
  101. OC.Lostpassword.resetError(resetErrorMsg);
  102. }
  103. },
  104. redirect : function(msg){
  105. if(OC.webroot !== '') {
  106. window.location = OC.webroot;
  107. } else {
  108. window.location = '/';
  109. }
  110. },
  111. resetError : function(msg){
  112. var node = OC.Lostpassword.getResetStatusNode();
  113. node.addClass('warning');
  114. node.html(msg);
  115. },
  116. getResetStatusNode : function (){
  117. if (!$('#lost-password').length){
  118. $('<p id="lost-password"></p>').insertBefore($('#reset-password fieldset'));
  119. } else {
  120. $('#lost-password').replaceWith($('<p id="lost-password"></p>'));
  121. }
  122. return $('#lost-password');
  123. }
  124. };
  125. $(document).ready(OC.Lostpassword.init);