lostpassword.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. OC.Lostpassword = {
  2. sendErrorMsg : t('core', 'Couldn\'t send reset email. Please contact your administrator.'),
  3. sendSuccessMsg : t('core', 'We have send a password reset e-mail to the e-mail address known to us for this account. 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" class="checkbox checkbox--white" 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[href=""]').click(OC.Lostpassword.resetLink);
  12. $('#lost-password-back').click(OC.Lostpassword.backToLogin);
  13. $('form[name=login]').submit(OC.Lostpassword.onSendLink);
  14. $('#reset-password #submit').click(OC.Lostpassword.resetPassword);
  15. OC.Lostpassword.resetButtons();
  16. },
  17. resetButtons : function() {
  18. $('#reset-password-wrapper .submit-icon')
  19. .addClass('icon-confirm-white')
  20. .removeClass('icon-loading-small-dark');
  21. $('#reset-password-submit')
  22. .attr('value', t('core', 'Reset password'))
  23. .prop('disabled', false);
  24. $('#user').prop('disabled', false);
  25. $('.login-additional').fadeIn();
  26. },
  27. backToLogin : function(event) {
  28. event.preventDefault();
  29. $('#reset-password-wrapper').slideUp().fadeOut();
  30. $('#lost-password').slideDown().fadeIn();
  31. $('#lost-password-back').hide();
  32. $('.remember-login-container').slideDown().fadeIn();
  33. $('#submit-wrapper').slideDown().fadeIn();
  34. $('.groupbottom').slideDown().fadeIn();
  35. $('#user').parent().addClass('grouptop');
  36. $('#password').attr('required', true);
  37. $('form[name=login]').removeAttr('action');
  38. $('#user').focus();
  39. },
  40. resetLink : function(event){
  41. event.preventDefault();
  42. $('#lost-password').hide();
  43. $('.wrongPasswordMsg').hide();
  44. $('#lost-password-back').slideDown().fadeIn();
  45. $('.remember-login-container').slideUp().fadeOut();
  46. $('#submit-wrapper').slideUp().fadeOut();
  47. $('.groupbottom').slideUp().fadeOut(function(){
  48. $('#user').parent().removeClass('grouptop');
  49. });
  50. $('#reset-password-wrapper').slideDown().fadeIn();
  51. $('#password').attr('required', false);
  52. $('form[name=login]').attr('action', 'lostpassword/email');
  53. $('#user').focus();
  54. // Generate a browser warning for required fields if field empty
  55. if ($('#user').val().length === 0) {
  56. $('#submit').trigger('click');
  57. } else {
  58. if (OC.config.lost_password_link === 'disabled') {
  59. return;
  60. } else if (OC.config.lost_password_link) {
  61. window.location = OC.config.lost_password_link;
  62. } else {
  63. OC.Lostpassword.onSendLink();
  64. }
  65. }
  66. },
  67. onSendLink: function (event) {
  68. // Only if password reset form is active
  69. if($('form[name=login][action]').length === 1) {
  70. if (event) {
  71. event.preventDefault();
  72. }
  73. $('#reset-password-wrapper .submit-icon')
  74. .removeClass('icon-confirm-white')
  75. .addClass('icon-loading-small-dark');
  76. $('#reset-password-submit')
  77. .attr('value', t('core', 'Sending email …'))
  78. .prop('disabled', true);
  79. $('#user').prop('disabled', true);
  80. $('.login-additional').fadeOut();
  81. $.post(
  82. OC.generateUrl('/lostpassword/email'),
  83. {
  84. user : $('#user').val()
  85. },
  86. OC.Lostpassword.sendLinkDone
  87. ).fail(function() {
  88. OC.Lostpassword.sendLinkError(OC.Lostpassword.sendErrorMsg);
  89. });
  90. }
  91. },
  92. sendLinkDone : function(result){
  93. var sendErrorMsg;
  94. if (result && result.status === 'success'){
  95. OC.Lostpassword.sendLinkSuccess();
  96. } else {
  97. if (result && result.msg){
  98. sendErrorMsg = result.msg;
  99. } else {
  100. sendErrorMsg = OC.Lostpassword.sendErrorMsg;
  101. }
  102. OC.Lostpassword.sendLinkError(sendErrorMsg);
  103. }
  104. },
  105. sendLinkSuccess : function(msg){
  106. var node = OC.Lostpassword.getSendStatusNode();
  107. // update is the better success message styling
  108. node.addClass('update').css({width:'auto'});
  109. node.html(OC.Lostpassword.sendSuccessMsg);
  110. OC.Lostpassword.resetButtons();
  111. },
  112. sendLinkError : function(msg){
  113. var node = OC.Lostpassword.getSendStatusNode();
  114. node.addClass('warning');
  115. node.html(msg);
  116. OC.Lostpassword.resetButtons();
  117. },
  118. getSendStatusNode : function(){
  119. if (!$('#lost-password').length){
  120. $('<p id="lost-password"></p>').insertBefore($('#remember_login'));
  121. } else {
  122. $('#lost-password').replaceWith($('<p id="lost-password"></p>'));
  123. }
  124. return $('#lost-password');
  125. },
  126. resetPassword : function(event){
  127. event.preventDefault();
  128. if ($('#password').val()){
  129. $.post(
  130. $('#password').parents('form').attr('action'),
  131. {
  132. password : $('#password').val(),
  133. proceed: $('#encrypted-continue').is(':checked') ? 'true' : 'false'
  134. },
  135. OC.Lostpassword.resetDone
  136. );
  137. }
  138. if($('#encrypted-continue').is(':checked')) {
  139. $('#reset-password #submit').hide();
  140. $('#reset-password #float-spinner').removeClass('hidden');
  141. }
  142. },
  143. resetDone : function(result){
  144. var resetErrorMsg;
  145. if (result && result.status === 'success'){
  146. OC.Lostpassword.redirect('/login?user=' + result.user);
  147. } else {
  148. if (result && result.msg){
  149. resetErrorMsg = result.msg;
  150. } else if (result && result.encryption) {
  151. resetErrorMsg = OC.Lostpassword.encryptedMsg;
  152. } else {
  153. resetErrorMsg = OC.Lostpassword.resetErrorMsg;
  154. }
  155. OC.Lostpassword.resetError(resetErrorMsg);
  156. }
  157. },
  158. redirect : function(url){
  159. window.location = OC.generateUrl(url);
  160. },
  161. resetError : function(msg){
  162. var node = OC.Lostpassword.getResetStatusNode();
  163. node.addClass('warning');
  164. node.html(msg);
  165. },
  166. getResetStatusNode : function (){
  167. if (!$('#lost-password').length){
  168. $('<p id="lost-password"></p>').insertBefore($('#reset-password fieldset'));
  169. } else {
  170. $('#lost-password').replaceWith($('<p id="lost-password"></p>'));
  171. }
  172. return $('#lost-password');
  173. }
  174. };
  175. $(document).ready(OC.Lostpassword.init);