Merged in feature/MAPG-172-create-cookie-notice (pull request #139)

Feature/MAPG-172 create cookie notice
This commit is contained in:
Bence Pőcze 2020-06-24 20:03:29 +00:00
commit e200dab2a4
4 changed files with 59 additions and 9 deletions

View File

@ -84,7 +84,7 @@ hr {
}
p.small, span.small {
font-size: 12px;
font-size: 14px;
}
.justify {
@ -148,6 +148,13 @@ button, a.button {
line-height: 35px;
}
button.small {
font-size: 14px;
padding: 0 12px;
height: 32px;
line-height: 32px;
}
button:enabled:hover, button:enabled:focus, a.button:hover, a.button:focus {
background-color: #29457f;
outline: none;
@ -336,6 +343,12 @@ div.buttonContainer>button {
margin: 0 auto;
}
#cookiesNotice {
background-color: #eeeeee;
padding: 10px;
text-align: center;
}
#loading {
position: fixed;
width: 64px;

View File

@ -14,5 +14,30 @@
<script src="<?= $jsFile ?>"></script>
<?php endforeach; ?>
<?php endif; ?>
<?php if (!isset($_COOKIE['COOKIES_CONSENT'])): ?>
<script>
(function () {
MapGuesser = {
cookiesAgreed: false,
agreeCookies: function () {
if (MapGuesser.cookiesAgreed) {
return;
}
var expirationDate = new Date(new Date().getTime() + 20 * 365 * 24 * 60 * 60 * 1000).toUTCString();
document.cookie = 'COOKIES_CONSENT=1; expires=' + expirationDate + '; path=/';
MapGuesser.cookiesAgreed = true;
document.getElementById('cookiesNotice').style.display = 'none';
}
};
window.onclick = function () {
MapGuesser.agreeCookies();
};
})();
</script>
<?php endif; ?>
</body>
</html>

View File

@ -22,6 +22,14 @@
<link rel="icon" type="image/png" sizes="16x16" href="<?= $_ENV['STATIC_ROOT'] ?>/img/favicon/16x16.png?rev=<?= REVISION ?>">
</head>
<body>
<?php if (!isset($_COOKIE['COOKIES_CONSENT'])): ?>
<div id="cookiesNotice">
<p class="small">
<?= $_ENV['APP_NAME'] ?> uses cookies to improve user experience. By using the app or clicking I agree, you consent to our use of cookies.
</p>
<button id="agreeCookies" class="small marginTop">I agree</button>
</div>
<?php endif; ?>
<div id="loading">
<img src="<?= $_ENV['STATIC_ROOT'] ?>/img/loading.svg?rev=<?= REVISION ?>" width="64" height="64">
</div>

12
web.php
View File

@ -49,15 +49,19 @@ Container::$routeCollection->group('admin', function (MapGuesser\Routing\RouteCo
$routeCollection->post('admin.deleteMap', 'deleteMap/{mapId}', [MapGuesser\Controller\MapAdminController::class, 'deleteMap']);
});
Container::$sessionHandler = new MapGuesser\Session\DatabaseSessionHandler();
if (isset($_COOKIE['COOKIES_CONSENT'])) {
Container::$sessionHandler = new MapGuesser\Session\DatabaseSessionHandler();
session_set_save_handler(Container::$sessionHandler, true);
session_start([
session_set_save_handler(Container::$sessionHandler, true);
session_start([
'gc_maxlifetime' => 604800,
'cookie_lifetime' => 604800,
'cookie_httponly' => true,
'cookie_samesite' => 'Lax'
]);
]);
} else {
$_SESSION = [];
}
Container::$request = new MapGuesser\Request\Request($_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'], $_GET, $_POST, $_SESSION);