Skip to content

Instantly share code, notes, and snippets.

@seanvree
Created March 11, 2019 06:34
Show Gist options
  • Save seanvree/3f7241de25b78c93f2c970f582356b3e to your computer and use it in GitHub Desktop.
Save seanvree/3f7241de25b78c93f2c970f582356b3e to your computer and use it in GitHub Desktop.
authcheck
function checkLogin() {
console.log('Logarr auth: ENABLED | Checking login status (checkLogin)');
$.ajax({
type: "GET",
url: "assets/php/login-status.php",
// data: info,
success: function (data) {
if (data === "true") {
// User is logged IN:
console.log('Logarr user is logged IN (checkLogin)');
} else {
// User is logged OUT:
console.log('Logarr user is logged OUT (checkLogin)');
logouttoast();
//If user user logs out, refresh index page to envoke authentication page after 3s:
setTimeout(function () {
window.location.href = "index.php";
}, 3000);
}
},
error: function () {
// error
console.log('ERROR: An error occurred while checking login status (checkLogin)');
}
});
//check login status every 10s:
//setInterval(checkLogin, 3000);
}
function checkLoginauto() {
console.log('Logarr is checking auth settings (checkLoginauto)');
$.ajax({
type: "GET",
url: "assets/php/auth-config.php",
// data: info,
success: function (data) {
if (data === "true") {
// Logger auth enabled:
console.log('Logger auth: ENABLED (checkLoginauto)');
// setInterval(function () {
// checkLogin();
// }, 5000);
} else {
// Logger auth disabled
console.log('Logger auth: DISABLED (checkLoginauto)');
//logouttoast();
// If user user logs out, refresh index page to envoke authentication page after 3s:
// setTimeout(function () {
// window.location.href = "index.php";
// }, 3000);
}
},
error: function () {
// error
console.log('ERROR: An error occurred while checking login status (checkLoginauto)');
}
});
//check login status every 10s:
// setInterval(function () {
//checkLoginauto();
// }, 15000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment