This commit is contained in:
Mr_sl1d3r 2025-10-30 15:53:18 +01:00
parent 98bdf7935f
commit ee62019331
1 changed files with 100 additions and 1 deletions

101
index.php
View File

@ -47,7 +47,7 @@ $username = isset($_SESSION['username']) ? $_SESSION['username'] : null;
<a href="./php/auth/logout.php" class="px-4 py-2 bg-[#84dd63] text-[#1f2937] rounded hover:bg-[#cbff4d]">Logout</a>
<?php else: ?>
<button id="openLogin" class="px-4 py-2 bg-[#84dd63] text-[#1f2937] rounded hover:bg-[#cbff4d]">Login</button>
<button class="px-4 py-2 bg-[#69747c] text-white rounded opacity-80 cursor-not-allowed">Registrati (presto)</button>
<button id="openRegister" class="px-4 py-2 bg-[#69747c] text-white rounded hover:bg-[#545454]">Registrati</button>
<?php endif; ?>
</div>
</div>
@ -64,6 +64,7 @@ $username = isset($_SESSION['username']) ? $_SESSION['username'] : null;
<a href="#" class="px-5 py-2 bg-[#6baa75] text-white rounded hover:bg-[#84dd63]">Sfoglia Catalogo</a>
<?php if (!$isLogged): ?>
<button id="openLogin2" class="px-5 py-2 bg-[#545454] text-white rounded hover:bg-[#69747c]">Accedi</button>
<button id="openRegister2" class="px-5 py-2 bg-[#69747c] text-white rounded hover:bg-[#545454]">Registrati</button>
<?php endif; ?>
</div>
</div>
@ -100,6 +101,58 @@ $username = isset($_SESSION['username']) ? $_SESSION['username'] : null;
</div>
</div>
<!-- Modal Registrazione -->
<div id="registerModal" class="fixed inset-0 bg-black/40 hidden items-center justify-center">
<div class="bg-white w-full max-w-2xl rounded-lg shadow-lg p-6">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-semibold text-[#545454]">Registrazione Utente</h3>
<button id="closeRegister" class="text-[#69747c] hover:text-[#545454]"></button>
</div>
<form id="registerForm" class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm text-[#69747c]">Nome</label>
<input type="text" name="nome" required class="mt-1 w-full border rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-[#84dd63]">
</div>
<div>
<label class="block text-sm text-[#69747c]">Cognome</label>
<input type="text" name="cognome" required class="mt-1 w-full border rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-[#84dd63]">
</div>
<div>
<label class="block text-sm text-[#69747c]">Data di nascita</label>
<input type="date" name="data_nascita" required class="mt-1 w-full border rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-[#84dd63]">
</div>
<div>
<label class="block text-sm text-[#69747c]">Luogo di nascita</label>
<input type="text" name="luogo_nascita" required class="mt-1 w-full border rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-[#84dd63]">
</div>
<div>
<label class="block text-sm text-[#69747c]">Codice Fiscale</label>
<input type="text" name="cod_fiscale" maxlength="16" required class="mt-1 w-full border rounded px-3 py-2 uppercase focus:outline-none focus:ring-2 focus:ring-[#84dd63]">
</div>
<div>
<label class="block text-sm text-[#69747c]">Telefono</label>
<input type="tel" name="telefono" maxlength="10" required class="mt-1 w-full border rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-[#84dd63]">
</div>
<div class="md:col-span-2 mt-2 border-t pt-4">
<h2 class="text-lg font-semibold text-[#545454]">Credenziali di accesso</h2>
</div>
<div>
<label class="block text-sm text-[#69747c]">Username</label>
<input type="text" name="username" required class="mt-1 w-full border rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-[#84dd63]" placeholder="es. utente@mail.com">
</div>
<div>
<label class="block text-sm text-[#69747c]">Password</label>
<input type="password" name="password" required class="mt-1 w-full border rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-[#84dd63]" placeholder="Almeno 8 caratteri, maiuscola, minuscola, speciale">
</div>
<div id="registerError" class="md:col-span-2 hidden text-red-600 text-sm"></div>
<div id="registerOk" class="md:col-span-2 hidden text-green-700 text-sm"></div>
<div class="md:col-span-2 mt-2">
<button type="submit" class="w-full bg-[#6baa75] text-white rounded py-2 hover:bg-[#84dd63]">Registrati</button>
</div>
</form>
</div>
</div>
<script>
$(function() {
const $modal = $('#loginModal');
@ -128,6 +181,52 @@ $username = isset($_SESSION['username']) ? $_SESSION['username'] : null;
}
});
});
const $regModal = $('#registerModal');
$('#openRegister, #openRegister2').on('click', function(){ $regModal.removeClass('hidden').addClass('flex'); });
$('#closeRegister').on('click', function(){ $regModal.addClass('hidden').removeClass('flex'); $('#registerError').addClass('hidden').text(''); $('#registerOk').addClass('hidden').text(''); });
function clientValidate(pwd){
if(/\s/.test(pwd)) return 'La password non deve contenere spazi';
if(pwd.length < 8) return 'La password deve avere almeno 8 caratteri';
if(!/[a-z]/.test(pwd)) return 'La password deve contenere almeno una minuscola';
if(!/[A-Z]/.test(pwd)) return 'La password deve contenere almeno una maiuscola';
if(!/[^a-zA-Z0-9]/.test(pwd)) return 'La password deve contenere almeno un carattere speciale';
return null;
}
$('#registerForm').on('submit', function(e){
e.preventDefault();
const $err = $('#registerError');
const $ok = $('#registerOk');
$err.addClass('hidden').text('');
$ok.addClass('hidden').text('');
const pwd = $(this).find('input[name="password"]').val();
const v = clientValidate(pwd);
if (v) { $err.removeClass('hidden').text(v); return; }
$.ajax({
url: './php/auth/register.php',
method: 'POST',
data: $(this).serialize(),
headers: { 'X-Requested-With': 'XMLHttpRequest' },
success: function(resp){
try { resp = typeof resp === 'string' ? JSON.parse(resp) : resp; } catch(_) {}
if (resp && resp.status === 'ok') {
$ok.removeClass('hidden').text('Registrazione completata. Reindirizzamento...');
setTimeout(function(){ window.location.reload(); }, 800);
} else {
const msg = resp && resp.errors ? resp.errors.join(' | ') : 'Registrazione non riuscita';
$err.removeClass('hidden').text(msg);
}
},
error: function(){
$err.removeClass('hidden').text('Errore di rete. Riprovare.');
}
});
});
});
</script>
</body>