login.js 1.3 KB

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