$(document).ready(function(e) { $('#loginForm').submit(function(e){ e.preventDefault(); $('#btnSignin').click(); }) $('#btnSignin').click(function(e){ e.preventDefault(); if(!isValidEmail($('#email').val())){ toastr["error"]("Invalid Email address", "Access Denied"); return; } if($('#email').val().length < 6){ toastr["error"]("Invalid Password", "Access Denied"); return; } $.ajax({ type: "POST", url:"//ico.glamjet.io/controllers/login/processLogin.php?d=", dataType:'JSONP', data:{ account_id: $('#account_id').val(), email: $('#email').val(), password: $('#password').val(), key: $('#key').val() }, success: function(data){ if(data.error == "1"){ toastr["error"](data.message, "Access Denied"); } if(data.error == "2"){ window.location.href = "/?captcha=2"; return; } if(data.error == "0"){ if(data.user_id > 0){ console.log("redirect"); window.location = '/overview.php'; } } } }); }); if($('#key').length == 0){ $('#keycon').append(""); } grecaptcha.ready(function() { grecaptcha.execute('6LdyuL4ZAAAAAM0YPE4PSM9zfICW4aINJXItlObp', {action: 'login'}).then(function(token) { $.ajax({ url: 'controllers/login/captcha.php', dataType:'JSON', type:'POST', data:{ token:token }, success(data){ if(data.error == 0){ $('.grecaptcha-badge').hide(); $('#btnSignin').html(' Sign in'); $('#btnSignin').removeAttr('disabled'); } else{ window.location.href = "/?captcha=2"; } } }) }); }); }); function isValidEmail(email) { email = email.toLowerCase(); return /^[a-z0-9]+([-._+][a-z0-9]+)*[-._+]*@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}$/.test(email) && /^(?=.{1,64}@.{4,64}$)(?=.{6,100}$).*/.test(email); }