fix plusieurs petits bugs

php
Anthony RICHARD 2 years ago
parent b815dbef75
commit f16c0de702

@ -42,9 +42,9 @@ class AdminController extends UserController
public function removeUser(): void { public function removeUser(): void {
try { try {
global $user; $userToRemove = Validation::filter_int($_GET['userToRemove'] ?? null);
$model = new MdlAdmin(); $model = new MdlAdmin();
$model->removeUser($user->getId()); $model->removeUser($userToRemove);
$this->showAllUsers(); $this->showAllUsers();
} }
catch (Exception $e) { catch (Exception $e) {
@ -80,9 +80,11 @@ class AdminController extends UserController
public function removeUserFromGroup(): void { public function removeUserFromGroup(): void {
try { try {
$id = Validation::filter_int($_GET['id'] ?? null); $userToRemove = Validation::filter_int($_GET['userToRemove'] ?? null);
$groupID = Validation::filter_int($_GET['selectedGroup'] ?? null);
$model = new MdlAdmin(); $model = new MdlAdmin();
$model->removeUserFromGroup($id); $model->removeUserFromGroup($userToRemove);
$_GET['selectedGroup'] = $groupID;
$this->showGroupDetails(); $this->showGroupDetails();
} }
catch (Exception $e) { catch (Exception $e) {
@ -120,10 +122,10 @@ class AdminController extends UserController
public function addUserToGroup(): void { public function addUserToGroup(): void {
try { try {
global $user; $userToAdd = Validation::filter_int($_GET['userToAdd'] ?? null);
$group = Validation::filter_int($_GET['groupID'] ?? null); $group = Validation::filter_int($_GET['groupID'] ?? null);
$model = new MdlAdmin(); $model = new MdlAdmin();
$model->addUserToGroup($user->getId(), $group); $model->addUserToGroup($userToAdd, $group);
$_GET['selectedGroup'] = $group; $_GET['selectedGroup'] = $group;
$this->showGroupDetails(); $this->showGroupDetails();
} }

@ -57,16 +57,17 @@ class FrontController
global $user; global $user;
$user = call_user_func_array(array($mdl, 'is'), array($_SESSION['login'], $_SESSION['roles'])); $user = call_user_func_array(array($mdl, 'is'), array($_SESSION['login'], $_SESSION['roles']));
if ($target == 'User' && $action == null) UserController::home();
else if (!$user || $user->getId() != $id) throw new Exception("erreur 403 permission denied");
$controller = '\\controller\\' . $target . 'Controller'; $controller = '\\controller\\' . $target . 'Controller';
$controller = new $controller; $controller = new $controller;
if ($target == 'User' && $action == null) $controller->home();
else if (!$user || $user->getId() != $id) throw new Exception("erreur 403 permission denied");
if (is_callable(array($controller, $action))) if (is_callable(array($controller, $action)))
call_user_func_array(array($controller, $action), array($match['params'])); call_user_func_array(array($controller, $action), array($match['params']));
} }
} }
else if ($target == 'User' && $action == null) UserController::home();
else (new UserController())->login(); else (new UserController())->login();
} }
} }

@ -54,7 +54,7 @@ class UserController extends VisitorController
} }
} }
public function home(): void { public static function home(): void {
global $twig; global $twig;
global $user; global $user;
if(isset($user)){ if(isset($user)){

@ -97,7 +97,7 @@ class VisitorController
if (!$this->checkLoginExist($login)) throw new Exception(("login invalide")); if (!$this->checkLoginExist($login)) throw new Exception(("login invalide"));
$user = $model->connection($login, $password); $user = $model->connection($login, $password);
if ($user == null) throw new Exception("mot de passe invalide"); if ($user == null) throw new Exception("mot de passe invalide");
FrontController::home(); UserController::home();
} }
public function checkLoginExist(string $login): bool { public function checkLoginExist(string $login): bool {
@ -108,7 +108,7 @@ class VisitorController
public function disconnect(): void { public function disconnect(): void {
$mdl = new MdlUser(); $mdl = new MdlUser();
$mdl->deconnection(); $mdl->deconnection();
FrontController::home(); UserController::home();
} }
public function resultatsJeux(): void{ public function resultatsJeux(): void{

@ -1,4 +1,4 @@
<form action="{{ base }}/admin/{{ userID }}/addGroup" method="GET"> <form action="{{ base }}/admin/{{ userID }}/addGroup" method="POST">
<input name="num" type="text" placeholder="number" required> <input name="num" type="text" placeholder="number" required>
<input name="year" type="text" placeholder="year" required> <input name="year" type="text" placeholder="year" required>
<input name="sector" type="text" placeholder="sector" required> <input name="sector" type="text" placeholder="sector" required>

@ -1,5 +1,4 @@
<table> <table>
{{ userID }}
{% if groups is defined %} {% if groups is defined %}
{% for row in groups %} {% for row in groups %}
{% if selectedGroup is defined and selectedGroup == row.id %} {% if selectedGroup is defined and selectedGroup == row.id %}

@ -28,8 +28,10 @@
{% endif %} {% endif %}
{% if userRole is empty %} {% if userRole is empty %}
<li class="nav-item"><a class="nav-link" href="{{base}}/visitor/login">Login</a></li> <li class="nav-item"><a class="nav-link" href="{{base}}/visitor/login">Login</a></li>
{% else %}
<li class="nav-item"><a class="nav-link" href="{{ base }}/visitor/disconnect">Log out</a></li>
{% endif %} {% endif %}
<li class="nav-item"><a class="nav-link" href="{{ base }}/visitor/disconnect">Log out</a></li>
</ul> </ul>
</div> </div>
</div> </div>

@ -24,17 +24,17 @@
{% if action is defined %} {% if action is defined %}
{% if action == 'removeUserFromGroup' %} {% if action == 'removeUserFromGroup' %}
<td><a href="{{base}}/admin/{{ userID }}/removeUserFromGroup?id={{row.id}}&selectedGroup={{selectedGroup}}"> <td><a href="{{base}}/admin/{{ userID }}/removeUserFromGroup?userToRemove={{row.id}}&selectedGroup={{ selectedGroup }}">
<input class="btn-black" type="button" value="Delete from group"/> <input class="btn-black" type="button" value="Delete from group"/>
</a></td> </a></td>
{% elseif action == 'addUserToGroup' %} {% elseif action == 'addUserToGroup' %}
<td><a href="{{base}}/admin/{{ userID }}/addUserToGroup?userID={{row.id}}&groupID={{selectedGroup}}"> <td><a href="{{base}}/admin/{{ userID }}/addUserToGroup?userToAdd={{row.id}}&groupID={{selectedGroup}}">
<input class="btn-black" type="button" value="Add to group"/> <input class="btn-black" type="button" value="Add to group"/>
</a></td> </a></td>
{% elseif action == 'removeUser' %} {% elseif action == 'removeUser' %}
<td><a href="{{base}}/admin/{{ userID }}/removeUser?userID={{row.id}}"> <td><a href="{{base}}/admin/{{ userID }}/removeUser?userToRemove={{row.id}}">
<input class="btn-black" type="button" value="Delete"/> <input class="btn-black" type="button" value="Delete"/>
</a></td> </a></td>
{% endif %} {% endif %}

Loading…
Cancel
Save