Commit 51681b03 authored by Mindiell's avatar Mindiell

Modification de l'architecture pour obtenir un vrai modèle MVC

parent 2e2f305e
......@@ -57,7 +57,7 @@ test-functional: ## Launch functional tests.
@./vendor/bin/codecept run functional
server-start: server-stop ## Launch a local server
@php -S 127.0.0.1:8000 -t ./www/ >> ./var/log/server.log &
@php -S 127.0.0.1:8000 -t ./www/ >> ./log/server.log &
@echo "\033[32mServer running. (http://127.0.0.1:8000)\033[0m"
server-stop: ## Stop local server if running
......
......@@ -3,13 +3,13 @@
AUTOLOAD=../app/
; Répertoire contenant les templates
UI=../templates/
UI=../app/view/
; Répertoire des fichiers temporaires
TEMP=../tmp/
; Répertoire des logs
LOGS=../tmp
LOGS=../log/
; Gestionnaire d'erreur personnalisé
; ONERROR="Main->error"
......
This diff is collapsed.
<?php
namespace Controller;
class Bank extends Controller
{
......@@ -14,7 +15,7 @@ class Bank extends Controller
{
@include_once("config.php");
$cb_log = new Log('/cb.log');
$cb_log = new \Log('/cb.log');
$error="";
$result = $f3->get('POST.vads_result');
$status = $f3->get('POST.vads_trans_status');
......@@ -106,7 +107,7 @@ class Bank extends Controller
$id = intval($order_id);
$cb_log->write("Id: ".$order_id);
$res = $db->query("SELECT * FROM dons WHERE id='".$id."';");
$don = $res->fetch(PDO::FETCH_ASSOC);
$don = $res->fetch(\PDO::FETCH_ASSOC);
if (!$don) {
$cb_log->write("Transaction id not found: ".$order_id);
......@@ -144,11 +145,11 @@ class Bank extends Controller
// ok, somme OK, status = completed, transaction found.
$db->query("UPDATE dons SET status=status+1 WHERE id='".$id."';");
$res = $db->query("SELECT status FROM dons WHERE id='".$id."';");
$status = $res->fetch(PDO::FETCH_ASSOC);
$status = $res->fetch(\PDO::FETCH_ASSOC);
$status = $status['status'];
$res = $db->query("SELECT * FROM users WHERE id='".$don['user_id']."';");
$user = $res->fetch(PDO::FETCH_ASSOC);
$user = $res->fetch(\PDO::FETCH_ASSOC);
$cb_log->write("Utilisation d'un utilisateur existant");
// Ajout du nouveau don au cumul actuel
if ($status!=101) {
......@@ -156,7 +157,7 @@ class Bank extends Controller
$db->query("UPDATE users set cumul = cumul + " . $don['somme'] . ", total = total + " . $don['somme'] . " WHERE id='".$don['user_id']."'");
}
$result = $db->query("SELECT cumul FROM users WHERE id='".$don['user_id']."'");
$cumul = $result->fetch(PDO::FETCH_ASSOC);
$cumul = $result->fetch(\PDO::FETCH_ASSOC);
$cumul = $cumul['cumul'];
$cb_log->write("Nouveau cumul: ".$cumul);
$user_id = $user['id'];
......
<?php
namespace Controller;
class Campaign extends Controller
{
......@@ -20,7 +21,7 @@ class Campaign extends Controller
{
parent::afterRoute($f3, $args);
// Rendu HTML de la page
echo Template::instance()->render('campaign/base.html');
echo \Template::instance()->render('campaign/base.html');
}
public static function show($f3, $args)
......@@ -29,8 +30,8 @@ class Campaign extends Controller
// So, get the $db
$db = $f3->get('DB');
// Number of month left for a one-year provisionning since CAMPAIGN_START_DATE
$now = new DateTime('now');
$start = new DateTime(CAMPAIGN_START_DATE);
$now = new \DateTime('now');
$start = new \DateTime(CAMPAIGN_START_DATE);
if ($start > $now) {
$months = 0;
} else {
......@@ -74,7 +75,7 @@ class Campaign extends Controller
// Page d'attente
public function wait($f3)
{
echo Template::instance()->render('campaign/wait.html');
echo \Template::instance()->render('campaign/wait.html');
exit;
}
......@@ -140,29 +141,29 @@ class Campaign extends Controller
// Si l'utilisateur est déjà connecté, on le récupère
if ($f3->get('SESSION.user', true)) {
$user = $db->query("SELECT * FROM users WHERE id = ".$f3->get('SESSION.id'));
$user = $user->fetch(PDO::FETCH_ASSOC);
$user = $user->fetch(\PDO::FETCH_ASSOC);
$email = $user['email'];
$user_id = $user['id'];
$cumul_id = $user['cumul'];
} else {
// Depuis les dons cumulés, on recherche d'abord si le donateur existe déjà (basé sur son email)
$email = Utils::asl($f3->get('email'));
$email = \Utils::asl($f3->get('email'));
$hash = hash('sha256', $f3->get('password'));
$sql = "SELECT id FROM users WHERE email = '".Utils::asl($email)."';";
$sql = "SELECT id FROM users WHERE email = '".\Utils::asl($email)."';";
$result = $db->query($sql);
if ($result->fetchColumn() > 0) {
// We have an existing user, we should try to login with the provided password
// or 403.
$mapper = new DB\SQL\Mapper($f3->get('DB'), 'users');
$mapper = new \DB\SQL\Mapper($f3->get('DB'), 'users');
$auth = new \Auth($mapper, array('id' => 'email', 'pw' => 'hash'));
$login = $auth->login($email, $hash);
if (!$login) {
$f3->error(403);
} else {
$result = $db->query("SELECT id, cumul FROM users WHERE email = '".Utils::asl($email)."'");
$user = $result->fetch(PDO::FETCH_ASSOC);
$result = $db->query("SELECT id, cumul FROM users WHERE email = '".\Utils::asl($email)."'");
$user = $result->fetch(\PDO::FETCH_ASSOC);
$user_id = $user['id'];
$cumul_id = $user['cumul'];
}
......@@ -191,7 +192,7 @@ class Campaign extends Controller
setcookie("donlqdn", md5("SALT!!!".$id."!!!"), 86400, "/");
$target = PAYMENT_URL; //"https://paiement.systempay.fr/vads-payment/";
$transaction_date = new DateTime('now', new DateTimeZone("UTC"));
$transaction_date = new \DateTime('now', new \DateTimeZone("UTC"));
$params = array(
// Champs obligatoires
"vads_trans_date" => $transaction_date->format("YmdHis"),
......@@ -250,7 +251,7 @@ class Campaign extends Controller
$f3->set('signature', $signature);
// Log des informations envoyées pour debug en cas de souci
$don_log = new Log('dons.log');
$don_log = new \Log('dons.log');
$don_log->write('target : '. $target);
$don_log->write('params : ');
foreach ($params as $key=>$value) {
......
<?php
namespace Controller;
class Controller
{
// Constructeur
public function __construct()
{
$f3=Base::instance();
$f3=\Base::instance();
}
// Fonction appelée avant routage
......@@ -62,7 +63,7 @@ class Controller
}
// Log dir
$f3->set('LOGS', LOGS);
//$f3->set('LOGS', LOGS);
$f3->set('mail', array(
"from" => "contact@laquadrature.net",
......
......@@ -5,6 +5,7 @@
* The command should be called like this :
* php index.php "/action"
*/
namespace Controller;
class Cron extends Controller
{
......@@ -21,20 +22,20 @@ class Cron extends Controller
{
// This method is used to generate a piplome. It might be called with an
// id parameters, in which case we will ask to regenerate a specific piplome.
$logger = new Log("/piplome.log");
$logger = new \Log("/piplome.log");
$ids = array();
$db = $f3->get('DB');
if (array_key_exists('id', $args)) {
// Let's check if we can have a pdf
$result = $db->query("SELECT dons.id as id, decimale, users.pseudo as nom, lang FROM dons LEFT JOIN users ON dons.user_id = users.id WHERE dons.status IN (1, 4, 101) AND dons.id='".Utils::asl($args['id'])."'");
$result = $db->query("SELECT dons.id as id, decimale, users.pseudo as nom, lang FROM dons LEFT JOIN users ON dons.user_id = users.id WHERE dons.status IN (1, 4, 101) AND dons.id='".\Utils::asl($args['id'])."'");
} else {
// We want to generate all piplomes which does not exists yet
$result = $db->query("SELECT dons.id as id, decimale, users.pseudo as nom, lang FROM dons LEFT JOIN users ON dons.user_id = users.id WHERE pdf='' AND dons.status IN (1, 4, 101) LIMIT 100;");
}
$pdfs = [];
foreach ($result->fetchAll(PDO::FETCH_ASSOC) as $row) {
foreach ($result->fetchAll(\PDO::FETCH_ASSOC) as $row) {
$pdfs[] = $row;
}
......@@ -50,8 +51,8 @@ class Cron extends Controller
do {
$decimale = rand(10, 200000);
$logger->write("Trying if $decimale is free");
$result = $db->query("SELECT id FROM dons WHERE decimale='".Utils::asl($decimale)."';");
$tmp = $result->fetchAll(PDO::FETCH_COLUMN, 'id');
$result = $db->query("SELECT id FROM dons WHERE decimale='".\Utils::asl($decimale)."';");
$tmp = $result->fetchAll(\PDO::FETCH_COLUMN, 'id');
} while ($tmp);
$logger->write("Found a decimal of pi: ".$decimale."");
$pdf['decimale'] = $decimale;
......@@ -93,7 +94,7 @@ class Cron extends Controller
}
fclose($pi);
$pdf['nom'] = Utils::clean_encoding(Utils::sanitize_piplomes($pdf['nom']));
$pdf['nom'] = \Utils::clean_encoding(\Utils::sanitize_piplomes($pdf['nom']));
$logger->write("PDF File will be ". $pdf['hash']);
$logger->write("decimales: ".$decimales);
......@@ -170,8 +171,8 @@ class Cron extends Controller
FROM dons
LEFT JOIN users ON dons.user_id = users.id
WHERE dons.status IN (1, 4, 101)
AND dons.id='".Utils::asl($args['id'])."'");
$pdf = $result->fetch(PDO::FETCH_ASSOC);
AND dons.id='".\Utils::asl($args['id'])."'");
$pdf = $result->fetch(\PDO::FETCH_ASSOC);
$fp = fopen(PIPLOME_PATH . $pdf['hash'] .".pdf", "rb");
if ($fp) {
$fsize = filesize(PIPLOME_PATH . $pdf['hash'] .".pdf");
......
This diff is collapsed.
[routes]
; Site principal
GET|POST @home:/=Campaign->show
GET @what:/what=Campaign->what
GET @who:/who=Campaign->who
GET @why:/why=Campaign->why
GET @faq:/faq=Campaign->faq
GET @merci:/merci=Campaign->merci
GET @material:/material=Campaign->material
POST @donate:/donate=Campaign->donate
GET|POST @home:/=Controller\Campaign->show
GET @what:/what=Controller\Campaign->what
GET @who:/who=Controller\Campaign->who
GET @why:/why=Controller\Campaign->why
GET @faq:/faq=Controller\Campaign->faq
GET @merci:/merci=Controller\Campaign->merci
GET @material:/material=Controller\Campaign->material
POST @donate:/donate=Controller\Campaign->donate
; Page de retour de la banque
POST @cb:/cb=Bank->cb
POST @cb:/cb=Controller\Bank->cb
; Pages d'administration personnelle
GET|POST @perso:/perso=Perso->show
POST|GET @login:/login=Perso->login
GET|POST @logout:/perso/logout=Perso->logout
GET|POST @cancel:/cancel/@id=Perso->cancel
POST @infos:/infos=Perso->infos
POST @add_contrepartie:/add/contrepartie=Perso->add_contrepartie
POST @adresses:/perso/adresses=Perso->adresses
GET @recu:/receipt/@id=Perso->receipt
GET|POST @perso:/perso=Controller\Perso->show
POST|GET @login:/login=Controller\Perso->login
GET|POST @logout:/perso/logout=Controller\Perso->logout
GET|POST @cancel:/cancel/@id=Controller\Perso->cancel
POST @infos:/infos=Controller\Perso->infos
POST @add_contrepartie:/add/contrepartie=Controller\Perso->add_contrepartie
POST @adresses:/perso/adresses=Controller\Perso->adresses
GET @recu:/receipt/@id=Controller\Perso->receipt
; Cron jobs
GET /cron/@action=Cron->@action
GET /cron/piplome/@id=Cron->piplome
GET /cron/@action=Controller\Cron->@action
GET /cron/piplome/@id=Controller\Cron->piplome
; Pages d'administration
GET|POST @admin:/admin=Admin->show
GET @add_support:/admin/support/add=Admin->support
GET @edit_support:/admin/support/edit/@id=Admin->support
POST @modify_support:/admin/support/edit=Admin->support
GET|POST @admin:/admin=Controller\Admin->show
GET @add_support:/admin/support/add=Controller\Admin->support
GET @edit_support:/admin/support/edit/@id=Controller\Admin->support
POST @modify_support:/admin/support/edit=Controller\Admin->support
GET|POST @admin_accounts:/admin/accounts=Admin->accounts
GET|POST @admin_accounts:/admin/accounts=Controller\Admin->accounts
GET|POST @counterparts:/admin/counterparts=Admin->counterparts
POST @export:/counterparts/admin/export=Admin->counterparts
GET|POST @edit_counterpart:/admin/counterparts/edit/@id=Admin->counterpart
GET|POST @counterparts:/admin/counterparts=Controller\Admin->counterparts
POST @export:/counterparts/admin/export=Controller\Admin->counterparts
GET|POST @edit_counterpart:/admin/counterparts/edit/@id=Controller\Admin->counterpart
GET|POST @cbs:/admin/cbs=Admin->cbs
POST @export_cbs:/admin/cbs/export=Admin->cbs
GET|POST @cbs:/admin/cbs=Controller\Admin->cbs
POST @export_cbs:/admin/cbs/export=Controller\Admin->cbs
GET|POST @users:/admin/users=Admin->users
POST @add_user:/admin/users/add=Admin->user
GET @user_info:/admin/users/@id=Admin->user
POST @modify_user:/admin/users/@id=Admin->user
GET|POST @users:/admin/users=Controller\Admin->users
POST @add_user:/admin/users/add=Controller\Admin->user
GET @user_info:/admin/users/@id=Controller\Admin->user
POST @modify_user:/admin/users/@id=Controller\Admin->user
POST @adresse:/admin/adresses=Admin->adresse
POST @adresse:/admin/adresses=Controller\Admin->adresse
GET @counterparts_dashboard:/admin/counterparts_dashboard=Admin->counterparts_dashboard
GET @counterparts_dashboard:/admin/counterparts_dashboard=Controller\Admin->counterparts_dashboard
GET|POST @banque:/admin/banque=Admin->banque
GET|POST @banque:/admin/banque=Controller\Admin->banque
GET @stats:/admin/stats=Admin->stats
GET @stats:/admin/stats=Controller\Admin->stats
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment