Revert "Revert "Service Worker fix""

This reverts commit c0e1b6b6e1.
This commit is contained in:
Matteo Gheza 2020-10-27 01:15:23 +01:00
parent c0e1b6b6e1
commit 10dcdc80ea
3 changed files with 37 additions and 32 deletions

View File

@ -133,7 +133,7 @@ class tools{
$array2[] = $temp;
}
}
}
} else {
if(!in_array($arr, $array2)){
@ -261,7 +261,7 @@ class database{
$this->query = $this->stmt->execute();
}
bdump($this->query);
if($fetch == true){
if(count($others_params) > 1) {
$toReturn[] = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
@ -279,12 +279,12 @@ class database{
die();
}
}
public function exists($table, $id){
$risultato = $this->exec("SELECT :table FROM `%PREFIX%_services` WHERE id = :id;", true, [":table" => $table, ":id" => $id]);
return !empty($risultato);
}
public function getOption($name){
if(defined($name)){
return constant($name);
@ -462,7 +462,7 @@ class user{
return $return_name;
}
}
public function nameById($id){
$profiles = $this->database->exec("SELECT `name` FROM `%PREFIX%_profiles` WHERE id = :id;", true, [":id" => $id]);
if(!empty($profiles)){
@ -484,12 +484,12 @@ class user{
return false;
}
}
public function hidden(){
$profiles = $this->database->exec("SELECT `name` FROM `%PREFIX%_profiles` WHERE hidden = 1;", true);
return $profiles;
}
public function available($name){
$user = $this->database->exec("SELECT available FROM `%PREFIX%_users` WHERE name = :name;", true, [":name" => $name]);
if(empty($user)){
@ -498,7 +498,7 @@ class user{
return $user[0]["available"];
}
}
public function info(){
return array("autenticated" => $this->authenticated(), "id" => $this->auth->getUserId(), "name" => $this->name(), "full_viewer" => $this->requireRole(Role::FULL_VIEWER), "tester" => $this->requireRole(Role::TESTER), "developer" => $this->requireRole(Role::DEVELOPER));
}
@ -546,6 +546,7 @@ class user{
$_SESSION['_user_disabled'] = $user[0]["disabled"];
$_SESSION['_user_chief'] = $user[0]["chief"];
$this->tools->profiler_stop();
setcookie("authenticated", true);
return true;
}
}
@ -571,6 +572,7 @@ class user{
$this->auth->logOut();
$this->auth->destroySession();
$this->log("Logout", $this->auth->getUserId(), $this->auth->getUserId(), date("d/m/Y"), date("H:i.s"));
setcookie("authenticated", false, time() - 3600);
}
catch (\Delight\Auth\NotLoggedInException $e) {
die('Not logged in');

View File

@ -10,6 +10,29 @@ import '../node_modules/bootstrap-toggle/js/bootstrap-toggle.js';
import '../node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css';
import 'time-input-polyfill/auto';
// Cookie functions from w3schools
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
$( document ).ajaxError(function(event, xhr, settings, error) {
console.error("Error requesting content: "+error+" - status code "+xhr.status);
console.log(event);
@ -38,30 +61,9 @@ $( document ).ready(function() {
// dispatch the accept event
window.dispatchEvent(new Event("cookieAlertAccept"))
});
// Cookie functions from w3schools
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
});
if ('serviceWorker' in navigator) {
if (getCookie("authenticated")) {
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js').then(registration => {
console.log('SW registered: ', registration);
@ -69,6 +71,7 @@ if ('serviceWorker' in navigator) {
console.log('SW registration failed: ', registrationError);
});
});
}
}
function fillTable(data){

View File

@ -1,7 +1,7 @@
let cacheVersion = 1
let cacheName = "static-"+cacheVersion
const urls = ['/offline.php', '/resources/dist/main.js', '/resources/dist/maps.js', '/manifest.webmanifest', '/resources/images/favicon.ico', '/resources/dist/marker-icon.png', '/resources/dist/layers.png', '/resources/dist/layers-2x.png', '/resources/images/android-chrome-192x192.png', '/resources/images/android-chrome-384x384.png', '/resources/images/black_helmet.png', '/resources/images/red_helmet.png', '/resources/images/wheel.png', '/resources/images/logo.png', '/resources/images/owner.png', '/resources/dist/fonts/fontawesome-webfont.ttf', '/resources/dist/fonts/fontawesome-webfont.svg'];
const urls = ['/offline.php', '/resources/dist/main.js', '/resources/dist/maps.js', '/manifest.webmanifest', '/resources/images/favicon.ico', '/resources/dist/marker-icon.png', '/resources/dist/layers.png', '/resources/dist/layers-2x.png', '/resources/images/android-chrome-192x192.png', '/resources/images/android-chrome-384x384.png', '/resources/images/black_helmet.png', '/resources/images/red_helmet.png', '/resources/images/wheel.png', '/resources/images/logo.png', '/resources/images/owner.png', '/resources/dist/fonts/fontawesome-webfont.ttf', '/resources/dist/fonts/fontawesome-webfont.svg', '/resources/dist/fonts/fontawesome-webfont.woff', '/resources/dist/fonts/fontawesome-webfont.woff2'];
function fetchHandler(event, content_type, not_found_message){
event.respondWith(