var server = 'https://airangel-update.4dapt.com'; var domain = 'angel'; var page = window.document.URL.split('/')[3]; if (page === 'index.html' || page === '' || page === undefined){ if (localStorage.getItem('loc') === null){ var loginbutton = document.getElementById('login-button'); loginbutton.onclick = function() { run(loginbutton); }; $('form.login-form').keypress(function(e){ if (e.keyCode === 13){ // 'Enter if (e.target.id === 'userid'){ $('#pswd').focus(); } else if (e.target.id === 'pswd'){ run(loginbutton); } } }); } } else { check_login(); } // To add additional users add to the or clause in the if statement found in the run function. Be sure to add a username and a password // Once added move to the script2.js docement and add credentials to the inital if statement function run(button) { $.ajax({ url: server + '/login.php', type: "POST", data: `username=${button.form.userid.value}&password=${button.form.pswd.value}&domain=${domain}`, dataType: 'json', success: function(data){ console.log(data); if (typeof data.login !== 'undefined' && data.login.length === 32){ localStorage.setItem('login', data.login); if (typeof data.domain !== 'undefined' && data.login.length === 32) { $.cookie('client', data.domain, {expires: 1}); console.log('login: success!'); window.open('/map.html', '_self'); } } else { window.alert(data.error); } }, error: function(jqXHR, textStatus, errorThrown){ console.log(jqXHR, textStatus, errorThrown); alert("Error connection"); } }); } function check_login(callback){ $.ajax({ url: server + '/login.php', type: "POST", data: `check_login=` + localStorage.getItem('login'), dataType: 'json', success: function(data){ if (data.sess_login !== '12345'){ logout(); } else if(callback){ callback(); } }, error: function(jqXHR, textStatus, errorThrown){ console.log(jqXHR, textStatus, errorThrown); alert("Error connection"); logout(); } }); } function logout() { localStorage.removeItem('login'); $.removeCookie('client'); let currUrl = window.document.URL; if (currUrl.indexOf('index') === -1) { window.open('/', '_self'); } }