1
This commit is contained in:
parent
139ac6de00
commit
fa3707bf3d
14
db/setup.php
14
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();
|
||||
|
||||
51
index.php
51
index.php
@ -61,7 +61,9 @@
|
||||
<a href="logout.php" class="btn btn-outline-primary">Sair</a>
|
||||
<?php else: ?>
|
||||
<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; ?>
|
||||
</div>
|
||||
</div>
|
||||
@ -70,6 +72,16 @@
|
||||
|
||||
<!-- Main Content -->
|
||||
<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">
|
||||
<h1 class="display-5 fw-bold">Seu Portal Completo de <span class="text-primary">Pickleball</span></h1>
|
||||
</div>
|
||||
@ -167,6 +179,43 @@
|
||||
</div>
|
||||
</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 -->
|
||||
<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>
|
||||
|
||||
58
signup.php
Normal file
58
signup.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user