Initial DEV environment from production snapshot

This commit is contained in:
2025-11-22 10:51:24 +00:00
commit 143a17a6e7
18 changed files with 474 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
/vendor/
/assets/*.log
/config.php
/smtp_config.php

0
assets/style.css Executable file
View File

53
auth/login.php Executable file
View File

@@ -0,0 +1,53 @@
<?php
require_once __DIR__ . '/../init.php';
if (is_logged_in()) header('Location: ../game/dashboard.php');
$error = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'] ?? '';
$pass = $_POST['password'] ?? '';
$pdo = getPDO();
$stmt = $pdo->prepare("SELECT id, password_hash FROM users WHERE email = ?");
$stmt->execute([$email]);
$row = $stmt->fetch();
if ($row && password_verify($pass, $row['password_hash'])) {
$_SESSION['user_id'] = $row['id'];
$_SESSION['user_email'] = $email;
header('Location: ../game/dashboard.php');
exit;
} else {
$error = 'Credenziali non valide.';
}
}
$page_title = 'Login';
include __DIR__ . '/../header.php';
?>
<div class="row justify-content-center">
<div class="col-md-6">
<h2>Login</h2>
<?php if($error): ?>
<div class="alert alert-danger"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<form method="post">
<div class="mb-3">
<label>Email</label>
<input type="email" name="email" class="form-control" required>
</div>
<div class="mb-3">
<label>Password</label>
<input type="password" name="password" class="form-control" required>
</div>
<button class="btn btn-primary">Accedi</button>
<a href="<?= BASE_URL ?>/auth/register.php" class="btn btn-link">Registrati</a>
</form>
</div>
</div>
<?php include __DIR__ . '/../footer.php'; ?>

4
auth/logout.php Executable file
View File

@@ -0,0 +1,4 @@
<?php
session_start();
session_destroy();
header("location: ../index.php");

79
auth/register.php Executable file
View File

@@ -0,0 +1,79 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../init.php';
require_once __DIR__ . '/../send_email.php';
if (is_logged_in()) header('Location: ../game/dashboard.php');
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = filter_var($_POST['email'] ?? '', FILTER_VALIDATE_EMAIL);
$pass = $_POST['password'] ?? '';
$pass2 = $_POST['password_confirm'] ?? '';
if (!$email) $errors[] = 'Inserisci un indirizzo email valido.';
if (strlen($pass) < 8) $errors[] = 'La password deve essere almeno 8 caratteri.';
if ($pass !== $pass2) $errors[] = 'Le password non coincidono.';
if (empty($errors)) {
$pdo = getPDO();
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
$stmt->execute([$email]);
if ($stmt->fetch()) {
$errors[] = 'Email già registrata.';
} else {
$hash = password_hash($pass, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (email, password_hash) VALUES (?, ?)");
$stmt->execute([$email, $hash]);
// Invia mail di benvenuto
$subject = "Benvenuto su Diplomacy Web App";
$body = "<p>Ciao ".htmlspecialchars($email).",</p>
<p>Grazie per esserti registrato su Diplomacy Web App. Ora puoi iniziare a giocare con i tuoi amici!</p>
<p>— Il team di Diplomacy</p>";
sendEmail($email, $subject, $body);
// Login automatico
$_SESSION['user_id'] = $pdo->lastInsertId();
$_SESSION['user_email'] = $email;
header('Location: ../game/dashboard.php');
exit;
}
}
}
$page_title = 'Registrati';
include __DIR__ . '/../header.php';
?>
<div class="row justify-content-center">
<div class="col-md-6">
<h2>Registrazione</h2>
<?php if(!empty($errors)): ?>
<div class="alert alert-danger">
<ul><?php foreach($errors as $e) echo "<li>".htmlspecialchars($e)."</li>"; ?></ul>
</div>
<?php endif; ?>
<form method="post" novalidate>
<div class="mb-3">
<label>Email</label>
<input type="email" name="email" class="form-control" required value="<?= htmlspecialchars($_POST['email'] ?? '') ?>">
</div>
<div class="mb-3">
<label>Password</label>
<input type="password" name="password" class="form-control" required>
</div>
<div class="mb-3">
<label>Conferma Password</label>
<input type="password" name="password_confirm" class="form-control" required>
</div>
<button class="btn btn-primary">Registrati</button>
</form>
</div>
</div>
<?php include __DIR__ . '/../footer.php'; ?>

5
composer.json Executable file
View File

@@ -0,0 +1,5 @@
{
"require": {
"phpmailer/phpmailer": "^7.0"
}
}

101
composer.lock generated Executable file
View File

@@ -0,0 +1,101 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "826f515f5ef16946d3e3ee3e3205b25e",
"packages": [
{
"name": "phpmailer/phpmailer",
"version": "v7.0.0",
"source": {
"type": "git",
"url": "https://github.com/PHPMailer/PHPMailer.git",
"reference": "c7111310c6116ba508a6a170a89eaaed2129bd42"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/c7111310c6116ba508a6a170a89eaaed2129bd42",
"reference": "c7111310c6116ba508a6a170a89eaaed2129bd42",
"shasum": ""
},
"require": {
"ext-ctype": "*",
"ext-filter": "*",
"ext-hash": "*",
"php": ">=5.5.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"doctrine/annotations": "^1.2.6 || ^1.13.3",
"php-parallel-lint/php-console-highlighter": "^1.0.0",
"php-parallel-lint/php-parallel-lint": "^1.3.2",
"phpcompatibility/php-compatibility": "^9.3.5",
"roave/security-advisories": "dev-latest",
"squizlabs/php_codesniffer": "^3.7.2",
"yoast/phpunit-polyfills": "^1.0.4"
},
"suggest": {
"decomplexity/SendOauth2": "Adapter for using XOAUTH2 authentication",
"ext-imap": "Needed to support advanced email address parsing according to RFC822",
"ext-mbstring": "Needed to send email in multibyte encoding charset or decode encoded addresses",
"ext-openssl": "Needed for secure SMTP sending and DKIM signing",
"greew/oauth2-azure-provider": "Needed for Microsoft Azure XOAUTH2 authentication",
"hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication",
"league/oauth2-google": "Needed for Google XOAUTH2 authentication",
"psr/log": "For optional PSR-3 debug logging",
"symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)",
"thenetworg/oauth2-azure": "Needed for Microsoft XOAUTH2 authentication"
},
"type": "library",
"autoload": {
"psr-4": {
"PHPMailer\\PHPMailer\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-2.1-only"
],
"authors": [
{
"name": "Marcus Bointon",
"email": "phpmailer@synchromedia.co.uk"
},
{
"name": "Jim Jagielski",
"email": "jimjag@gmail.com"
},
{
"name": "Andy Prevost",
"email": "codeworxtech@users.sourceforge.net"
},
{
"name": "Brent R. Matzelle"
}
],
"description": "PHPMailer is a full-featured email creation and transfer class for PHP",
"support": {
"issues": "https://github.com/PHPMailer/PHPMailer/issues",
"source": "https://github.com/PHPMailer/PHPMailer/tree/v7.0.0"
},
"funding": [
{
"url": "https://github.com/Synchro",
"type": "github"
}
],
"time": "2025-10-15T16:40:02+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.6.0"
}

1
diplomacy Submodule

Submodule diplomacy added at b28edd336a

7
footer.php Executable file
View File

@@ -0,0 +1,7 @@
</div> <!-- /container -->
<!-- jQuery e Bootstrap JS via CDN -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

0
game/create_game.php Executable file
View File

0
game/create_game_action.php Executable file
View File

99
game/dashboard.php Executable file
View File

@@ -0,0 +1,99 @@
<?php
session_start();
require_once __DIR__ . '/init.php';
if (!isset($_SESSION['user_id'])) {
header('Location: auth/login.php');
exit;
}
$pdo = getPDO();
// Info utente
$stmt = $pdo->prepare("SELECT id, email, created_at FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
// Partite dell'utente
$stmt = $pdo->prepare("
SELECT g.id, g.name, g.status, g.created_at
FROM games g
JOIN game_players gp ON g.id = gp.game_id
WHERE gp.user_id = ?
ORDER BY g.created_at DESC
");
$stmt->execute([$_SESSION['user_id']]);
$games = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!doctype html>
<html lang="it">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dashboard - Diplomacy</title>
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/custom.css" rel="stylesheet">
<style>
body {
min-height: 100vh;
display: flex;
}
#sidebar {
min-width: 250px;
max-width: 250px;
background-color: #343a40;
color: #fff;
}
#sidebar a {
color: #fff;
text-decoration: none;
}
#sidebar a:hover {
background-color: #495057;
}
#content {
flex-grow: 1;
padding: 20px;
}
</style>
</head>
<body>
<div id="sidebar" class="d-flex flex-column p-3">
<h3 class="text-center">Diplomacy</h3>
<hr class="text-white">
<ul class="nav nav-pills flex-column mb-auto">
<li class="nav-item"><a href="/dashboard" class="nav-link active">Dashboard</a></li>
<li class="nav-item"><a href="/create_game" class="nav-link">Crea partita</a></li>
<li class="nav-item"><a href="/auth/logout" class="nav-link">Logout</a></li>
</ul>
</div>
<div id="content">
<h1>Benvenuto, <?= htmlspecialchars($user['email']) ?>!</h1>
<p>Qui puoi vedere le tue partite e creare nuove partite con i tuoi amici.</p>
<h4 class="mt-4">Le tue partite</h4>
<?php if (count($games) === 0): ?>
<div class="alert alert-info">Non stai giocando a nessuna partita. <a href="/create_game">Crea una nuova partita</a></div>
<?php else: ?>
<div class="row row-cols-1 row-cols-md-2 g-4 mt-2">
<?php foreach ($games as $game): ?>
<div class="col">
<div class="card shadow-sm">
<div class="card-body">
<h5 class="card-title"><?= htmlspecialchars($game['name']) ?></h5>
<span class="badge bg-secondary"><?= htmlspecialchars($game['status']) ?></span>
<p class="card-text"><small>Creata il <?= htmlspecialchars($game['created_at']) ?></small></p>
<a href="/game/<?= $game['id'] ?>" class="btn btn-primary btn-sm">Apri partita</a>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<script src="assets/js/bootstrap.bundle.min.js"></script>
</body>
</html>

0
game/invite.php Executable file
View File

38
header.php Executable file
View File

@@ -0,0 +1,38 @@
<?php
require_once __DIR__ . '/init.php';
$user = current_user();
?>
<!doctype html>
<html lang="it">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Diplomacy — <?= htmlspecialchars($page_title ?? '') ?></title>
<!-- Bootstrap 5 CSS via CDN -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="/assets/style.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light mb-4">
<div class="container">
<a class="navbar-brand" href="<?= BASE_URL ?>/">Diplomacy</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<?php if($user): ?>
<li class="nav-item"><a class="nav-link" href="<?= BASE_URL ?>/game/dashboard.php">Dashboard</a></li>
<li class="nav-item"><a class="nav-link" href="<?= BASE_URL ?>/auth/logout.php">Logout (<?= htmlspecialchars($user['email']) ?>)</a></li>
<?php else: ?>
<li class="nav-item"><a class="nav-link" href="<?= BASE_URL ?>/auth/login.php">Login</a></li>
<li class="nav-item"><a class="nav-link" href="<?= BASE_URL ?>/auth/register.php">Registrati</a></li>
<?php endif; ?>
</ul>
</div>
</div>
</nav>
<div class="container">

18
index.php Executable file
View File

@@ -0,0 +1,18 @@
<?php
$page_title = "Benvenuto";
include __DIR__ . '/header.php';
?>
<div class="text-center mt-5">
<h1>Benvenuto su Diplomacy Web App</h1>
<p class="lead">Gioca con i tuoi amici su invito! Registrati o effettua il login per iniziare.</p>
<?php if(!is_logged_in()): ?>
<a href="<?= BASE_URL ?>/auth/register.php" class="btn btn-primary btn-lg me-2">Registrati</a>
<a href="<?= BASE_URL ?>/auth/login.php" class="btn btn-secondary btn-lg">Login</a>
<?php else: ?>
<a href="<?= BASE_URL ?>/game/dashboard.php" class="btn btn-success btn-lg">Vai alla Dashboard</a>
<?php endif; ?>
</div>
<?php include __DIR__ . '/footer.php'; ?>

25
init.php Executable file
View File

@@ -0,0 +1,25 @@
<?php
require_once __DIR__ . '/config.php';
session_start();
function getPDO(){
static $pdo = null;
if ($pdo === null) {
$dsn = "mysql:host=".DB_HOST.";dbname=".DB_NAME.";charset=utf8mb4";
$pdo = new PDO($dsn, DB_USER, DB_PASS, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
}
return $pdo;
}
function is_logged_in(){
return !empty($_SESSION['user_id']);
}
function current_user(){
if (!is_logged_in()) return null;
return ['id'=>$_SESSION['user_id'], 'email'=>$_SESSION['user_email']];
}

32
send_email.php Executable file
View File

@@ -0,0 +1,32 @@
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/smtp_config.php';
function sendEmail($to, $subject, $body){
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = SMTP_HOST;
$mail->SMTPAuth = true;
$mail->Username = SMTP_USER;
$mail->Password = SMTP_PASS;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // TLS
$mail->Port = SMTP_PORT;
$mail->setFrom(SMTP_FROM, SMTP_FROM_NAME);
$mail->addAddress($to);
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->send();
return true;
} catch (Exception $e) {
error_log("Mailer Error: ".$mail->ErrorInfo);
return false;
}
}

8
testmail.php Executable file
View File

@@ -0,0 +1,8 @@
<?php
require_once __DIR__ . '/send_email.php';
if(sendEmail('ginctronic@gmail.com','Test PHPMailer','Se ricevi questa mail, Gmail funziona!')){
echo "Mail inviata correttamente!";
} else {
echo "Errore nell'invio della mail, controlla log.";
}