Commit 51681b03 authored by Mindiell's avatar Mindiell
Browse files

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

parent 2e2f305e
...@@ -57,7 +57,7 @@ test-functional: ## Launch functional tests. ...@@ -57,7 +57,7 @@ test-functional: ## Launch functional tests.
@./vendor/bin/codecept run functional @./vendor/bin/codecept run functional
server-start: server-stop ## Launch a local server 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" @echo "\033[32mServer running. (http://127.0.0.1:8000)\033[0m"
server-stop: ## Stop local server if running server-stop: ## Stop local server if running
......
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
AUTOLOAD=../app/ AUTOLOAD=../app/
; Répertoire contenant les templates ; Répertoire contenant les templates
UI=../templates/ UI=../app/view/
; Répertoire des fichiers temporaires ; Répertoire des fichiers temporaires
TEMP=../tmp/ TEMP=../tmp/
; Répertoire des logs ; Répertoire des logs
LOGS=../tmp LOGS=../log/
; Gestionnaire d'erreur personnalisé ; Gestionnaire d'erreur personnalisé
; ONERROR="Main->error" ; ONERROR="Main->error"
......
This diff is collapsed.
<?php <?php
namespace Controller;
class Bank extends Controller class Bank extends Controller
{ {
...@@ -14,7 +15,7 @@ class Bank extends Controller ...@@ -14,7 +15,7 @@ class Bank extends Controller
{ {
@include_once("config.php"); @include_once("config.php");
$cb_log = new Log('/cb.log'); $cb_log = new \Log('/cb.log');
$error=""; $error="";
$result = $f3->get('POST.vads_result'); $result = $f3->get('POST.vads_result');
$status = $f3->get('POST.vads_trans_status'); $status = $f3->get('POST.vads_trans_status');
...@@ -106,7 +107,7 @@ class Bank extends Controller ...@@ -106,7 +107,7 @@ class Bank extends Controller
$id = intval($order_id); $id = intval($order_id);
$cb_log->write("Id: ".$order_id); $cb_log->write("Id: ".$order_id);
$res = $db->query("SELECT * FROM dons WHERE id='".$id."';"); $res = $db->query("SELECT * FROM dons WHERE id='".$id."';");
$don = $res->fetch(PDO::FETCH_ASSOC); $don = $res->fetch(\PDO::FETCH_ASSOC);
if (!$don) { if (!$don) {
$cb_log->write("Transaction id not found: ".$order_id); $cb_log->write("Transaction id not found: ".$order_id);
...@@ -144,11 +145,11 @@ class Bank extends Controller ...@@ -144,11 +145,11 @@ class Bank extends Controller
// ok, somme OK, status = completed, transaction found. // ok, somme OK, status = completed, transaction found.
$db->query("UPDATE dons SET status=status+1 WHERE id='".$id."';"); $db->query("UPDATE dons SET status=status+1 WHERE id='".$id."';");
$res = $db->query("SELECT status FROM dons 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']; $status = $status['status'];
$res = $db->query("SELECT * FROM users WHERE id='".$don['user_id']."';"); $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"); $cb_log->write("Utilisation d'un utilisateur existant");
// Ajout du nouveau don au cumul actuel // Ajout du nouveau don au cumul actuel
if ($status!=101) { if ($status!=101) {
...@@ -156,7 +157,7 @@ class Bank extends Controller ...@@ -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']."'"); $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']."'"); $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']; $cumul = $cumul['cumul'];
$cb_log->write("Nouveau cumul: ".$cumul); $cb_log->write("Nouveau cumul: ".$cumul);
$user_id = $user['id']; $user_id = $user['id'];
......
<?php <?php
namespace Controller;
class Campaign extends Controller class Campaign extends Controller
{ {
...@@ -20,7 +21,7 @@ class Campaign extends Controller ...@@ -20,7 +21,7 @@ class Campaign extends Controller
{ {
parent::afterRoute($f3, $args); parent::afterRoute($f3, $args);
// Rendu HTML de la page // 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) public static function show($f3, $args)
...@@ -29,8 +30,8 @@ class Campaign extends Controller ...@@ -29,8 +30,8 @@ class Campaign extends Controller
// So, get the $db // So, get the $db
$db = $f3->get('DB'); $db = $f3->get('DB');
// Number of month left for a one-year provisionning since CAMPAIGN_START_DATE // Number of month left for a one-year provisionning since CAMPAIGN_START_DATE
$now = new DateTime('now'); $now = new \DateTime('now');
$start = new DateTime(CAMPAIGN_START_DATE); $start = new \DateTime(CAMPAIGN_START_DATE);
if ($start > $now) { if ($start > $now) {
$months = 0; $months = 0;
} else { } else {
...@@ -74,7 +75,7 @@ class Campaign extends Controller ...@@ -74,7 +75,7 @@ class Campaign extends Controller
// Page d'attente // Page d'attente
public function wait($f3) public function wait($f3)
{ {
echo Template::instance()->render('campaign/wait.html'); echo \Template::instance()->render('campaign/wait.html');
exit; exit;
} }
...@@ -140,29 +141,29 @@ class Campaign extends Controller ...@@ -140,29 +141,29 @@ class Campaign extends Controller
// Si l'utilisateur est déjà connecté, on le récupère // Si l'utilisateur est déjà connecté, on le récupère
if ($f3->get('SESSION.user', true)) { if ($f3->get('SESSION.user', true)) {
$user = $db->query("SELECT * FROM users WHERE id = ".$f3->get('SESSION.id')); $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']; $email = $user['email'];
$user_id = $user['id']; $user_id = $user['id'];
$cumul_id = $user['cumul']; $cumul_id = $user['cumul'];
} else { } else {
// Depuis les dons cumulés, on recherche d'abord si le donateur existe déjà (basé sur son email) // 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')); $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); $result = $db->query($sql);
if ($result->fetchColumn() > 0) { if ($result->fetchColumn() > 0) {
// We have an existing user, we should try to login with the provided password // We have an existing user, we should try to login with the provided password
// or 403. // 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')); $auth = new \Auth($mapper, array('id' => 'email', 'pw' => 'hash'));
$login = $auth->login($email, $hash); $login = $auth->login($email, $hash);
if (!$login) { if (!$login) {
$f3->error(403); $f3->error(403);
} else { } else {
$result = $db->query("SELECT id, cumul FROM users WHERE email = '".Utils::asl($email)."'"); $result = $db->query("SELECT id, cumul FROM users WHERE email = '".\Utils::asl($email)."'");
$user = $result->fetch(PDO::FETCH_ASSOC); $user = $result->fetch(\PDO::FETCH_ASSOC);
$user_id = $user['id']; $user_id = $user['id'];
$cumul_id = $user['cumul']; $cumul_id = $user['cumul'];
} }
...@@ -191,7 +192,7 @@ class Campaign extends Controller ...@@ -191,7 +192,7 @@ class Campaign extends Controller
setcookie("donlqdn", md5("SALT!!!".$id."!!!"), 86400, "/"); setcookie("donlqdn", md5("SALT!!!".$id."!!!"), 86400, "/");
$target = PAYMENT_URL; //"https://paiement.systempay.fr/vads-payment/"; $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( $params = array(
// Champs obligatoires // Champs obligatoires
"vads_trans_date" => $transaction_date->format("YmdHis"), "vads_trans_date" => $transaction_date->format("YmdHis"),
...@@ -250,7 +251,7 @@ class Campaign extends Controller ...@@ -250,7 +251,7 @@ class Campaign extends Controller
$f3->set('signature', $signature); $f3->set('signature', $signature);
// Log des informations envoyées pour debug en cas de souci // 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('target : '. $target);
$don_log->write('params : '); $don_log->write('params : ');
foreach ($params as $key=>$value) { foreach ($params as $key=>$value) {
......
<?php <?php
namespace Controller;
class Controller class Controller
{ {
// Constructeur // Constructeur
public function __construct() public function __construct()
{ {
$f3=Base::instance(); $f3=\Base::instance();
} }
// Fonction appelée avant routage // Fonction appelée avant routage
...@@ -62,7 +63,7 @@ class Controller ...@@ -62,7 +63,7 @@ class Controller
} }
// Log dir // Log dir
$f3->set('LOGS', LOGS); //$f3->set('LOGS', LOGS);
$f3->set('mail', array( $f3->set('mail', array(
"from" => "contact@laquadrature.net", "from" => "contact@laquadrature.net",
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* The command should be called like this : * The command should be called like this :
* php index.php "/action" * php index.php "/action"
*/ */
namespace Controller;
class Cron extends Controller class Cron extends Controller
{ {
...@@ -21,20 +22,20 @@ 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 // 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. // 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(); $ids = array();
$db = $f3->get('DB'); $db = $f3->get('DB');
if (array_key_exists('id', $args)) { if (array_key_exists('id', $args)) {
// Let's check if we can have a pdf // 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 { } else {
// We want to generate all piplomes which does not exists yet // 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;"); $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 = []; $pdfs = [];
foreach ($result->fetchAll(PDO::FETCH_ASSOC) as $row) { foreach ($result->fetchAll(\PDO::FETCH_ASSOC) as $row) {
$pdfs[] = $row; $pdfs[] = $row;
} }
...@@ -50,8 +51,8 @@ class Cron extends Controller ...@@ -50,8 +51,8 @@ class Cron extends Controller
do { do {
$decimale = rand(10, 200000); $decimale = rand(10, 200000);
$logger->write("Trying if $decimale is free"); $logger->write("Trying if $decimale is free");
$result = $db->query("SELECT id FROM dons WHERE decimale='".Utils::asl($decimale)."';"); $result = $db->query("SELECT id FROM dons WHERE decimale='".\Utils::asl($decimale)."';");
$tmp = $result->fetchAll(PDO::FETCH_COLUMN, 'id'); $tmp = $result->fetchAll(\PDO::FETCH_COLUMN, 'id');
} while ($tmp); } while ($tmp);
$logger->write("Found a decimal of pi: ".$decimale.""); $logger->write("Found a decimal of pi: ".$decimale."");
$pdf['decimale'] = $decimale; $pdf['decimale'] = $decimale;
...@@ -93,7 +94,7 @@ class Cron extends Controller ...@@ -93,7 +94,7 @@ class Cron extends Controller
} }
fclose($pi); 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("PDF File will be ". $pdf['hash']);
$logger->write("decimales: ".$decimales); $logger->write("decimales: ".$decimales);
...@@ -170,8 +171,8 @@ class Cron extends Controller ...@@ -170,8 +171,8 @@ class Cron extends Controller
FROM dons FROM dons
LEFT JOIN users ON dons.user_id = users.id LEFT JOIN users ON dons.user_id = users.id
WHERE dons.status IN (1, 4, 101) WHERE dons.status IN (1, 4, 101)
AND dons.id='".Utils::asl($args['id'])."'"); AND dons.id='".\Utils::asl($args['id'])."'");
$pdf = $result->fetch(PDO::FETCH_ASSOC); $pdf = $result->fetch(\PDO::FETCH_ASSOC);
$fp = fopen(PIPLOME_PATH . $pdf['hash'] .".pdf", "rb"); $fp = fopen(PIPLOME_PATH . $pdf['hash'] .".pdf", "rb");
if ($fp) { if ($fp) {
$fsize = filesize(PIPLOME_PATH . $pdf['hash'] .".pdf"); $fsize = filesize(PIPLOME_PATH . $pdf['hash'] .".pdf");
......
<?php <?php
namespace Controller;
use LQDN\Command\AddressCreateCommand; use LQDN\Command\AddressCreateCommand;
use LQDN\Command\AddressDeleteCommand; use LQDN\Command\AddressDeleteCommand;
...@@ -19,7 +20,7 @@ class Perso extends Controller ...@@ -19,7 +20,7 @@ class Perso extends Controller
{ {
// Rendu HTML de la page // Rendu HTML de la page
parent::afterRoute($f3, $args); parent::afterRoute($f3, $args);
echo Template::instance()->render('campaign/base.html'); echo \Template::instance()->render('campaign/base.html');
} }
public function show($f3, $args) public function show($f3, $args)
...@@ -41,7 +42,7 @@ class Perso extends Controller ...@@ -41,7 +42,7 @@ class Perso extends Controller
// Let's update the total first // Let's update the total first
$total = 0; $total = 0;
$total_res = $db->query("SELECT SUM(somme) as total FROM dons WHERE status in (1, 4, 101, 102) AND user_id='".$f3->get('SESSION.id')."'"); $total_res = $db->query("SELECT SUM(somme) as total FROM dons WHERE status in (1, 4, 101, 102) AND user_id='".$f3->get('SESSION.id')."'");
$total_res = $total_res->fetch(PDO::FETCH_ASSOC); $total_res = $total_res->fetch(\PDO::FETCH_ASSOC);
$total = $total_res['total']; $total = $total_res['total'];
// While we're at it, let's remove the price of each asked contreparties // While we're at it, let's remove the price of each asked contreparties
// printed piplome is 30, pibag is 50, pishirt is 100 and hoodie is 250 // printed piplome is 30, pibag is 50, pishirt is 100 and hoodie is 250
...@@ -53,7 +54,7 @@ class Perso extends Controller ...@@ -53,7 +54,7 @@ class Perso extends Controller
count(if(quoi='hoodie', 1, 0)) as hoodies count(if(quoi='hoodie', 1, 0)) as hoodies
FROM contreparties FROM contreparties
WHERE user_id = '".$f3->get('SESSION.id')."';"); WHERE user_id = '".$f3->get('SESSION.id')."';");
$cumul_counterpart = $cumul_counterpart->fetch(PDO::FETCH_ASSOC); $cumul_counterpart = $cumul_counterpart->fetch(\PDO::FETCH_ASSOC);
foreach (['hoodies', 'pishirts', 'pibags', 'piplomes'] as $key) { foreach (['hoodies', 'pishirts', 'pibags', 'piplomes'] as $key) {
if (!array_key_exists($key, $cumul_counterpart)) { if (!array_key_exists($key, $cumul_counterpart)) {
$cumul_counterpart[$key] = 0; $cumul_counterpart[$key] = 0;
...@@ -65,11 +66,11 @@ class Perso extends Controller ...@@ -65,11 +66,11 @@ class Perso extends Controller
$db->query("UPDATE users SET total = '".$total."', cumul = '".$cumul."' WHERE id = '".$f3->get('SESSION.id')."'"); $db->query("UPDATE users SET total = '".$total."', cumul = '".$cumul."' WHERE id = '".$f3->get('SESSION.id')."'");
$result = $db->query("SELECT id, pseudo, email, total, cumul FROM users WHERE id='".$f3->get('SESSION.id')."' "); $result = $db->query("SELECT id, pseudo, email, total, cumul FROM users WHERE id='".$f3->get('SESSION.id')."' ");
$data = $result->fetch(PDO::FETCH_ASSOC); $data = $result->fetch(\PDO::FETCH_ASSOC);
$f3->set('infos', $data); $f3->set('infos', $data);
$result = $db->query("SELECT id, pdf, decimale FROM dons WHERE user_id='".$data['id']."' and pdf!='' "); $result = $db->query("SELECT id, pdf, decimale FROM dons WHERE user_id='".$data['id']."' and pdf!='' ");
$pdfs = array(); $pdfs = array();
foreach ($result->fetchAll(PDO::FETCH_ASSOC) as $row) { foreach ($result->fetchAll(\PDO::FETCH_ASSOC) as $row) {
$pdfs[$row['pdf']] = $row; $pdfs[$row['pdf']] = $row;
} }
$addresses = $f3->get('container')['address_finder']->findByUserId((int) $data['id']); $addresses = $f3->get('container')['address_finder']->findByUserId((int) $data['id']);
...@@ -83,7 +84,7 @@ class Perso extends Controller ...@@ -83,7 +84,7 @@ class Perso extends Controller
$db = $f3->get('DB'); $db = $f3->get('DB');
$result =$db->query("SELECT datec, status, quoi, taille, adresse_id FROM contreparties WHERE user_id='".$f3->get('SESSION.id')."' ORDER BY datec DESC"); $result =$db->query("SELECT datec, status, quoi, taille, adresse_id FROM contreparties WHERE user_id='".$f3->get('SESSION.id')."' ORDER BY datec DESC");
$data = array(); $data = array();
foreach ($result->fetchAll(PDO::FETCH_ASSOC) as $row) { foreach ($result->fetchAll(\PDO::FETCH_ASSOC) as $row) {
$data[] = $row; $data[] = $row;
} }
$f3->set('contreparties', $data); $f3->set('contreparties', $data);
...@@ -95,7 +96,7 @@ class Perso extends Controller ...@@ -95,7 +96,7 @@ class Perso extends Controller
$db = $f3->get('DB'); $db = $f3->get('DB');
$result = $db->query("SELECT datec, somme, id, pdf, status FROM dons WHERE user_id='".$f3->get('infos.id')."' AND status IN (1,4,102) ORDER BY datec ASC"); $result = $db->query("SELECT datec, somme, id, pdf, status FROM dons WHERE user_id='".$f3->get('infos.id')."' AND status IN (1,4,102) ORDER BY datec ASC");
$data = array(); $data = array();
foreach ($result->fetchAll(PDO::FETCH_ASSOC) as $row) { foreach ($result->fetchAll(\PDO::FETCH_ASSOC) as $row) {
$data[] = $row; $data[] = $row;
} }
$f3->set('dons', $data); $f3->set('dons', $data);
...@@ -107,7 +108,7 @@ class Perso extends Controller ...@@ -107,7 +108,7 @@ class Perso extends Controller
$db = $f3->get('DB'); $db = $f3->get('DB');
$result = $db->query("SELECT datec, somme, status, id, pdf, identifier FROM dons WHERE user_id='".$f3->get('infos.id')."' AND status IN (101) ORDER BY datec ASC"); $result = $db->query("SELECT datec, somme, status, id, pdf, identifier FROM dons WHERE user_id='".$f3->get('infos.id')."' AND status IN (101) ORDER BY datec ASC");
$data = array(); $data = array();
foreach ($result->fetchAll(PDO::FETCH_ASSOC) as $row) { foreach ($result->fetchAll(\PDO::FETCH_ASSOC) as $row) {
$data[] = $row; $data[] = $row;
} }
$f3->set('dons_recurrents', $data); $f3->set('dons_recurrents', $data);
...@@ -131,9 +132,9 @@ class Perso extends Controller ...@@ -131,9 +132,9 @@ class Perso extends Controller
// Tentative de connexion // Tentative de connexion
// We should use auth module from Fat Free // We should use auth module from Fat Free
$db = $f3->get('DB'); $db = $f3->get('DB');
$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')); $auth = new \Auth($mapper, array('id' => 'email', 'pw' => 'hash'));
$email = Utils::asl($f3->get('email')); $email = \Utils::asl($f3->get('email'));
$hash = hash('sha256', $f3->get('password')); $hash = hash('sha256', $f3->get('password'));
$login = $auth->login($email, $hash); $login = $auth->login($email, $hash);
...@@ -141,8 +142,8 @@ class Perso extends Controller ...@@ -141,8 +142,8 @@ class Perso extends Controller
if ($login) { if ($login) {
// We want to retrieve the associated user // We want to retrieve the associated user
$result = $db->query("SELECT id, email FROM users WHERE email='".$email."'"); $result = $db->query("SELECT id, email FROM users WHERE email='".$email."'");
$id = $result->fetch(PDO::FETCH_ASSOC)['id']; $id = $result->fetch(\PDO::FETCH_ASSOC)['id'];
$email = $result->fetch(PDO::FETCH_ASSOC)['email']; $email = $result->fetch(\PDO::FETCH_ASSOC)['email'];
$f3->set('SESSION.id', $id); $f3->set('SESSION.id', $id);
$f3->set('SESSION.email', $email); $f3->set('SESSION.email', $email);
$f3->set('SESSION.user', true); $f3->set('SESSION.user', true);
...@@ -172,15 +173,15 @@ class Perso extends Controller ...@@ -172,15 +173,15 @@ class Perso extends Controller
if ($f3->get('email')!='') { if ($f3->get('email')!='') {
// On vérifie que l'adresse mail existe // On vérifie que l'adresse mail existe
$db = $f3->get('DB'); $db = $f3->get('DB');
$result = $db->query("SELECT email FROM users WHERE email='".Utils::asl($f3->get('email'))."';"); $result = $db->query("SELECT email FROM users WHERE email='".\Utils::asl($f3->get('email'))."';");
$row = $result->fetch(PDO::FETCH_ASSOC); $row = $result->fetch(\PDO::FETCH_ASSOC);
if ($row['email']!='') { if ($row['email']!='') {
// On régénère un mot de passe // On régénère un mot de passe
$pass = Utils::generate_password(); $pass = \Utils::generate_password();
// On ne conserve que le mot de passe haché // On ne conserve que le mot de passe haché
$hash = hash('sha256', $pass); $hash = hash('sha256', $pass);
// On le sauve en base de données // On le sauve en base de données
$query = "UPDATE users SET hash='".$hash."' WHERE email='".Utils::asl($f3->get('email'))."';"; $query = "UPDATE users SET hash='".$hash."' WHERE email='".\Utils::asl($f3->get('email'))."';";
$db->query($query); $db->query($query);
// On le renvoie par email // On le renvoie par email
...@@ -222,7 +223,7 @@ class Perso extends Controller ...@@ -222,7 +223,7 @@ class Perso extends Controller
if ($mailer->send($text)) { if ($mailer->send($text)) {
$f3->set('SESSION.message', _("Nouveau mot de passe envoyé par mail.")); $f3->set('SESSION.message', _("Nouveau mot de passe envoyé par mail."));
} else { } else {
$logger = new Log('mail.log'); $logger = new \Log('mail.log');
$f3->set('SESSION.error', _('Oops')); $f3->set('SESSION.error', _('Oops'));
$logger->write($mailer->log()); $logger->write($mailer->log());
} }
...@@ -240,14 +241,14 @@ class Perso extends Controller ...@@ -240,14 +241,14 @@ class Perso extends Controller
// On vérifie que l'adresse mail n'existe pas // On vérifie que l'adresse mail n'existe pas
$db = $f3->get('DB'); $db = $f3->get('DB');
$query = $db->query("SELECT email FROM users WHERE email='".$f3->get('email')."';"); $query = $db->query("SELECT email FROM users WHERE email='".$f3->get('email')."';");
$result = $query->fetch(PDO::FETCH_ASSOC); $result = $query->fetch(\PDO::FETCH_ASSOC);
$cumul = 0; $cumul = 0;
if ($result['email']!=$f3->get('email')) { if ($result['email']!=$f3->get('email')) {
$hash = hash('sha256', $f3->get('password')); $hash = hash('sha256', $f3->get('password'));
// On recherche le montant cumulé jusqu'à présent. On fait la somme depuis le // On recherche le montant cumulé jusqu'à présent. On fait la somme depuis le
// premier janvier 2013 en se basant sur l'adresse mail // premier janvier 2013 en se basant sur l'adresse mail
$res = $db->query("SELECT sum(dons.somme) as somme FROM dons INNER JOIN users WHERE dons.user_id = users.id AND users.email='".$f3->get('email')."' and dons.status in (1, 4, 102) and dons.datec>'2013-01-01';"); $res = $db->query("SELECT sum(dons.somme) as somme FROM dons INNER JOIN users WHERE dons.user_id = users.id AND users.email='".$f3->get('email')."' and dons.status in (1, 4, 102) and dons.datec>'2013-01-01';");
$total = $res->fetch(PDO::FETCH_ASSOC); $total = $res->fetch(\PDO::FETCH_ASSOC);
$total = $total['somme']; $total = $total['somme'];
// Création de l'utilisateur // Création de l'utilisateur
$query = "INSERT INTO users (email, hash, total, cumul) VALUES ('".$f3->get('email')."', '".$hash."', '".$total."', 0);"; $query = "INSERT INTO users (email, hash, total, cumul) VALUES ('".$f3->get('email')."', '".$hash."', '".$total."', 0);";
...@@ -270,8 +271,8 @@ class Perso extends Controller ...@@ -270,8 +271,8 @@ class Perso extends Controller
if ($f3->get('password') != $f3->get('password_confirmation')) { if ($f3->get('password') != $f3->get('password_confirmation')) {
$f3->set('SESSION.error', 'Passwords mismatch'); $f3->set('SESSION.error', 'Passwords mismatch');
} else { } else {
$sql = "UPDATE users SET email='".Utils::asl($f3->get('email'))."', $sql = "UPDATE users SET email='".\Utils::asl($f3->get('email'))."',
pseudo='".Utils::asl($f3->get('pseudo'))."'"; pseudo='".\Utils::asl($f3->get('pseudo'))."'";
if ($f3->get('password') != '') { if ($f3->get('password') != '') {
$hash = hash('sha256', $f3->get('password')); $hash = hash('sha256', $f3->get('password'));
$sql .= ", hash='".$hash."'"; $sql .= ", hash='".$hash."'";
...@@ -298,15 +299,15 @@ class Perso extends Controller ...@@ -298,15 +299,15 @@ class Perso extends Controller
try { try {
$f3->get('container')['command_handler']->handle( $f3->get('container')['command_handler']->handle(
new AddressCreateCommand( new AddressCreateCommand(
Utils::