🐛 connection ne fonction plus

pull/8/head
mapoint2 1 year ago
parent 4674a7f2ad
commit b027322e4f

@ -36,7 +36,7 @@ class AdminControleur
//mauvaise action
default:
$dVueEreur[] = "Erreur d'appel php";
echo $twig->render('listArticle.html', ['dVueErreur'=>$dVueEreur,'isAdmin' => AdminModel::isAdmin()]);
echo $twig->render('listArticle.html', ['dVueErreur'=>$dVueEreur,'isAdmin' => (AdminModel::isAdmin())]);
break;
}
} catch (\PDOException $e) {
@ -67,7 +67,7 @@ class AdminControleur
public function connection(){
global $twig; // nécessaire pour utiliser variables globales
if (!AdminModel::isAdmin()){
if (AdminModel::isAdmin()){
$this->listArticle();
}
else {

@ -15,7 +15,7 @@ class FrontControleur
global $twig;
$router = new AltoRouter();
$router->setBasePath('~mapoint2/SAE/Php_RSS/fluxRSS/');
$router->map('GET', '/[a:action]?', 'UserControleur');
$router->map('GET', '/', 'AdminControleur');
$router->map('GET|POST','/user/[a:action]?','UserControleur');
$router->map('GET|POST','/admin/[a:action]?','AdminControleur');
@ -31,7 +31,7 @@ class FrontControleur
try {
if($controller == "AdminControleur"){
if (!AdminModel::isAdmin()){
$action = "connection";
//$action = "connection";
}
}
$controller = '\\controleur\\' . $controller;

@ -71,25 +71,36 @@ class UserControleur
*/
public function connection(){
global $twig; // nécessaire pour utiliser variables globales
echo $twig->render('Connection.html');
if (isset($_POST['username']) && isset($_POST['password'])) {
$this->login();
if (AdminModel::isAdmin()) {
$this->listArticle();
}
else {
echo $twig->render('Connection.html');
if (isset($_POST['username']) && isset($_POST['password'])) {
$this->login();
}
}
}
/**
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
* @throws \Twig\Error\LoaderError
* @throws \Exception
*/
public function login(){
$username = $_POST['username'];
$password = $_POST['password'];
$adminModel = new AdminModel();
$admin = $adminModel->connection($username, $password);
if ($admin != null) {
$this->listArticle();
}
else{
unset($_POST['username']);
unset($_POST['passwords']);
unset($_SESSION['role']);
$this->connection();
}
}

@ -25,11 +25,13 @@ class AdminModel
return new Admin($username,$motDePasse['mail']);
}
}
unset($_SESSION['role']);
unset($_SESSION['pseudo']);
return null;
}
public static function isAdmin(): bool
{
return isset($_SESSION['role']) && $_SESSION['role'] == 'admin';
return (isset($_SESSION['role']) && $_SESSION['role'] == 'admin');
}
}

@ -43,7 +43,7 @@
<!-- action !!!!!!!!!! -->
<input type="hidden" name="action" value="login" />
</form>
<a href="/~mapoint2/SAE/Php_RSS/fluxRSS/">Not a member? Go to Articles</a>
<a href="/~mapoint2/SAE/Php_RSS/fluxRSS/user/">Not a member? Go to Articles</a>
</div>
</body>
</html>

Loading…
Cancel
Save