signup.js 1.6 KB

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