$(function () { if (window.my_user_id >= 0) document.location.href = '/'; $('#username_error').hide(); $('#password_error').hide(); $('#captcha_error').hide(); $('#login_button').click(function () { api_unchecked('login', { username: $('#username').val(), password: $('#password').val(), 'h-captcha-response': grecaptcha.getResponse() }, function (data) { if (data.error !== undefined) { switch (data.error) { case 'captcha check failed': show_hide('#captcha_error'); break; case 'illegal username': show_hide('#username_error'); delayed(function () { $('#username').toggleClass('is-danger'); }); break; case 'illegal password': case 'illegal credentials': show_hide('#password_error'); delayed(function () { $('#password').toggleClass('is-danger'); }); break; default: popup('danger', 'Error: ' + data.error); break; } $('#password').val(''); grecaptcha.reset(); return; } popup('primary', 'Successfully logged in!'); setTimeout(function () { document.location.href = '/'; }, 1500); }); }); });