$(document).ready(function() { // load language & callback next loadConf(curr_lng, false, function(_langs,_conf) { $('.loginLogo').attr('src',_conf.loginLogo); if (window.location.hash=="#forgotConfirm") { $('.modal .modal-header .modal-title').text(_langs.forgot_login); $('.modal .modal-body').text(_langs.check_email); $('.modal .modal-footer .cancel').addClass('hide'); $('.modal .modal-footer .ok').bind('click', function() { $('.modal').modal('hide'); }); $('.modal').modal(); } if (window.location.hash=="#regActivate") { $('.modal .modal-header .modal-title').text(_langs.send_reg); $('.modal .modal-body').text(_langs.reg_finish); $('.modal .modal-footer .cancel').addClass('hide'); $('.modal .modal-footer .ok').bind('click', function() { $('.modal').modal('hide'); }); $('.modal').modal(); } $('.login_form .form .btn').bind('click',function() { if (!$(this).hasClass('login')) { $('.login_form .user').val('demoacwa'); $('.login_form .pass').val('demoacwa'); } $.ajax({ url: "/api/v2/login", data: JSON.stringify({ "username" : $('.login_form .user').val(), "password" : $('.login_form .pass').val() }), beforeSend: function() { $('.preloader').removeClass('hide'); }, complete: function(res,xhr) { if (res.status == 200) { // document.location='/'+_conf.modules[0]; document.location=window.location.pathname; } else { $('.login_form .form .user').val(''); $('.login_form .form .pass').val(''); $('.login_form .form .login.btn.btn-default').removeClass('shakeX').addClass('shakeX'); $('.preloader').addClass('hide'); $('.login_form .user').select().focus(); } } }); }); // show forgot pass form $('.login_form .register_forgot .forgot_pass').bind('click',function() { $('.login_form .form').fadeOut('fast', function() { $('.login_form .forgot_form').removeClass('hide').fadeIn('', function() { $('.login_form .forgot_form .email').focus(); }); }); }); // show reg pass form $('.login_form .register_forgot .new_reg').bind('click',function() { $('.login_form .form').fadeOut('fast', function() { $('.login_form .reg_form').removeClass('hide').fadeIn('', function() { $('.login_form .reg_form .email').focus(); }); }); }); // back to login form $('.login_form .back a').bind('click',function() { $('.login_form .form').removeClass('hide').fadeIn('fast'); $('.login_form .forgot_form').addClass('hide'); $('.login_form .reg_form').addClass('hide'); $('.login_form .form .user').focus(); }); // forgot mail $('.login_form .forgot_form input[type=submit]').bind('click',function() { var button=$(this); var form=button.parent(); var email=form.find('.email'); if (validateEmail(email.val())) { $.ajax({ url: "/api/v2/forgotReg/"+curr_lng, data: JSON.stringify({ "email" : email.val() }), beforeSend: function() { $('.preloader').removeClass('hide'); }, complete: function(res,xhr) { $('.preloader').addClass('hide'); if (res.status==200) { $('.modal .modal-header .modal-title').text(_langs.forgot_login); $('.modal .modal-body').text(_langs.check_email); $('.modal .modal-footer .cancel').addClass('hide'); $('.modal .modal-footer .ok').bind('click', function() { $('.login_form .back a').trigger('click'); $('.modal').modal('hide'); email.val(''); $('.login_form .form .user').val(''); $('.login_form .form .pass').val(''); }); $('.modal').modal(); } else { email.addClass('shakeX').css('color','#f00'); setTimeout(function() { email.removeClass('shakeX'); }, 750); } } }); } else { email.addClass('shakeX').css('color','#f00'); setTimeout(function() { email.removeClass('shakeX'); }, 750); } }); // new registration $('.login_form .reg_form input[type=submit]').bind('click',function() { var button=$(this); var form=button.parent(); var email=form.find('.email'); var user=form.find('.new_user'); if (validateEmail(email.val()) && validateUser(user.val())) { $.ajax({ url: "/api/v2/userReg/"+curr_lng, data: JSON.stringify({ "email" : email.val(), "username" : user.val() }), beforeSend: function() { $('.preloader').removeClass('hide'); }, complete: function(res,xhr) { $('.preloader').addClass('hide'); if (res.status==201) { $('.modal .modal-header .modal-title').text(_langs.register); $('.modal .modal-body').text(_langs.check_email); $('.modal .modal-footer .cancel').addClass('hide'); $('.modal .modal-footer .ok').bind('click', function() { $('.login_form .back a').trigger('click'); $('.modal').modal('hide'); email.val(''); user.val(''); $('.login_form .form .user').val(''); $('.login_form .form .pass').val(''); }); $('.modal').modal(); } else { if (res.responseJSON.data.conflict=="emailAddress") { email.addClass('shakeX').css('color','#f00'); setTimeout(function() { email.removeClass('shakeX'); }, 750); } else if (res.responseJSON.data.conflict=="username") { user.addClass('shakeX').css('color','#f00'); setTimeout(function() { user.removeClass('shakeX'); }, 750); } } } }); } else { if (!validateEmail(email.val())) { email.addClass('shakeX').css('color','#f00'); setTimeout(function() { email.removeClass('shakeX'); }, 750); } if (!validateUser(user.val())) { user.addClass('shakeX').css('color','#f00'); setTimeout(function() { user.removeClass('shakeX'); }, 750); } } }); $('.login_form .forgot_form .email, .login_form .reg_form .email, .login_form .reg_form .new_user').bind('keydown',function() { $(this).css('color',''); }); // remember me toggle // $('.login_form .remember a').bind('click', function() { // $('.login_form .remember .remember_me_on').trigger('click'); // }); $('.login_form .user').select().focus(); }); });