Jeremy DUCOURTHIAL 3 years ago
commit 14b5b29ca6

@ -1,16 +1,15 @@
<?php <?php
require_once("gatewaySources.php");
class controllerAdmin { class controllerAdmin {
function __construct() { function __construct() {
global $dsn,$user,$pass;
session_start(); session_start();
try try
{ {
$action=$_REQUEST['action']; $action=$_REQUEST['action'];
switch($action) { switch($action) {
case NULL:
break;
case "ajoutSource": case "ajoutSource":
$this->ajoutSource($_REQUEST["linkSource"]); $this->ajoutSource($_REQUEST["linkSource"]);
break; break;
@ -20,8 +19,12 @@ class controllerAdmin {
case "setNbArticlesParPage": case "setNbArticlesParPage":
$this->setNbArticlesParPage($_REQUEST["nbSourceParPage"]); $this->setNbArticlesParPage($_REQUEST["nbSourceParPage"]);
break; break;
default:
} $gateway = new GatewayNews(new Connection($dsn,$user,$pass));
$listeNews = $gateway->getNews();
require('vues/listeNews.php');
break;
}
} }
catch (PDOException $e) catch (PDOException $e)
{ {

@ -0,0 +1,38 @@
<?php
require('gatewayAdmins.php');
require('config.php');
class MdlAdmin
{
public function connection($login, $mdp){
$gateway = new GatewayAdmin(new Connection($dsn,$user,$pass));
if(password_verify($mdp,$gatewayAdmin->getCredential($login))){
$_SESSION['role']='admin';
$_SESSION['login']=$login;
return new Admin($login,$role);
}
else{
return NULL;
}
}
public function déconnexion(){
session_unset();
session_destroy();
$_SESSION = array();
}
public function isAdmin(){
if(isset $_SESSION['login'] && isset $_SESSION['role']) {
$login = Nettoyer::nettoyer_string($_SESSION['login']);
$role = Nettoyer::nettoyer_string($_SESSION['role']);
return new Admin($login,$role)
}
else{
return null;
}
}
}

@ -3,12 +3,12 @@
class Admin class Admin
{ {
private string $username; private string $username;
private string $password; private string $role;
public function __construct(string $username, string $password) public function __construct(string $username, string $role)
{ {
$this->username = $username; $this->username = $username;
$this->password = $password; $this->role = $role;
} }
public function getUsername() public function getUsername()
@ -16,9 +16,9 @@ class Admin
return $this->username; return $this->username;
} }
public function getPassword() public function getRole()
{ {
return $this->password; return $this->role;
} }
} }

@ -1,13 +1,4 @@
w<html>
<body>
<?php <?php
include("news.php");
include ('RssParser.php');
include("gatewayNews.php");
include("gatewaySources.php");
include ("config.php");
$parser = new RssParser(); $parser = new RssParser();
$gatewayNew = new gatewayNews($con); $gatewayNew = new gatewayNews($con);
$gatewaySource = new gatewaySources($con); $gatewaySource = new gatewaySources($con);
@ -20,21 +11,4 @@ foreach($listeSources as $source){
$gateNews->addNews($n); $gateNews->addNews($n);
} }
} }
/*
$resultFlux = $parser->getResultFlux("https://www.lemonde.fr/sciences/rss_full.xml");
foreach($resultFlux as $n){
$gateNews->addNews($n);
echo $n->getTitle();
echo "</br>";
echo $n->getPubdate();
echo "</br>";
echo $n->getLink();
echo "</br>";
echo $n->getDescription();
echo "</br>";
echo "</br>";
}
*/
?> ?>
</body>
</html>

@ -1,5 +1,5 @@
<?php <?php
include("connection.php"); require_once("connection.php");
//préfixe //préfixe
$rep=__DIR__.'/../'; $rep=__DIR__.'/../';
//BD //BD

@ -18,15 +18,13 @@ class GatewayAdmin
); );
} }
public function getAdmin($username,$password)
public function getCredential($login)
{ {
$query = "SELECT * FROM admin WHERE username = '$username' AND password = '$password'"; $query = "SELECT password FROM admin WHERE username = :login;";
$this->con->executeQuery($query, array()); $this->con->executeQuery($query, array(':login' => array($login, PDO::PARAM_STR)));
$results=$this->con->getResults(); $results=$this->con->getResults();
Foreach ($results as $admin){ return $results[0]['password'];
$listeAdmin[] = new Admin($admin["username"],$admin["password"]);
}
return $listeAdmin;
} }
} }

@ -1,11 +1,14 @@
<?php <?php
//chargement config
require_once("config.php");
require_once("connection.php"); require_once("connection.php");
require_once("ControllerAdmin.php"); require_once("ControllerAdmin.php");
require_once("gatewayAdmins.php"); require_once("gatewayAdmins.php");
require_once("gatewaySources.php"); require_once("gatewaySources.php");
require_once("gatewayNews.php");
require_once("gatewaySources.php");
//chargement config
require_once("config.php");
$controller = new ControllerAdmin(); $controller = new ControllerAdmin();
$c = new GatewaySources(); $c = new GatewaySources();

@ -0,0 +1,16 @@
<!doctype html>
<html>
<?php
foreach ($listeNews as $n){
echo $n->getTitle();
echo "</br>";
echo $n->getPubdate();
echo "</br>";
echo $n->getLink();
echo "</br>";
echo $n->getDescription();
echo "</br>";
echo "</br>";
}
?>
</html>
Loading…
Cancel
Save