You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lostpassword.js 3.9KB

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