fix
This commit is contained in:
119
forgot_password.php
Normal file
119
forgot_password.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* Pagina Recupero Password - Step 1
|
||||
*
|
||||
* L'utente inserisce la sua email e riceve un link per resettare la password
|
||||
*/
|
||||
|
||||
require_once 'includes/config.php';
|
||||
require_once 'includes/functions.php';
|
||||
|
||||
session_start();
|
||||
|
||||
// Se l'utente è già loggato, reindirizza
|
||||
if (is_logged_in()) {
|
||||
header('Location: user/dashboard.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$email = '';
|
||||
$error = '';
|
||||
$success = false;
|
||||
|
||||
// Processa il form se inviato
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$email = sanitize_input($_POST['email'] ?? '');
|
||||
|
||||
// Validazione
|
||||
if (empty($email)) {
|
||||
$error = 'Inserisci il tuo indirizzo email';
|
||||
} elseif (!validate_email($email)) {
|
||||
$error = 'Email non valida';
|
||||
} else {
|
||||
// Cerca l'utente
|
||||
$user = get_user_by_email($email);
|
||||
|
||||
if ($user) {
|
||||
// Crea token di reset
|
||||
$token = create_password_reset_token($user['id']);
|
||||
|
||||
// Invia email
|
||||
if (send_password_reset_email($email, $token)) {
|
||||
$success = true;
|
||||
} else {
|
||||
$error = 'Errore nell\'invio dell\'email. Riprova più tardi.';
|
||||
}
|
||||
} else {
|
||||
// Per sicurezza, mostra lo stesso messaggio anche se l'email non esiste
|
||||
// Questo previene di scoprire quali email sono registrate
|
||||
$success = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Recupero Password - Pilates Platform</title>
|
||||
<link rel="stylesheet" href="assets/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container-sm" style="padding-top: 3rem;">
|
||||
<div class="card">
|
||||
<div class="text-center mb-3">
|
||||
<h1 class="logo">Pilates Studio</h1>
|
||||
</div>
|
||||
|
||||
<h2 class="card-header text-center">Recupero Password</h2>
|
||||
|
||||
<?php if ($success): ?>
|
||||
<div class="alert alert-success">
|
||||
<strong>Email inviata!</strong><br>
|
||||
Se l'indirizzo email è registrato, riceverai un'email con le istruzioni per reimpostare la password.
|
||||
Controlla anche la cartella spam.
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<a href="login.php" class="btn btn-primary">Torna al Login</a>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-error">
|
||||
<?php echo htmlspecialchars($error); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<p class="text-muted text-center mb-2">
|
||||
Inserisci il tuo indirizzo email e ti invieremo un link per reimpostare la password.
|
||||
</p>
|
||||
|
||||
<form method="POST" action="">
|
||||
<div class="form-group">
|
||||
<label for="email" class="form-label">Email</label>
|
||||
<input
|
||||
type="email"
|
||||
id="email"
|
||||
name="email"
|
||||
class="form-control"
|
||||
value="<?php echo htmlspecialchars($email); ?>"
|
||||
required
|
||||
autofocus
|
||||
>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary btn-large" style="width: 100%;">
|
||||
Invia Link di Reset
|
||||
</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="text-center mt-2">
|
||||
<p class="mt-2">
|
||||
<a href="login.php">← Torna al Login</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user