Build : Squelette du code 🍻
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
ccea28238d
commit
dadfbb7164
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ControllerAdministrator
|
||||||
|
{
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
global $dsn, $user, $pass, $vues;
|
||||||
|
session_start();
|
||||||
|
try {
|
||||||
|
$action = "";
|
||||||
|
if (isset($_REQUEST['action'])) {
|
||||||
|
$action = $_REQUEST['action'];
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($action) {
|
||||||
|
case "goToAdministratorConnexion":
|
||||||
|
require($vues['AdministratorConnexion']);
|
||||||
|
break;
|
||||||
|
case "goToAdministration":
|
||||||
|
require($vues['Administration']);
|
||||||
|
break;
|
||||||
|
case "verifValidation":
|
||||||
|
$this->validationConnexion();
|
||||||
|
break;
|
||||||
|
case "quitterAdministrator":
|
||||||
|
$Administrator->deconnexion();
|
||||||
|
header("location: index.php");
|
||||||
|
break;
|
||||||
|
case "AjouterQuestion":
|
||||||
|
case "SupprimerQuestion":
|
||||||
|
case "ModifierQuestion":
|
||||||
|
case "AjouterReponse":
|
||||||
|
case "SupprimerReponse":
|
||||||
|
case "ModifierReponse":
|
||||||
|
case "AjouterAdmin":
|
||||||
|
case "SupprimerAdmin":
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
// $dataVueEreur[] = "Erreur inattendue!!! ";
|
||||||
|
// require(__DIR__.'/../vues/erreur.php');
|
||||||
|
} catch (Exception $e2) {
|
||||||
|
// $dataVueEreur[] = "Erreur inattendue!!! ";
|
||||||
|
// require ($rep.$vues['erreur']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function validationConnexion()
|
||||||
|
{
|
||||||
|
global $vues;
|
||||||
|
$validation = new Validation();
|
||||||
|
$error = [];
|
||||||
|
$validation->val_form($_POST['name'], $_POST['password'], $error);
|
||||||
|
foreach ($error as $key) {
|
||||||
|
print($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($error)) {
|
||||||
|
$validation = $Administrator->connection($_POST['name'], $_POST['password']);
|
||||||
|
if (!empty($validation)) {
|
||||||
|
header("location: index.php?action=goToAdministratoristration");
|
||||||
|
} else {
|
||||||
|
header("location: index.php?action=goToAdministratorConnexion");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
header("location: index.php?action=goToAdministratorConnexion");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class FrontController
|
||||||
|
{
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
global $dsn, $user, $pass, $vues;
|
||||||
|
$listeAction_Administrator = array('goToAdministratorConnexion', 'verifValidation', 'ajoutSource', 'supprimerSource', 'setNbArticlesParPage', 'goToAdministratoristration', 'refreshData', 'quitterAdministrator');
|
||||||
|
try {
|
||||||
|
$mdlAdministrator = new MdlAdministrator();
|
||||||
|
$Administrator = $mdlAdministrator->isAdministrator();
|
||||||
|
$action = "";
|
||||||
|
if (isset($_REQUEST['action'])) {
|
||||||
|
$action = $_REQUEST['action'];
|
||||||
|
}
|
||||||
|
if (in_array($action, $listeAction_Administrator)) {
|
||||||
|
if ($Administrator == NULL) {
|
||||||
|
new ControllerAdministrator();
|
||||||
|
} else {
|
||||||
|
header("Location:" . $vues["AdministratorConnexion"]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$gatewayNews = new GatewayNews(new Connection($dsn, $user, $pass));
|
||||||
|
$page = 1;
|
||||||
|
if (isset($_GET['page'])) {
|
||||||
|
$page = $_GET['page'];
|
||||||
|
}
|
||||||
|
$gate = new GatewayConfigAdministrator(new Connection($dsn, $user, $pass));
|
||||||
|
$nbArticlePages = $gate->getConfigAdministrator(1);
|
||||||
|
$listeNews = $gatewayNews->getNews($page, $nbArticlePages);
|
||||||
|
$pageAvant = $page - 1;
|
||||||
|
$pageApres = $page + 1;
|
||||||
|
|
||||||
|
|
||||||
|
$pageMAX = $gatewayNews->getNbNews() / $nbArticlePages + 1;
|
||||||
|
require($vues['listeNews']);
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
header("Location:" . $vues["erreur"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class GatewayAdministrator
|
||||||
|
{
|
||||||
|
private $con;
|
||||||
|
|
||||||
|
public function __construct($con)
|
||||||
|
{
|
||||||
|
$this->con = $con;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addAdministrator($Administrator)
|
||||||
|
{
|
||||||
|
$query = "insert into Administratoristrator(id,username,password) values (:id,:username,:password);";
|
||||||
|
$this->con->executeQuery(
|
||||||
|
$query,
|
||||||
|
array(
|
||||||
|
':id' => array($Administrator->getId(), PDO::PARAM_INT),
|
||||||
|
':username' => array($Administrator->getUsername(), PDO::PARAM_STR),
|
||||||
|
':password' => array(password_hash($Administrator->getPassword(), PASSWORD_DEFAULT), PDO::PARAM_STR)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getCredential($login)
|
||||||
|
{
|
||||||
|
$query = "SELECT password FROM Administrator WHERE username = :login;";
|
||||||
|
$this->con->executeQuery($query, array(':login' => array($login, PDO::PARAM_STR)));
|
||||||
|
$results = $this->con->getResults();
|
||||||
|
if ($results == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $results[0]['password'];
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Administrator
|
||||||
|
{
|
||||||
|
private int $id;
|
||||||
|
private string $username;
|
||||||
|
|
||||||
|
public function __construct(int $id, string $username)
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
$this->username = $username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUsername()
|
||||||
|
{
|
||||||
|
return $this->username;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
<?php
|
||||||
|
class Appel
|
||||||
|
{
|
||||||
|
static function refresh()
|
||||||
|
{
|
||||||
|
global $dsn, $user, $pass;
|
||||||
|
try {
|
||||||
|
} catch (Exception $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Autoload
|
||||||
|
{
|
||||||
|
private static $_instance = null;
|
||||||
|
|
||||||
|
public static function charger()
|
||||||
|
{
|
||||||
|
if (null !== self::$_instance) {
|
||||||
|
throw new RuntimeException(sprintf('%s is already started', __CLASS__));
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$_instance = new self();
|
||||||
|
|
||||||
|
|
||||||
|
if (!spl_autoload_register(array(self::$_instance, '_autoload'), false)) {
|
||||||
|
throw new RuntimeException(sprintf('%s : Could not start the autoload', __CLASS__));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function shutDown()
|
||||||
|
{
|
||||||
|
if (null !== self::$_instance) {
|
||||||
|
|
||||||
|
if (!spl_autoload_unregister(array(self::$_instance, '_autoload'))) {
|
||||||
|
throw new RuntimeException('Could not stop the autoload');
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$_instance = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function _autoload($class)
|
||||||
|
{
|
||||||
|
global $rep;
|
||||||
|
$filename = $class . '.php';
|
||||||
|
$dir = array('models/', './', 'usages/', 'controllers/', 'gateways/', 'update/', 'vues/');
|
||||||
|
foreach ($dir as $d) {
|
||||||
|
$file = $rep . $d . $filename;
|
||||||
|
//echo $file;
|
||||||
|
if (file_exists($file)) {
|
||||||
|
include $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
//préfixe
|
||||||
|
$rep= __DIR__ . '/../';
|
||||||
|
//BD
|
||||||
|
$user= 'jeducourth';
|
||||||
|
$pass='achanger';
|
||||||
|
$dsn='mysql:host=localhost;dbname=dbjeducourth';
|
||||||
|
|
||||||
|
//Vues
|
||||||
|
$vues['erreur'] ='vues/erreur.php';
|
||||||
|
$vues['listeNews'] ='vues/listeNews.php';
|
||||||
|
$vues['connexionView'] ='vues/connexionView.php';
|
||||||
|
$vues['Administratoristration'] ='vues/Administratoristration.php';
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
class ConnectionBaseDeDonnee extends PDO {
|
||||||
|
private $stmt;
|
||||||
|
|
||||||
|
public function __construct(string $dsn, string $username, string $password) {
|
||||||
|
|
||||||
|
parent::__construct($dsn,$username,$password);
|
||||||
|
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** * @param string $query
|
||||||
|
* @param array $parameters *
|
||||||
|
* @return bool Returns `true` on success, `false` otherwise
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function executeQuery(string $query, array $parameters = []) : bool{
|
||||||
|
$this->stmt = parent::prepare($query);
|
||||||
|
foreach ($parameters as $name => $value) {
|
||||||
|
$this->stmt->bindValue($name, $value[0], $value[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->stmt->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getResults() : array {
|
||||||
|
return $this->stmt->fetchall();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in new issue