login.ui.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. window.adjustPanelPos = function()
  2. {
  3. let $login = $('#login');
  4. let bestTop = Math.max(0, Math.floor($(window).height() - $login.outerHeight())/2);
  5. $login.css('margin-top', bestTop);
  6. };
  7. window.refreshCaptcha = function(obj)
  8. {
  9. let $this = $(obj)
  10. let captchaLink = $.createLink('misc', 'captcha');
  11. captchaLink += captchaLink.indexOf('?') < 0 ? '?' : '&';
  12. captchaLink += 's=' + Math.random();
  13. $this.attr('src', captchaLink);
  14. };
  15. /**
  16. * Show notice for one click package use weak password.
  17. *
  18. * @access public
  19. * @return void
  20. */
  21. window.showNotice = function()
  22. {
  23. if(typeof(process4Safe) == 'string') zui.Modal.alert(process4Safe);
  24. };
  25. window.switchLang = function(lang)
  26. {
  27. selectLang(lang);
  28. };
  29. adjustPanelPos();
  30. $(window).on('resize', adjustPanelPos);
  31. timeoutID = null;
  32. window.safeSubmit = function(e)
  33. {
  34. e.preventDefault();
  35. e.stopPropagation();
  36. let account = $('#account').val().trim();
  37. let password = $('input#password[type="password"]').val().trim();
  38. let passwordStrength = computePasswordStrength(password);
  39. let hasMD5 = typeof(md5) == 'function';
  40. let referer = $('[name=referer]').val();
  41. let link = $.createLink('user', 'login');
  42. let keepLogin = $('#keepLoginon').prop('checked') ? 1 : 0;
  43. let captcha = $('#captcha').length == 1 ? $('#captcha').val() : '';
  44. let timeout = true;
  45. clearTimeout(timeoutID);
  46. timeoutID = setTimeout(function()
  47. {
  48. if(timeout) zui.Modal.alert(loginTimeoutTip);
  49. }, 4000);
  50. $('#submit').attr('disabled', 'disabled');
  51. $.get($.createLink('user', 'refreshRandom'), function(rand)
  52. {
  53. if(password != '') password = hasMD5 ? md5(md5(password) + rand) : password,
  54. timeout = false;
  55. $.post(link,
  56. {
  57. "account" : account,
  58. "password" : password,
  59. 'passwordStrength' : passwordStrength,
  60. 'referer' : referer,
  61. 'verifyRand' : rand,
  62. 'keepLogin' : keepLogin,
  63. 'captcha' : captcha
  64. },
  65. function(data)
  66. {
  67. data = JSON.parse(data);
  68. if(data.result == 'fail')
  69. {
  70. zui.Modal.alert(data.message);
  71. if($('.captchaBox').length == 1) refreshCaptcha($('.captchaBox .input-group .input-group-addon img'));
  72. clearTimeout(timeoutID);
  73. $('#submit').removeAttr('disabled').trigger('blur');
  74. waitDom('.modal.show .btn.primary', function()
  75. {
  76. let $this = $(this);
  77. setTimeout(function(){$this.trigger('focus')}, 200);
  78. })
  79. return false;
  80. }
  81. let anchor = '';
  82. if(location.hash.indexOf('#app=') === 0)
  83. {
  84. const params = $.parseUrlParams(location.hash.substring(1));
  85. $.cookie.set('tab', params.app, {expires: config.cookieLife, path: config.webRoot});
  86. anchor = location.hash;
  87. }
  88. location.href = data.locate + anchor;
  89. });
  90. });
  91. return false;
  92. };
  93. window.demoSubmit = function($el)
  94. {
  95. let account = $($el).attr('data-account');
  96. let password = $($el).attr('data-password');
  97. let link = $.createLink('user', 'login');
  98. let passwordStrength = computePasswordStrength(password);
  99. clearTimeout(timeoutID);
  100. $.post(link,
  101. {
  102. "account" : account,
  103. "password" : password,
  104. 'passwordStrength' : passwordStrength,
  105. },
  106. function(data)
  107. {
  108. data = JSON.parse(data);
  109. if(data.result == 'fail')
  110. {
  111. zui.Modal.alert(data.message);
  112. return false;
  113. }
  114. location.href = data.locate;
  115. });
  116. }
  117. document.getElementById("account").focus();