diff --git a/db/setup.php b/db/setup.php index ef76881..c16c8d3 100644 --- a/db/setup.php +++ b/db/setup.php @@ -10,13 +10,21 @@ try { $pdo->exec(" CREATE TABLE IF NOT EXISTS `users` ( `id` INT AUTO_INCREMENT PRIMARY KEY, - `username` VARCHAR(255) NOT NULL UNIQUE, + `username` VARCHAR(255) NOT NULL, + `email` VARCHAR(255) NOT NULL UNIQUE, `password` VARCHAR(255) NOT NULL, `role` VARCHAR(50) NOT NULL, + `birth_date` DATE, `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; "); + // Add columns if they don't exist + try { $pdo->exec("ALTER TABLE `users` ADD COLUMN `email` VARCHAR(255) NOT NULL UNIQUE AFTER `username`"); } catch (PDOException $e) { /* Ignore */ } + try { $pdo->exec("ALTER TABLE `users` ADD COLUMN `birth_date` DATE AFTER `role`"); } catch (PDOException $e) { /* Ignore */ } + // We can't easily remove the unique constraint in a single command that works on all versions, so we'll leave it for now. + // The signup logic will handle this by checking for existing usernames. + // Create clubs table $pdo->exec(" CREATE TABLE IF NOT EXISTS `clubs` ( @@ -49,12 +57,14 @@ try { } else { // Insert default superadmin user $username = 'superadmin'; + $email = 'superadmin@picklepro.com'; $password = 'superadmin'; // Default password, you should change this $hashed_password = password_hash($password, PASSWORD_DEFAULT); $role = 'superadmin'; - $stmt = $pdo->prepare("INSERT INTO users (username, password, role) VALUES (:username, :password, :role)"); + $stmt = $pdo->prepare("INSERT INTO users (username, email, password, role) VALUES (:username, :email, :password, :role)"); $stmt->bindParam(':username', $username); + $stmt->bindParam(':email', $email); $stmt->bindParam(':password', $hashed_password); $stmt->bindParam(':role', $role); $stmt->execute(); diff --git a/index.php b/index.php index fc0c99b..3c594a5 100644 --- a/index.php +++ b/index.php @@ -61,7 +61,9 @@ Sair Entrar - Cadastrar + @@ -70,6 +72,16 @@
+ + + + + +

Seu Portal Completo de Pickleball

@@ -167,6 +179,43 @@ + + + diff --git a/signup.php b/signup.php new file mode 100644 index 0000000..b70f662 --- /dev/null +++ b/signup.php @@ -0,0 +1,58 @@ +prepare('SELECT id FROM users WHERE email = ?'); + $stmt->execute([$email]); + if ($stmt->fetch()) { + $_SESSION['error_message'] = 'Este e-mail já está cadastrado.'; + header('Location: index.php'); + exit; + } + + // Insert new user + $hashedPassword = password_hash($password, PASSWORD_DEFAULT); + $stmt = $pdo->prepare('INSERT INTO users (username, email, password, role, birth_date) VALUES (?, ?, ?, ?, ?)'); + $stmt->execute([$fullName, $email, $hashedPassword, 'atleta', $birthDate]); + + $_SESSION['success_message'] = 'Cadastro realizado com sucesso! Você já pode fazer o login.'; + header('Location: index.php'); + exit; + + } catch (PDOException $e) { + $_SESSION['error_message'] = 'Erro no banco de dados. Tente novamente mais tarde.'; + // In a real app, you would log this error: error_log($e->getMessage()); + header('Location: index.php'); + exit; + } +}