service worker
This commit is contained in:
parent
4b41102bd1
commit
41a07df168
@ -6,13 +6,7 @@
|
||||
src: url('../fonts/Fredoka-Regular.ttf');
|
||||
}
|
||||
|
||||
@font-face{
|
||||
font-family:'FontAwesome';
|
||||
src:url('../fonts/fontawesome-webfont.woff2?v=4.7.0') format('woff2'),
|
||||
url('../fonts/fontawesome-webfont.svg?v=4.7.0#fontawesomeregular') format('svg');
|
||||
font-weight:normal;
|
||||
font-style:normal}
|
||||
.fa-exclamation-circle:before{content:"\f06a"}
|
||||
|
||||
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////
|
||||
@ -273,7 +267,7 @@ a:hover {
|
||||
background-color: #fff;
|
||||
border: 1px solid #c80000;
|
||||
border-radius: 14px;
|
||||
padding: 4px 25px 4px 10px;
|
||||
padding: 4px 10px 4px 10px;
|
||||
top: 50%;
|
||||
-webkit-transform: translateY(-50%);
|
||||
-moz-transform: translateY(-50%);
|
||||
@ -296,7 +290,6 @@ a:hover {
|
||||
}
|
||||
|
||||
.alert-validate::after {
|
||||
content: "\f06a";
|
||||
font-family: FontAwesome;
|
||||
display: block;
|
||||
position: absolute;
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
$(document).ready(function(){
|
||||
$("#li_accueil").addClass("hover");
|
||||
|
||||
});
|
||||
@ -4,6 +4,7 @@
|
||||
if (!window.navigator.onLine){
|
||||
console.log("offline");
|
||||
$(".info_message").show();
|
||||
$(".info_message").show();
|
||||
}
|
||||
"use strict";
|
||||
var input = $('.validate-input .input-forms');
|
||||
@ -25,7 +26,7 @@
|
||||
success: function(data, status, jqXHR) {
|
||||
console.log(data.trim());
|
||||
if (data.trim() == "true"){
|
||||
location.href='/';
|
||||
location.href='/accueil.php';
|
||||
} else {
|
||||
$("#zone-login").addClass("shaking_error");
|
||||
setTimeout(function() {
|
||||
@ -79,11 +80,29 @@ $('.hidden').delay(300).fadeIn(400);
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
navigator.serviceWorker.register('sw.js')
|
||||
.then(registration => {
|
||||
console.log(`Service Worker enregistré ! Ressource: ${registration.scope}`);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(`Echec de l'enregistrement du Service Worker: ${err}`);
|
||||
});
|
||||
.then(registration => {console.log(`[SW] enregistré ! ${registration.scope}`);})
|
||||
.catch(err => {console.log(`[SW] Echec de l'enregistrement: ${err}`);});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
function getCookie(user) {
|
||||
var cookieArr = document.cookie.split(";");
|
||||
for (var i = 0; i < cookieArr.length; i++) {
|
||||
var cookiePair = cookieArr[i].split("=");
|
||||
if (user == cookiePair[0].trim()) {
|
||||
return decodeURIComponent(cookiePair[1]);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function checkCookie() {
|
||||
var username = getCookie("username");
|
||||
var pass = getCookie("pass");
|
||||
if (!(username != "" && username != null && pass != null && pass != null)) {
|
||||
console.log("no cookie");
|
||||
}
|
||||
}
|
||||
checkCookie();*/
|
||||
@ -28,6 +28,8 @@ if (isset($_COOKIE['username']) && isset($_COOKIE['pass'])) {
|
||||
$ID_add_company = $query_add_company->fetchALL(PDO::FETCH_OBJ)[0]->ID_company;
|
||||
$query_add_company = $bdd->prepare('INSERT INTO companies_located VALUES (:ID_localisation, :ID_company);');
|
||||
$query_add_company->execute(['ID_localisation' => $_POST["localisation"], 'ID_company' => $ID_add_company]);
|
||||
$query_add_company = $bdd->prepare('INSERT INTO companies_located VALUES (:ID_localisation, :ID_company);');
|
||||
$query_add_company->execute(['ID_localisation' => $_POST["localisation"], 'ID_company' => $ID_add_company]);
|
||||
echo "<script>location.href='/gestion_entreprises.php';</script>";
|
||||
} catch (Exception $e) {
|
||||
echo "false";
|
||||
|
||||
35
website/fallback.php
Normal file
35
website/fallback.php
Normal file
@ -0,0 +1,35 @@
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<title>Offline</title>
|
||||
<meta name="description" content="description">
|
||||
<link rel="stylesheet" href="http://ctsstatic.fr/assets/vendors/fontawesome/css/all.min.css">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/png" href="http://ctsstatic.fr/assets/images/logo_petit.png">
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" type="text/css" href="http://ctsstatic.fr/assets/css/a_propos.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="main">
|
||||
<div class="content">
|
||||
<div class="bubble">
|
||||
<img src="http://ctsstatic.fr/assets/images/fond_cesi_large.png" alt="fond cesi">
|
||||
<div class="centered">Aucune connexion à internet</div>
|
||||
</div>
|
||||
<div class="bubble">
|
||||
<div class="title_bubble">Page inaccessible en mode hors ligne.</div>
|
||||
<div class="text_content">
|
||||
Due à un manque de connexion internet, nous ne pouvez pas afficher cette page.
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<a class="btnvoir" href="/">
|
||||
<span>Retour à la page de connexion</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,15 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<?php
|
||||
if (isset($_COOKIE['username']) && isset($_COOKIE['pass'])) {
|
||||
require "controller/ConnexionBDD.php";
|
||||
if (!$error) {
|
||||
$query = $bdd->prepare('SELECT * FROM users NATURAL JOIN roles NATURAL JOIN roles_has_permissions NATURAL JOIN permissions WHERE code_permission="SFx1" AND username=:user AND password_user=:password_user;');
|
||||
$query->execute(['user' => $_COOKIE['username'], 'password_user' => $_COOKIE['pass']]);
|
||||
if ($query->rowCount() == 1){echo "<script>location.href='/accueil.php';</script>";}
|
||||
else {echo "<script>location.href='/controller/Disconnect.php';</script>";}
|
||||
}
|
||||
} else {
|
||||
?>
|
||||
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<title>Connexion - CTS</title>
|
||||
@ -27,7 +17,11 @@ if (isset($_COOKIE['username']) && isset($_COOKIE['pass'])) {
|
||||
<div class="boite-login">
|
||||
<div id="zone-login" class="zone-login hidden">
|
||||
<form method="post" class="form-login validate">
|
||||
<div class="info_message">Erreur de connexion Internet, veuillez vous connecter</div>
|
||||
<div class="info_message">
|
||||
Erreur de connexion Internet, veuillez vous connecter
|
||||
<br>
|
||||
<a href="/favoris.php">Accès aux favoris</a>
|
||||
</div>
|
||||
|
||||
<span class="form-title"><img src="http://ctsstatic.fr/assets/images/logo.png" alt="Cesi Ton Stage"></span>
|
||||
|
||||
@ -37,7 +31,7 @@ if (isset($_COOKIE['username']) && isset($_COOKIE['pass'])) {
|
||||
</div>
|
||||
|
||||
<div class="zone-input validate-input" data-validate = "Saisissez un mot de passe">
|
||||
<input class="input-forms" id="passwd" type="password" name="pass" placeholder="Mot de passe">
|
||||
<input class="input-forms" id="passwd" type="password" me="pass" placeholder="Mot de passe">
|
||||
<span class="focus-input"></span>
|
||||
</div>
|
||||
|
||||
@ -57,6 +51,3 @@ if (isset($_COOKIE['username']) && isset($_COOKIE['pass'])) {
|
||||
<script src="http://ctsstatic.fr/assets/js/index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
@ -1,59 +1,63 @@
|
||||
importScripts(
|
||||
'https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js'
|
||||
);
|
||||
if (workbox) {
|
||||
console.log(`Super ! Workbox est chargé 🎉`);
|
||||
|
||||
workbox.routing.registerRoute(
|
||||
/\.(?:html|js|css|png|jpg|jpeg|svg|gif)$/,
|
||||
new workbox.strategies.StaleWhileRevalidate()
|
||||
);
|
||||
}
|
||||
|
||||
//Installation du service worker
|
||||
self.addEventListener('install', (e) => {
|
||||
console.log('[Service Worker] Installation');
|
||||
var cacheName = 'CTS_v2';
|
||||
var appShellFiles = [
|
||||
'index.php',
|
||||
const staticCacheName = "site_static_v1";
|
||||
const dynamicCacheName = "site_dynamic_v1";
|
||||
const assets = [
|
||||
'./',
|
||||
'./index.php',
|
||||
'./fallback.php',
|
||||
'./manifest/manifest.json',
|
||||
'http://ctsstatic.fr/assets/css/index.css',
|
||||
'http://ctsstatic.fr/assets/css/a_propos.css',
|
||||
'http://ctsstatic.fr/assets/images/fond_cesi_large.png',
|
||||
'http://ctsstatic.fr/assets/vendors/fontawesome/css/all.min.css',
|
||||
'http://ctsstatic.fr/assets/js/index.js',
|
||||
'http://ctsstatic.fr/assets/js/nav_bar.js',
|
||||
'http://ctsstatic.fr/assets/css/nav_bar.css',
|
||||
'http://ctsstatic.fr/assets/images/logo.png',
|
||||
'http://ctsstatic.fr/assets/images/logo144.png',
|
||||
'http://ctsstatic.fr/assets/images/logo_petit.png',
|
||||
'http://ctsstatic.fr/assets/vendors/jquery/jquery-3.6.0.min.js'
|
||||
];
|
||||
'http://ctsstatic.fr/assets/vendors/jquery/jquery-3.6.0.min.js',
|
||||
'http://ctsstatic.fr/assets/js/sha1.min.js',
|
||||
'http://ctsstatic.fr/assets/fonts/Fredoka-Regular.ttf',
|
||||
];
|
||||
|
||||
e.waitUntil(
|
||||
caches.open(cacheName).then((cache) => {
|
||||
console.log('[Service Worker] Mise en cache globale: app shell et contenu')
|
||||
return cache.addAll(appShellFiles);
|
||||
}))
|
||||
self.addEventListener('install', evt => { //Event à l'installation
|
||||
//console.log("installed");
|
||||
evt.waitUntil( //Ne s'arrete pas tant que le cache n'est complet
|
||||
caches.open(staticCacheName).then(cache => {
|
||||
console.log("Caching assets");
|
||||
cache.addAll(assets);
|
||||
})
|
||||
)
|
||||
});
|
||||
|
||||
//fetch event afin de répondre quand on est en mode hors ligne.
|
||||
self.addEventListener('fetch', (e) => {
|
||||
e.respondWith(
|
||||
caches.open('ma_sauvegarde').then(function(cache) {
|
||||
return cache.match(e.request).then(function (response) {
|
||||
return response || fetch(e.request).then(function(response) {
|
||||
cache.put(e.request, response.clone());
|
||||
return response;
|
||||
});
|
||||
});
|
||||
self.addEventListener('activate', evt => {
|
||||
//console.log("activated");
|
||||
evt.waitUntil(
|
||||
caches.keys().then(keys => {
|
||||
//console.log(keys);
|
||||
return Promise.all(keys
|
||||
.filter(key => key !== staticCacheName && key !== dynamicCacheName)
|
||||
.map(key => caches.delete(key)))
|
||||
})
|
||||
);
|
||||
});
|
||||
/*
|
||||
self.addEventListener('fetch', (e) => {
|
||||
e.respondWith(
|
||||
caches.match(e.request).then((r) => {
|
||||
console.log('[Service Worker] Récupération de la ressource: '+e.request.url);
|
||||
return r || fetch(e.request).then((response) => {
|
||||
return caches.open(cacheName).then((cache) => {
|
||||
console.log('[Service Worker] Mise en cache de la nouvelle ressource: '+e.request.url);
|
||||
cache.put(e.request, response.clone());
|
||||
return response;
|
||||
});
|
||||
|
||||
/*self.addEventListener('fetch', evt => {
|
||||
evt.respondWith(
|
||||
caches.match(evt.request).then(cacheRes => {
|
||||
console.log(evt.request);
|
||||
return cacheRes || fetch(evt.request).then(fetchRes => {
|
||||
return caches.open(dynamicCacheName).then(cache => {
|
||||
if (evt.request.url.indexOf('favoris') > -1){
|
||||
cache.put(evt.request.url, fetchRes.clone());
|
||||
}
|
||||
return fetchRes;
|
||||
})
|
||||
});
|
||||
}).catch(() => {
|
||||
console.log("Erreur d'accès à :", evt.request.url)
|
||||
return caches.match('/fallback.php');
|
||||
})
|
||||
);
|
||||
});*/
|
||||
});
|
||||
*/
|
||||
Loading…
x
Reference in New Issue
Block a user