/** * Neon Login Script * * Developed by Arlind Nushi - www.laborator.co */ var ajax_response = 'ajax.sc'; $(document).ready(function() { $(".sc-login-error").hide(); $("#savecredentials").iCheck({ checkboxClass: 'icheckbox_flat-blue' }); $container = $("#form_login"); // Login Form & Validation $container.validate({ rules: { username: { required: true }, password: { required: true }, }, highlight: function(element) { $(element).closest('.form-group').addClass('sc-validate-has-error'); }, unhighlight: function(element) { $(element).closest('.form-group').removeClass('sc-validate-has-error'); }, submitHandler: function(ev) { $(".sc-autologout-error,.sc-login-error").hide(); sendLoginRequest(); } }); if(window.innerWidth <= 768) { $("input#password").on("change", function(){ sendLoginRequest(); }); } }); function sendLoginRequest() { window.onbeforeunload = null; current_url = new Url(window.location.href); ajax_response_url = new Url(ajax_response); var token = ''; var ident = ''; if(typeof(current_url.query.token) != "undefined"){ token = current_url.query.token; } if(typeof(current_url.query.ident) != "undefined"){ ident = current_url.query.ident; } $(".fa-chevron-double-right").removeClass("fa-chevron-double-right").addClass("fa-spinner fa-spin") $.ajax({ url: ajax_response + "?type=login", method: 'POST', dataType: 'json', data: { username: $("input#username").val(), password: $("input#password").val(), tokenpass: $("input#2tokenpass").val(), tokenpass: $("input#savecredentials").val(), X1: $("input#X1").val(), home: $("input#home").val(), redURL: $("input#redURL").val(), token: token, ident: ident }, error: function(xhr, errorType, exception ) { var errorMessage = exception || xhr.statusText; //If exception null, then default to xhr.statusText sendLoginRequest(); }, success: function(response) { console.log(response); $(".fa-spinner").addClass("fa-chevron-double-right").removeClass("fa-spinner fa-spin"); // Login status [success|invalid] // If login is invalid, we store the if (response.login_status == 'invalid') { $('.sc-login-error').slideUp("fast"); $('.sc-login-error').show(); } else if (response.login_status == 'success') { var redirect_url = ''; if (response.redirect_url && response.redirect_url.length) { redirect_url = response.redirect_url; } new_url = new Url(redirect_url); if(new_url.query.sc == "logout"){ new_url.query.sc = "home"; } redirect_url = new_url + ''; window.location.href = redirect_url; } } }); }