login.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. $(function () {
  2. if (window.my_user_id >= 0)
  3. document.location.href = '/';
  4. $('#username_error').hide();
  5. $('#password_error').hide();
  6. $('#captcha_error').hide();
  7. $('#login_button').click(function () {
  8. api_unchecked('login', {
  9. username: $('#username').val(),
  10. password: $('#password').val(),
  11. 'h-captcha-response': grecaptcha.getResponse()
  12. }, function (data) {
  13. if (data.error !== undefined) {
  14. switch (data.error) {
  15. case 'captcha check failed':
  16. show_hide('#captcha_error');
  17. break;
  18. case 'illegal username':
  19. show_hide('#username_error');
  20. delayed(function () {
  21. $('#username').toggleClass('is-danger');
  22. });
  23. break;
  24. case 'illegal password':
  25. case 'illegal credentials':
  26. show_hide('#password_error');
  27. delayed(function () {
  28. $('#password').toggleClass('is-danger');
  29. });
  30. break;
  31. default:
  32. popup('danger', 'Error: ' + data.error);
  33. break;
  34. }
  35. $('#password').val('');
  36. grecaptcha.reset();
  37. return;
  38. }
  39. popup('primary', 'Successfully logged in!');
  40. setTimeout(function () {
  41. document.location.href = '/';
  42. }, 1500);
  43. });
  44. });
  45. });