This commit is contained in:
Flatlogic Bot 2025-10-21 00:17:39 +00:00
parent 139ac6de00
commit fa3707bf3d
3 changed files with 120 additions and 3 deletions

View File

@ -10,13 +10,21 @@ try {
$pdo->exec(" $pdo->exec("
CREATE TABLE IF NOT EXISTS `users` ( CREATE TABLE IF NOT EXISTS `users` (
`id` INT AUTO_INCREMENT PRIMARY KEY, `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, `password` VARCHAR(255) NOT NULL,
`role` VARCHAR(50) NOT NULL, `role` VARCHAR(50) NOT NULL,
`birth_date` DATE,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ) 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 // Create clubs table
$pdo->exec(" $pdo->exec("
CREATE TABLE IF NOT EXISTS `clubs` ( CREATE TABLE IF NOT EXISTS `clubs` (
@ -49,12 +57,14 @@ try {
} else { } else {
// Insert default superadmin user // Insert default superadmin user
$username = 'superadmin'; $username = 'superadmin';
$email = 'superadmin@picklepro.com';
$password = 'superadmin'; // Default password, you should change this $password = 'superadmin'; // Default password, you should change this
$hashed_password = password_hash($password, PASSWORD_DEFAULT); $hashed_password = password_hash($password, PASSWORD_DEFAULT);
$role = 'superadmin'; $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(':username', $username);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':password', $hashed_password); $stmt->bindParam(':password', $hashed_password);
$stmt->bindParam(':role', $role); $stmt->bindParam(':role', $role);
$stmt->execute(); $stmt->execute();

View File

@ -61,7 +61,9 @@
<a href="logout.php" class="btn btn-outline-primary">Sair</a> <a href="logout.php" class="btn btn-outline-primary">Sair</a>
<?php else: ?> <?php else: ?>
<a href="/login.php" class="btn btn-link text-decoration-none me-2">Entrar</a> <a href="/login.php" class="btn btn-link text-decoration-none me-2">Entrar</a>
<a href="#" class="btn btn-primary">Cadastrar</a> <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#signupModal">
Cadastrar
</button>
<?php endif; ?> <?php endif; ?>
</div> </div>
</div> </div>
@ -70,6 +72,16 @@
<!-- Main Content --> <!-- Main Content -->
<main class="container my-4"> <main class="container my-4">
<?php if (isset($_SESSION['error_message'])): ?>
<div class="alert alert-danger" role="alert">
<?php echo $_SESSION['error_message']; unset($_SESSION['error_message']); ?>
</div>
<?php endif; ?>
<?php if (isset($_SESSION['success_message'])): ?>
<div class="alert alert-success" role="alert">
<?php echo $_SESSION['success_message']; unset($_SESSION['success_message']); ?>
</div>
<?php endif; ?>
<div class="text-center mb-5"> <div class="text-center mb-5">
<h1 class="display-5 fw-bold">Seu Portal Completo de <span class="text-primary">Pickleball</span></h1> <h1 class="display-5 fw-bold">Seu Portal Completo de <span class="text-primary">Pickleball</span></h1>
</div> </div>
@ -167,6 +179,43 @@
</div> </div>
</footer> </footer>
<!-- Signup Modal -->
<div class="modal fade" id="signupModal" tabindex="-1" aria-labelledby="signupModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="signupModalLabel">Cadastro de Atleta</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="signup.php" method="POST">
<div class="mb-3">
<label for="fullName" class="form-label">Nome Completo</label>
<input type="text" class="form-control" id="fullName" name="fullName" required>
</div>
<div class="mb-3">
<label for="birthDate" class="form-label">Data de Nascimento</label>
<input type="date" class="form-control" id="birthDate" name="birthDate" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">E-mail</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Senha</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="mb-3">
<label for="confirmPassword" class="form-label">Confirmar Senha</label>
<input type="password" class="form-control" id="confirmPassword" name="confirmPassword" required>
</div>
<button type="submit" class="btn btn-primary w-100">Cadastrar</button>
</form>
</div>
</div>
</div>
</div>
<!-- Scripts --> <!-- Scripts -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script> <script src="assets/js/main.js?v=<?php echo time(); ?>"></script>

58
signup.php Normal file
View File

@ -0,0 +1,58 @@
<?php
session_start();
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$fullName = $_POST['fullName'] ?? '';
$birthDate = $_POST['birthDate'] ?? '';
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
$confirmPassword = $_POST['confirmPassword'] ?? '';
// Validation
if (empty($fullName) || empty($birthDate) || empty($email) || empty($password) || empty($confirmPassword)) {
$_SESSION['error_message'] = 'Todos os campos são obrigatórios.';
header('Location: index.php');
exit;
}
if ($password !== $confirmPassword) {
$_SESSION['error_message'] = 'As senhas não correspondem.';
header('Location: index.php');
exit;
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$_SESSION['error_message'] = 'Formato de e-mail inválido.';
header('Location: index.php');
exit;
}
try {
$pdo = db();
// Check if user already exists
$stmt = $pdo->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;
}
}