signup.js 1.7 KB

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