From 143a17a6e726068384ed6c0ac29f772cfacac0fe Mon Sep 17 00:00:00 2001 From: ginc Date: Sat, 22 Nov 2025 10:51:24 +0000 Subject: [PATCH] Initial DEV environment from production snapshot --- .gitignore | 4 ++ assets/style.css | 0 auth/login.php | 53 +++++++++++++++++++ auth/logout.php | 4 ++ auth/register.php | 79 ++++++++++++++++++++++++++++ composer.json | 5 ++ composer.lock | 101 ++++++++++++++++++++++++++++++++++++ diplomacy | 1 + footer.php | 7 +++ game/create_game.php | 0 game/create_game_action.php | 0 game/dashboard.php | 99 +++++++++++++++++++++++++++++++++++ game/invite.php | 0 header.php | 38 ++++++++++++++ index.php | 18 +++++++ init.php | 25 +++++++++ send_email.php | 32 ++++++++++++ testmail.php | 8 +++ 18 files changed, 474 insertions(+) create mode 100644 .gitignore create mode 100755 assets/style.css create mode 100755 auth/login.php create mode 100755 auth/logout.php create mode 100755 auth/register.php create mode 100755 composer.json create mode 100755 composer.lock create mode 160000 diplomacy create mode 100755 footer.php create mode 100755 game/create_game.php create mode 100755 game/create_game_action.php create mode 100755 game/dashboard.php create mode 100755 game/invite.php create mode 100755 header.php create mode 100755 index.php create mode 100755 init.php create mode 100755 send_email.php create mode 100755 testmail.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aaac0ef --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/vendor/ +/assets/*.log +/config.php +/smtp_config.php diff --git a/assets/style.css b/assets/style.css new file mode 100755 index 0000000..e69de29 diff --git a/auth/login.php b/auth/login.php new file mode 100755 index 0000000..d3c2310 --- /dev/null +++ b/auth/login.php @@ -0,0 +1,53 @@ +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'; +?> + +
+
+

Login

+ +
+ + +
+
+ + +
+
+ + +
+ + Registrati +
+
+
+ + diff --git a/auth/logout.php b/auth/logout.php new file mode 100755 index 0000000..4a64a9e --- /dev/null +++ b/auth/logout.php @@ -0,0 +1,4 @@ +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 = "

Ciao ".htmlspecialchars($email).",

+

Grazie per esserti registrato su Diplomacy Web App. Ora puoi iniziare a giocare con i tuoi amici!

+

— Il team di Diplomacy

"; + 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'; +?> + +
+
+

Registrazione

+ + +
+
    ".htmlspecialchars($e).""; ?>
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+ + diff --git a/composer.json b/composer.json new file mode 100755 index 0000000..078861f --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "phpmailer/phpmailer": "^7.0" + } +} diff --git a/composer.lock b/composer.lock new file mode 100755 index 0000000..e37ef3a --- /dev/null +++ b/composer.lock @@ -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" +} diff --git a/diplomacy b/diplomacy new file mode 160000 index 0000000..b28edd3 --- /dev/null +++ b/diplomacy @@ -0,0 +1 @@ +Subproject commit b28edd336a57183abe082d954ce4c3629a07656d diff --git a/footer.php b/footer.php new file mode 100755 index 0000000..4a6d565 --- /dev/null +++ b/footer.php @@ -0,0 +1,7 @@ + + + + + + + diff --git a/game/create_game.php b/game/create_game.php new file mode 100755 index 0000000..e69de29 diff --git a/game/create_game_action.php b/game/create_game_action.php new file mode 100755 index 0000000..e69de29 diff --git a/game/dashboard.php b/game/dashboard.php new file mode 100755 index 0000000..64bdd83 --- /dev/null +++ b/game/dashboard.php @@ -0,0 +1,99 @@ +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); +?> + + + + + + + Dashboard - Diplomacy + + + + + + + +
+

Benvenuto, !

+

Qui puoi vedere le tue partite e creare nuove partite con i tuoi amici.

+ +

Le tue partite

+ +
Non stai giocando a nessuna partita. Crea una nuova partita
+ +
+ +
+
+
+
+ +

Creata il

+ Apri partita +
+
+
+ +
+ +
+ + + + diff --git a/game/invite.php b/game/invite.php new file mode 100755 index 0000000..e69de29 diff --git a/header.php b/header.php new file mode 100755 index 0000000..779bc3e --- /dev/null +++ b/header.php @@ -0,0 +1,38 @@ + + + + + + + Diplomacy — <?= htmlspecialchars($page_title ?? '') ?> + + + + + + + + + +
diff --git a/index.php b/index.php new file mode 100755 index 0000000..3781c32 --- /dev/null +++ b/index.php @@ -0,0 +1,18 @@ + + +
+

Benvenuto su Diplomacy Web App

+

Gioca con i tuoi amici su invito! Registrati o effettua il login per iniziare.

+ + + Registrati + Login + + Vai alla Dashboard + +
+ + diff --git a/init.php b/init.php new file mode 100755 index 0000000..12ca979 --- /dev/null +++ b/init.php @@ -0,0 +1,25 @@ + 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']]; +} + diff --git a/send_email.php b/send_email.php new file mode 100755 index 0000000..a079ece --- /dev/null +++ b/send_email.php @@ -0,0 +1,32 @@ +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; + } +} diff --git a/testmail.php b/testmail.php new file mode 100755 index 0000000..b4b5964 --- /dev/null +++ b/testmail.php @@ -0,0 +1,8 @@ +