add listes sources a appel.php

master
Bastien OLLIER 3 years ago
parent cbad497b4e
commit 3a1eb53dea

@ -1,16 +1,15 @@
<?php
require_once("gatewaySources.php");
class controllerAdmin {
function __construct() {
global $dsn,$user,$pass;
session_start();
try
{
$action=$_REQUEST['action'];
switch($action) {
case NULL:
break;
case "ajoutSource":
$this->ajoutSource($_REQUEST["linkSource"]);
break;
@ -20,7 +19,11 @@ class controllerAdmin {
case "setNbArticlesParPage":
$this->setNbArticlesParPage($_REQUEST["nbSourceParPage"]);
break;
default:
$gateway = new GatewayNews(new Connection($dsn,$user,$pass));
$listeNews = $gateway->getNews();
require('vues/listeNews.php');
break;
}
}
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
{
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->password = $password;
$this->role = $role;
}
public function getUsername()
@ -16,9 +16,9 @@ class Admin
return $this->username;
}
public function getPassword()
public function getRole()
{
return $this->password;
return $this->role;
}
}

@ -1,13 +1,4 @@
w<html>
<body>
<?php
include("news.php");
include ('RssParser.php');
include("gatewayNews.php");
include("gatewaySources.php");
include ("config.php");
$parser = new RssParser();
$gatewayNew = new gatewayNews($con);
$gatewaySource = new gatewaySources($con);
@ -20,21 +11,4 @@ foreach($listeSources as $source){
$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
include("connection.php");
require_once("connection.php");
//préfixe
$rep=__DIR__.'/../';
//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'";
$this->con->executeQuery($query, array());
$query = "SELECT password FROM admin WHERE username = :login;";
$this->con->executeQuery($query, array(':login' => array($login, PDO::PARAM_STR)));
$results=$this->con->getResults();
Foreach ($results as $admin){
$listeAdmin[] = new Admin($admin["username"],$admin["password"]);
}
return $listeAdmin;
return $results[0]['password'];
}
}

@ -1,10 +1,13 @@
<?php
//chargement config
require_once("config.php");
require_once("connection.php");
require_once("ControllerAdmin.php");
require_once("gatewayAdmins.php");
require_once("gatewayNews.php");
require_once("gatewaySources.php");
//chargement config
require_once("config.php");
$controller = new ControllerAdmin();
?>

@ -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