lostpassword.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. $('#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();
  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(msg){
  159. if(OC.webroot !== '') {
  160. window.location = OC.webroot;
  161. } else {
  162. window.location = '/';
  163. }
  164. },
  165. resetError : function(msg){
  166. var node = OC.Lostpassword.getResetStatusNode();
  167. node.addClass('warning');
  168. node.html(msg);
  169. },
  170. getResetStatusNode : function (){
  171. if (!$('#lost-password').length){
  172. $('<p id="lost-password"></p>').insertBefore($('#reset-password fieldset'));
  173. } else {
  174. $('#lost-password').replaceWith($('<p id="lost-password"></p>'));
  175. }
  176. return $('#lost-password');
  177. }
  178. };
  179. $(document).ready(OC.Lostpassword.init);