feat(auth): add login/logout, user identity, and soft auth gate
- api/logout.php: destroys session + clears cookie, redirects to / - api/guest-session.php: sets guest flag, lets users explore without account - layout.php: removes hard PHP redirect; authenticated users see email + "Logg ut" in topbar; guests see guest banner (sticky, dismissible) and auth gate modal (dismissible via localStorage) instead of redirect - layout_footer.php: injects auth gate modal + JS for banner/modal dismiss - layout_dashboard.php: adds username + "Logg ut" to dash-topbar - index.php: adds "Utforsk uten konto" link under primary login CTA - tools.css: .guest-banner, .auth-gate-*, .topbar-user, .dash-topbar__user Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -47,5 +47,60 @@
|
||||
</menu>
|
||||
</form>
|
||||
</dialog>
|
||||
|
||||
<?php if (!empty($layoutIsGuest)): ?>
|
||||
<!-- Auth gate modal — shown to unauthenticated visitors unless they dismissed it -->
|
||||
<div id="authGate" class="auth-gate-backdrop" hidden aria-modal="true" role="dialog" aria-labelledby="authGateTitle">
|
||||
<div class="auth-gate-card">
|
||||
<p class="auth-gate-eyebrow">Do Better Norge</p>
|
||||
<h2 id="authGateTitle" class="auth-gate-title">Logg inn for å bruke verktøyene</h2>
|
||||
<p class="auth-gate-body">Våre juridiske AI-verktøy krever en gratis konto. Registrer deg på sekunder med Google.</p>
|
||||
<div class="auth-gate-actions">
|
||||
<a id="authGateLogin" href="/?return=<?= htmlspecialchars($layoutReturnUrl ?? '') ?>" class="auth-gate-btn auth-gate-btn--primary">Logg inn / Registrer deg</a>
|
||||
<button id="authGateDismiss" class="auth-gate-btn auth-gate-btn--ghost">Fortsett uten konto</button>
|
||||
</div>
|
||||
<p class="auth-gate-note">Gratis tilgang · Ingen kredittkort</p>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
(function () {
|
||||
'use strict';
|
||||
var GATE_KEY = 'dbn-auth-gate-v1';
|
||||
var BANNER_KEY = 'dbn-guest-banner-v1';
|
||||
var gate = document.getElementById('authGate');
|
||||
var banner = document.getElementById('guestBanner');
|
||||
var bannerClose = document.getElementById('guestBannerClose');
|
||||
|
||||
// Show or hide the guest banner
|
||||
if (banner) {
|
||||
if (localStorage.getItem(BANNER_KEY) === 'closed') {
|
||||
banner.hidden = true;
|
||||
}
|
||||
if (bannerClose) {
|
||||
bannerClose.addEventListener('click', function () {
|
||||
localStorage.setItem(BANNER_KEY, 'closed');
|
||||
banner.hidden = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Show auth gate modal unless already dismissed
|
||||
if (gate && localStorage.getItem(GATE_KEY) !== 'dismissed') {
|
||||
gate.hidden = false;
|
||||
document.getElementById('authGateDismiss').addEventListener('click', function () {
|
||||
localStorage.setItem(GATE_KEY, 'dismissed');
|
||||
gate.hidden = true;
|
||||
});
|
||||
// Close on backdrop click
|
||||
gate.addEventListener('click', function (e) {
|
||||
if (e.target === gate) {
|
||||
localStorage.setItem(GATE_KEY, 'dismissed');
|
||||
gate.hidden = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}());
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user