tolto username

This commit is contained in:
2026-10-07 16:42:59 +02:00
parent 6decde261b
commit 45279d53f1
+3 -26
View File
@@ -46,7 +46,7 @@ function isOwnAvatarFile($name): bool
function loadUser(PDO $pdo, int $id) function loadUser(PDO $pdo, int $id)
{ {
$stmt = $pdo->prepare( $stmt = $pdo->prepare(
"SELECT id, email, username, password, first_name, last_name, phone, address, "SELECT id, email, password, first_name, last_name, phone, address,
country_id, birthday, avatar, created_at country_id, birthday, avatar, created_at
FROM auth_users FROM auth_users
WHERE id = :id WHERE id = :id
@@ -92,7 +92,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action !== '') {
/* ---------- Dati personali ---------- */ /* ---------- Dati personali ---------- */
$firstName = trim($_POST['first_name'] ?? ''); $firstName = trim($_POST['first_name'] ?? '');
$lastName = trim($_POST['last_name'] ?? ''); $lastName = trim($_POST['last_name'] ?? '');
$username = trim($_POST['username'] ?? '');
$phone = trim($_POST['phone'] ?? ''); $phone = trim($_POST['phone'] ?? '');
$address = trim($_POST['address'] ?? ''); $address = trim($_POST['address'] ?? '');
$birthdayInput = trim($_POST['birthday'] ?? ''); $birthdayInput = trim($_POST['birthday'] ?? '');
@@ -112,18 +111,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action !== '') {
} }
} }
// Username facoltativo ma univoco
if ($username !== '') {
if (!preg_match('/^[A-Za-z0-9._-]{3,50}$/', $username)) {
$errors[] = 'Lo username può contenere lettere, numeri, punto, trattino e underscore (da 3 a 50 caratteri).';
} else {
$chk = $pdo->prepare("SELECT 1 FROM auth_users WHERE username = :u AND id <> :id LIMIT 1");
$chk->execute([':u' => $username, ':id' => $iduserlogin]);
if ($chk->fetchColumn()) {
$errors[] = 'Questo username è già usato da un altro utente.';
}
}
}
// Telefono facoltativo // Telefono facoltativo
if ($phone !== '' && !preg_match('/^[0-9+\s().\/-]{6,30}$/', $phone)) { if ($phone !== '' && !preg_match('/^[0-9+\s().\/-]{6,30}$/', $phone)) {
@@ -159,8 +146,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action !== '') {
if (empty($errors)) { if (empty($errors)) {
$sql = "UPDATE auth_users SET $sql = "UPDATE auth_users SET
first_name = :first_name, first_name = :first_name,
last_name = :last_name, last_name = :last_name,
username = :username,
phone = :phone, phone = :phone,
address = :address, address = :address,
birthday = :birthday, birthday = :birthday,
@@ -171,7 +157,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action !== '') {
$ok = $stmt->execute([ $ok = $stmt->execute([
':first_name' => $firstName, ':first_name' => $firstName,
':last_name' => $lastName, ':last_name' => $lastName,
':username' => $username !== '' ? $username : null,
':phone' => $phone !== '' ? $phone : null, ':phone' => $phone !== '' ? $phone : null,
':address' => $address !== '' ? $address : null, ':address' => $address !== '' ? $address : null,
':birthday' => $birthdayDb, ':birthday' => $birthdayDb,
@@ -191,7 +176,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action !== '') {
$postedProfile = array_merge($user, [ $postedProfile = array_merge($user, [
'first_name' => $firstName, 'first_name' => $firstName,
'last_name' => $lastName, 'last_name' => $lastName,
'username' => $username,
'phone' => $phone, 'phone' => $phone,
'address' => $address, 'address' => $address,
'country_id' => $countryInput, 'country_id' => $countryInput,
@@ -992,7 +976,7 @@ function renderFeedback(?array $fb): void
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-12">
<div class="form-field"> <div class="form-field">
<label for="email">Email</label> <label for="email">Email</label>
<div class="locked-field"> <div class="locked-field">
@@ -1003,13 +987,6 @@ function renderFeedback(?array $fb): void
<span class="field-hint">L'email serve per l'accesso e non si può modificare da qui. Per cambiarla contatta la segreteria.</span> <span class="field-hint">L'email serve per l'accesso e non si può modificare da qui. Per cambiarla contatta la segreteria.</span>
</div> </div>
</div> </div>
<div class="col-md-6">
<div class="form-field">
<label for="username">Username <span class="text-muted fw-normal">(facoltativo)</span></label>
<input type="text" id="username" name="username" class="form-control"
value="<?php echo e($form['username']); ?>" maxlength="50" autocomplete="nickname">
</div>
</div>
</div> </div>
<div class="row"> <div class="row">