good routes, good controllers
continuous-integration/drone/push Build is failing Details

pull/22/head
Override-6 2 years ago
parent 704f1272f7
commit 36051ebd83
Signed by untrusted user who does not match committer: maxime.batista
GPG Key ID: 8002CC4B4DD9ECA5

Before

Width:  |  Height:  |  Size: 507 B

After

Width:  |  Height:  |  Size: 507 B

Before

Width:  |  Height:  |  Size: 732 B

After

Width:  |  Height:  |  Size: 732 B

@ -30,7 +30,8 @@ function getAuthController(): APIAuthController {
/** /**
* A Front controller action * A Front controller action
*/ */
class Action { //TODO workaround for generic Action
class ApiAction {
/** /**
* @var callable(mixed[]): HttpResponse $action action to call * @var callable(mixed[]): HttpResponse $action action to call
*/ */
@ -69,18 +70,18 @@ class Action {
/** /**
* @param callable(mixed[]): HttpResponse $action * @param callable(mixed[]): HttpResponse $action
* @return Action an action that does not require to have an authorization. * @return ApiAction an action that does not require to have an authorization.
*/ */
public static function noAuth(callable $action): Action { public static function noAuth(callable $action): ApiAction {
return new Action($action, false); return new ApiAction($action, false);
} }
/** /**
* @param callable(mixed[]): HttpResponse $action * @param callable(mixed[]): HttpResponse $action
* @return Action an action that does require to have an authorization. * @return ApiAction an action that does require to have an authorization.
*/ */
public static function auth(callable $action): Action { public static function auth(callable $action): ApiAction {
return new Action($action, true); return new ApiAction($action, true);
} }
} }
@ -95,23 +96,23 @@ function handleMatch(array $match): HttpResponse {
} }
$action = $match['target']; $action = $match['target'];
if (!$action instanceof Action) { if (!$action instanceof ApiAction) {
throw new Exception("routed action is not an Action object."); throw new Exception("routed action is not an Action object.");
} }
$auth = null; $auth = null;
if ($action->isAuthRequired()) { if ($action->isAuthRequired()) {
$auth = tryGetAuthAccount(); $auth = tryGetAuthorization();
if ($auth == null) { if ($auth == null) {
return new JsonHttpResponse([ValidationFail::unauthorized("Missing or invalid 'Authorization' header")]); return new JsonHttpResponse([ValidationFail::unauthorized("Missing or invalid 'Authorization' header.")]);
} }
} }
return $action->run($match['params'], $auth); return $action->run($match['params'], $auth);
} }
function tryGetAuthAccount(): ?Account { function tryGetAuthorization(): ?Account {
$headers = getallheaders(); $headers = getallheaders();
// If no authorization header is set, try fallback to php session. // If no authorization header is set, try fallback to php session.
@ -128,10 +129,10 @@ function tryGetAuthAccount(): ?Account {
$router = new AltoRouter(); $router = new AltoRouter();
$router->setBasePath(get_public_path() . "/api"); $router->setBasePath(get_public_path() . "/api");
$router->map("POST", "/tactic/[i:id]/edit/name", Action::auth(fn(int $id, Account $acc) => getTacticController()->updateName($id, $acc))); $router->map("POST", "/tactic/[i:id]/edit/name", ApiAction::auth(fn(int $id, Account $acc) => getTacticController()->updateName($id, $acc)));
$router->map("GET", "/tactic/[i:id]", Action::auth(fn(int $id, Account $acc) => getTacticController()->getTacticInfo($id, $acc))); $router->map("GET", "/tactic/[i:id]", ApiAction::auth(fn(int $id, Account $acc) => getTacticController()->getTacticInfo($id, $acc)));
$router->map("POST", "/tactic/new", Action::auth(fn(Account $acc) => getTacticController()->newTactic($acc))); $router->map("POST", "/tactic/new", ApiAction::auth(fn(Account $acc) => getTacticController()->newTactic($acc)));
$router->map("POST", "/auth", Action::noAuth(fn() => getAuthController()->authorize())); $router->map("POST", "/auth", ApiAction::noAuth(fn() => getAuthController()->authorize()));
$match = $router->match(); $match = $router->match();

@ -7,12 +7,93 @@ require "../sql/database.php";
require "utils.php"; require "utils.php";
require "../src/react-display.php"; require "../src/react-display.php";
use App\Controller\FrontController; use App\Controller\AuthController;
use App\Controller\EditorController;
use App\Controller\Route\Action;
use App\Controller\Route\FrontController;
use App\Controller\TeamController;
use App\Controller\UserController;
use App\Controller\VisualizerController;
use App\Gateway\AccountGateway;
use App\Gateway\TacticInfoGateway;
use App\Gateway\TeamGateway;
use App\Model\AuthModel;
use App\Model\TacticModel;
use App\Model\TeamModel;
use App\Session\MutableSessionHandle;
use App\Session\PhpSessionHandle; use App\Session\PhpSessionHandle;
use App\Connexion;
use App\Session\SessionHandle;
$connexion = new Connexion(get_database());
function getUserController(): UserController {
global $connexion;
return new UserController(new TacticModel(new TacticInfoGateway($connexion)));
}
function getVisualizerController(): VisualizerController {
global $connexion;
return new VisualizerController(new TacticModel(new TacticInfoGateway($connexion)));
}
function getEditorController(): EditorController {
global $connexion;
return new EditorController(new TacticModel(new TacticInfoGateway($connexion)));
}
function getTeamController(): TeamController {
global $connexion;
return new TeamController(new TeamModel(new TeamGateway($connexion)));
}
function getAuthController(): AuthController {
global $connexion;
return new AuthController(new AuthModel(new AccountGateway($connexion)));
}
function initFrontController(FrontController $fc) {
//authentication
$fc->addRoute("GET", "/login", Action::noAuth(fn() => getAuthController()->displayLogin()));
$fc->addRoute("GET", "/register", Action::noAuth(fn() => getAuthController()->displayRegister()));
$fc->addRoute("POST", "/login", Action::noAuth(fn(SessionHandle $s) => getAuthController()->confirmLogin($_POST, $s)));
$fc->addRoute("POST", "/register", Action::noAuth(fn(SessionHandle $s) => getAuthController()->confirmRegister($_POST, $s)));
//user-related
$fc->addRoute("GET", "/home", Action::auth(fn(SessionHandle $s) => getUserController()->home($s)));
$fc->addRoute("GET", "/settings", Action::auth(fn(SessionHandle $s) => getUserController()->settings($s)));
//tactic-related
$fc->addRoute("GET", "/tactic/[i:id]/view", Action::auth(fn(int $id, SessionHandle $s) => getVisualizerController()->visualize($id, $s)));
$fc->addRoute("GET", "/tactic/[i:id]/edit", Action::auth(fn(int $id, SessionHandle $s) => getEditorController()->edit($id, $s)));
$fc->addRoute("GET", "/tactic/new", Action::auth(fn(SessionHandle $s) => getEditorController()->createNew($s)));
//team-related
$fc->addRoute("GET", "/team/new", Action::auth(fn(SessionHandle $s) => getTeamController()->displayCreateTeam($s)));
$fc->addRoute("POST", "/team/new", Action::auth(fn(SessionHandle $s) => getTeamController()->submitTeam($_POST, $s)));
$fc->addRoute("GET", "/team/search", Action::auth(fn(SessionHandle $s) => getTeamController()->displayListTeamByName($s)));
$fc->addRoute("POST", "/team/search", Action::auth(fn(SessionHandle $s) => getTeamController()->listTeamByName($_POST, $s)));
$fc->addRoute("GET", "/team/[i:id]", Action::auth(fn(int $id, SessionHandle $s) => getTeamController()->displayTeam($id, $s)));
$fc->addRoute("GET", "/team/members/add", Action::auth(fn(SessionHandle $s) => getTeamController()->displayAddMember($s)));
$fc->addRoute("POST", "/team/members/add", Action::auth(fn(SessionHandle $s) => getTeamController()->addMember($_POST, $s)));
$fc->addRoute("GET", "/team/members/remove", Action::auth(fn(SessionHandle $s) => getTeamController()->displayDeleteMember($s)));
$fc->addRoute("POST", "/team/members/remove", Action::auth(fn(SessionHandle $s) => getTeamController()->deleteMember($_POST, $s)));
}
//this is a global variable
$basePath = get_public_path(); $basePath = get_public_path();
$frontController = new FrontController($basePath);
$frontController->run(PhpSessionHandle::init()); function run() {
global $basePath;
$fc = new FrontController($basePath);
initFrontController($fc);
$fc->run(PhpSessionHandle::init());
}
run();

@ -1,13 +1,12 @@
<?php <?php
namespace App\Controller\Sub; namespace App\Controller;
use App\Http\HttpRequest; use App\Http\HttpRequest;
use App\Http\HttpResponse; use App\Http\HttpResponse;
use App\Http\ViewHttpResponse; use App\Http\ViewHttpResponse;
use App\Model\AuthModel; use App\Model\AuthModel;
use App\Session\MutableSessionHandle; use App\Session\MutableSessionHandle;
use App\Validation\FieldValidationFail;
use App\Validation\ValidationFail; use App\Validation\ValidationFail;
use App\Validation\Validators; use App\Validation\Validators;

@ -1,18 +1,13 @@
<?php <?php
namespace App\Controller\Sub; namespace App\Controller;
use App\Connexion;
use App\Controller\VisitorController;
use App\Data\TacticInfo; use App\Data\TacticInfo;
use App\Gateway\TacticInfoGateway;
use App\Http\HttpCodes; use App\Http\HttpCodes;
use App\Http\HttpResponse; use App\Http\HttpResponse;
use App\Http\JsonHttpResponse;
use App\Http\ViewHttpResponse; use App\Http\ViewHttpResponse;
use App\Model\TacticModel; use App\Model\TacticModel;
use App\Session\SessionHandle; use App\Session\SessionHandle;
use App\Validation\ValidationFail;
use App\Validator\TacticValidator; use App\Validator\TacticValidator;
class EditorController { class EditorController {

@ -0,0 +1,71 @@
<?php
namespace App\Controller\Route;
use App\Http\HttpResponse;
use App\Session\SessionHandle;
use Exception;
/**
* A Front controller action
*/
class Action {
/**
* @var callable(mixed[]): HttpResponse $action action to call
*/
private $action;
private bool $isAuthRequired;
/**
* @param callable(mixed[]): HttpResponse $action
*/
private function __construct(callable $action, bool $isAuthRequired) {
$this->action = $action;
$this->isAuthRequired = $isAuthRequired;
}
public function isAuthRequired(): bool {
return $this->isAuthRequired;
}
/**
* @param mixed[] $params
* @param SessionHandle $session
* @return HttpResponse
* @throws Exception <p>
* thrown if this action is required to be authenticated, but the given session does not contain a logged-in account.
* </p>
* <p>
* Caller is supposed to ensure that the user is logged-in before, if `$this->isAuthRequired()` is true before
* running this action.
* </p>
*/
public function run(array $params, SessionHandle $session): HttpResponse {
$params = array_values($params);
if ($this->isAuthRequired) {
if ($session->getAccount() == null) {
throw new Exception("action requires authorization.");
}
}
$params[] = $session;
return call_user_func_array($this->action, $params);
}
/**
* @param callable(mixed[]): HttpResponse $action
* @return Action an action that does not require to have an authorization.
*/
public static function noAuth(callable $action): Action {
return new Action($action, false);
}
/**
* @param callable(mixed[]): HttpResponse $action
* @return Action an action that does require to have an authorization.
*/
public static function auth(callable $action): Action {
return new Action($action, true);
}
}

@ -1,6 +1,6 @@
<?php <?php
namespace App\Controller; namespace App\Controller\Route;
use AltoRouter; use AltoRouter;
use App\Http\HttpCodes; use App\Http\HttpCodes;
@ -9,7 +9,6 @@ use App\Http\JsonHttpResponse;
use App\Http\ViewHttpResponse; use App\Http\ViewHttpResponse;
use App\Session\MutableSessionHandle; use App\Session\MutableSessionHandle;
use App\Validation\ValidationFail; use App\Validation\ValidationFail;
use Exception;
use Twig\Environment; use Twig\Environment;
use Twig\Error\LoaderError; use Twig\Error\LoaderError;
use Twig\Error\RuntimeError; use Twig\Error\RuntimeError;
@ -20,16 +19,16 @@ class FrontController {
private AltoRouter $router; private AltoRouter $router;
private string $basePath; private string $basePath;
private const USER_CONTROLLER = "UserController";
private const VISITOR_CONTROLLER = "VisitorController";
public function __construct(string $basePath) { public function __construct(string $basePath) {
$this->router = $this->createRouter($basePath); $this->router = $this->createRouter($basePath);
$this->initializeRouterMap();
$this->basePath = $basePath; $this->basePath = $basePath;
} }
public function addRoute(string $method, string $path, Action $action): void {
$this->router->map($method, $path, $action);
}
/** /**
* @param MutableSessionHandle $session * @param MutableSessionHandle $session
* @return void * @return void
@ -61,85 +60,36 @@ class FrontController {
return $router; return $router;
} }
/**
* Initialize project's routes
*
* @return void
*/
private function initializeRouterMap(): void {
$this->router->map("GET", "/home", self::USER_CONTROLLER);
$this->router->map("GET|POST", "/user/[a:action]/[i:idTactic]?", self::USER_CONTROLLER);
$this->router->map("GET|POST", "/visitor/[a:action]", self::VISITOR_CONTROLLER);
}
/** /**
* @param array<string, mixed> $match * @param array<string, mixed> $match
* @param MutableSessionHandle $session * @param MutableSessionHandle $session
* @return void * @return void
*/ */
private function handleMatch(array $match, MutableSessionHandle $session): void { private function handleMatch(array $match, MutableSessionHandle $session): void {
$tag = $match['target']; $action = $match['target'];
$params = array_values($match["params"]);
$action = $this->getAction($match); $this->handleResponseByType($this->tryToCall($action, $params, $session));
$params = $match["params"];
unset($params['action']);
$this->handleResponseByType($this->tryToCall($tag, $action, array_values($params), $session));
} }
/** /**
* @param string $controllerName * @param Action $action
* @param string $action
* @param array<int, mixed> $params * @param array<int, mixed> $params
* @param MutableSessionHandle $session * @param MutableSessionHandle $session
* @return HttpResponse * @return HttpResponse
*/ */
private function tryToCall(string $controllerName, string $action, array $params, MutableSessionHandle $session): HttpResponse { private function tryToCall(Action $action, array $params, MutableSessionHandle $session): HttpResponse {
if ($controllerName != self::VISITOR_CONTROLLER) { $account = null;
if ($action->isAuthRequired()) {
$account = $session->getAccount(); $account = $session->getAccount();
if ($account == null) { if ($account == null) {
// put in the session the initial url the user wanted to get // put in the session the initial url the user wanted to get
$session->setInitialTarget($_SERVER['REQUEST_URI']); $session->setInitialTarget($_SERVER['REQUEST_URI']);
return HttpResponse::redirect($this->basePath . "/visitor/login"); return HttpResponse::redirect($this->basePath . "/login");
} }
} }
$controller = $this->getController($controllerName); return $action->run($params, $session);
if (is_callable([$controller, $action])) {
// append the session as the last parameter of a controller function
$params[] = $session;
return call_user_func_array([$controller, $action], $params);
} else {
return ViewHttpResponse::twig("error.html.twig", [
'failures' => [ValidationFail::notFound("Could not find page ${_SERVER['REQUEST_URI']}.")],
], HttpCodes::NOT_FOUND);
}
}
/**
* Get the right method to call to do an action
*
* @param array<string, mixed> $match
* @return string
*/
private function getAction(array $match): string {
if (isset($match["params"]["action"])) {
return $match["params"]["action"];
}
return "home";
}
/**
* Initialize the right controller by the user's role
*
* @param string $controller
* @return mixed
*/
private function getController(string $controller) {
$namespace = "\\App\\Controller\\";
$controller = $namespace . $controller;
return new $controller();
} }
/** /**
@ -182,7 +132,7 @@ class FrontController {
$loader = new FilesystemLoader('../src/Views/'); $loader = new FilesystemLoader('../src/Views/');
$twig = new Environment($loader); $twig = new Environment($loader);
$twig->display($file, $args); $twig->display($file, $args);
} catch (RuntimeError | SyntaxError | LoaderError $e) { } catch (RuntimeError|SyntaxError|LoaderError $e) {
http_response_code(500); http_response_code(500);
echo "There was an error rendering your view, please refer to an administrator.\nlogs date: " . date("YYYD, d M Y H:i:s"); echo "There was an error rendering your view, please refer to an administrator.\nlogs date: " . date("YYYD, d M Y H:i:s");
throw $e; throw $e;

@ -1,11 +1,12 @@
<?php <?php
namespace App\Controller\Sub; namespace App\Controller;
use App\Http\HttpRequest; use App\Http\HttpRequest;
use App\Http\HttpResponse; use App\Http\HttpResponse;
use App\Http\ViewHttpResponse; use App\Http\ViewHttpResponse;
use App\Model\TeamModel; use App\Model\TeamModel;
use App\Session\SessionHandle;
use App\Validation\FieldValidationFail; use App\Validation\FieldValidationFail;
use App\Validation\Validators; use App\Validation\Validators;
@ -19,20 +20,20 @@ class TeamController {
$this->model = $model; $this->model = $model;
} }
public function displaySubmitTeam(): HttpResponse { public function displayCreateTeam(SessionHandle $session): HttpResponse {
return ViewHttpResponse::twig("insert_team.html.twig", []); return ViewHttpResponse::twig("insert_team.html.twig", []);
} }
public function displayAddMember() : HttpResponse { public function displayAddMember(SessionHandle $session): HttpResponse {
return ViewHttpResponse::twig("add_member.html.twig", []); return ViewHttpResponse::twig("add_member.html.twig", []);
} }
public function displayDeleteMember() : HttpResponse { public function displayDeleteMember(SessionHandle $session): HttpResponse {
return ViewHttpResponse::twig("delete_member.html.twig", []); return ViewHttpResponse::twig("delete_member.html.twig", []);
} }
public function submitTeam(array $request): HttpResponse { public function submitTeam(array $request, SessionHandle $session): HttpResponse {
$errors = []; $errors = [];
@ -51,10 +52,10 @@ class TeamController {
} }
return ViewHttpResponse::twig('insert_team.html.twig', ['bad_fields' => $badFields]); return ViewHttpResponse::twig('insert_team.html.twig', ['bad_fields' => $badFields]);
} }
return $this->getTeam($this->model->createTeam($request['name'], $request['picture'], $request['mainColor'], $request['secondColor'])); return $this->displayTeam($this->model->createTeam($request['name'], $request['picture'], $request['mainColor'], $request['secondColor']), $session);
} }
public function displayListTeamByName(): HttpResponse { public function displayListTeamByName(SessionHandle $session): HttpResponse {
return ViewHttpResponse::twig("list_team_by_name.html.twig", []); return ViewHttpResponse::twig("list_team_by_name.html.twig", []);
} }
@ -62,7 +63,7 @@ class TeamController {
* @param array<string , mixed> $request * @param array<string , mixed> $request
* @return HttpResponse * @return HttpResponse
*/ */
public function listTeamByName(array $request): HttpResponse { public function listTeamByName(array $request, SessionHandle $session): HttpResponse {
$errors = []; $errors = [];
$request = HttpRequest::from($request, $errors, [ $request = HttpRequest::from($request, $errors, [
"name" => [Validators::lenBetween(1, 32), Validators::nameWithSpaces()], "name" => [Validators::lenBetween(1, 32), Validators::nameWithSpaces()],
@ -82,30 +83,30 @@ class TeamController {
return ViewHttpResponse::twig('display_teams.html.twig', ['teams' => $results]); return ViewHttpResponse::twig('display_teams.html.twig', ['teams' => $results]);
} }
public function getTeam(int $id): HttpResponse { public function displayTeam(int $id, SessionHandle $session): HttpResponse {
$result = $this->model->displayTeam($id); $result = $this->model->displayTeam($id);
return ViewHttpResponse::twig('display_team.html.twig', ['team' => $result]); return ViewHttpResponse::twig('display_team.html.twig', ['team' => $result]);
} }
public function addMember(array $request) : HttpResponse { public function addMember(array $request, SessionHandle $session): HttpResponse {
$errors = []; $errors = [];
$request = HttpRequest::from($request, $errors, [ $request = HttpRequest::from($request, $errors, [
"team" => [Validators::isInteger()], "team" => [Validators::isInteger()],
"mail" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"),Validators::lenBetween(5, 256)] "mail" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"), Validators::lenBetween(5, 256)]
]); ]);
return $this->getTeam($this->model->addMember($request['mail'], intval($request['team']), $request['role'])); return $this->displayTeam($this->model->addMember($request['mail'], intval($request['team']), $request['role']), $session);
} }
public function deleteMember(array $request) : HttpResponse { public function deleteMember(array $request, SessionHandle $session): HttpResponse {
$errors = []; $errors = [];
$request = HttpRequest::from($request, $errors, [ $request = HttpRequest::from($request, $errors, [
"team" => [Validators::isInteger()], "team" => [Validators::isInteger()],
"mail" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"),Validators::lenBetween(5, 256)] "mail" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"), Validators::lenBetween(5, 256)]
]); ]);
return $this->getTeam($this->model->deleteMember($request['mail'], intval($request['team']))); return $this->displayTeam($this->model->deleteMember($request['mail'], intval($request['team'])), $session);
} }
} }

@ -3,86 +3,38 @@
namespace App\Controller; namespace App\Controller;
use App\Connexion; use App\Connexion;
use App\Controller\Sub\EditorController;
use App\Gateway\TacticInfoGateway; use App\Gateway\TacticInfoGateway;
use App\Gateway\TeamGateway;
use App\Http\HttpResponse; use App\Http\HttpResponse;
use App\Http\ViewHttpResponse; use App\Http\ViewHttpResponse;
use App\Model\TacticModel; use App\Model\TacticModel;
use App\Model\TeamModel;
use App\Session\SessionHandle; use App\Session\SessionHandle;
class UserController extends VisitorController { class UserController {
public function home(): HttpResponse {
$model = new TacticModel(new TacticInfoGateway(new Connexion(get_database())));
$listTactic = $model->getLast(5);
return ViewHttpResponse::twig("home.twig", ["recentTactic" => $listTactic]);
}
public function settings(): HttpResponse {
return ViewHttpResponse::twig("account_settings.twig", []);
}
public function view(int $id, SessionHandle $session): HttpResponse {
$model = new TacticModel(new TacticInfoGateway(new Connexion(get_database())));
return (new Sub\VisualizerController($model))->visualize($id, $session);
}
public function edit(int $id, SessionHandle $session): HttpResponse {
$model = new TacticModel(new TacticInfoGateway(new Connexion(get_database())));
return (new EditorController($model))->edit($id, $session);
}
public function create(SessionHandle $session): HttpResponse { private TacticModel $tactics;
$model = new TacticModel(new TacticInfoGateway(new Connexion(get_database())));
return (new EditorController($model))->createNew($session);
}
public function open(int $id, SessionHandle $session): HttpResponse {
$model = new TacticModel(new TacticInfoGateway(new Connexion(get_database())));
return (new Sub\VisualizerController($model))->visualize($id, $session);
}
public function createTeam(): HttpResponse {
$model = new TeamModel(new TeamGateway(new Connexion(get_database())));
$ctrl = new Sub\TeamController($model);
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
return $ctrl->displaySubmitTeam();
}
return $ctrl->submitTeam($_POST);
}
public function listTeams(): HttpResponse { /**
$model = new TeamModel(new TeamGateway(new Connexion(get_database()))); * @param TacticModel $tactics
$ctrl = new Sub\TeamController($model); */
if ($_SERVER['REQUEST_METHOD'] === 'GET') { public function __construct(TacticModel $tactics) {
return $ctrl->displayListTeamByName(); $this->tactics = $tactics;
}
return $ctrl->listTeamByName($_POST);
} }
public function getTeam(int $id): HttpResponse { /**
$model = new TeamModel(new TeamGateway(new Connexion(get_database()))); * @param SessionHandle $session
$ctrl = new Sub\TeamController($model); * @return HttpResponse the home page
return $ctrl->getTeam($id); */
} public function home(SessionHandle $session): HttpResponse {
//TODO use session's account to get the last 5 tactics if the logged-in account
public function addMember(): HttpResponse { $listTactic = $this->tactics->getLast(5);
$model = new TeamModel(new TeamGateway(new Connexion(get_database()))); return ViewHttpResponse::twig("home.twig", ["recentTactic" => $listTactic]);
$ctrl = new Sub\TeamController($model);
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
return $ctrl->displayAddMember($_POST);
}
return $ctrl->addMember($_POST);
} }
public function deleteMember(): HttpResponse { /**
$model = new TeamModel(new TeamGateway(new Connexion(get_database()))); * @return HttpResponse account settings page
$ctrl = new Sub\TeamController($model); */
if ($_SERVER['REQUEST_METHOD'] === 'GET') { public function settings(SessionHandle $session): HttpResponse {
return $ctrl->displayDeleteMember($_POST); return ViewHttpResponse::twig("account_settings.twig", []);
}
return $ctrl->deleteMember($_POST);
} }
} }

@ -1,28 +0,0 @@
<?php
namespace App\Controller;
use App\Connexion;
use App\Gateway\AccountGateway;
use App\Http\HttpResponse;
use App\Model\AuthModel;
use App\Session\MutableSessionHandle;
class VisitorController {
final public function register(MutableSessionHandle $session): HttpResponse {
$model = new AuthModel(new AccountGateway(new Connexion(get_database())));
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
return (new Sub\AuthController($model))->displayRegister();
}
return (new Sub\AuthController($model))->confirmRegister($_POST, $session);
}
final public function login(MutableSessionHandle $session): HttpResponse {
$model = new AuthModel(new AccountGateway(new Connexion(get_database())));
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
return (new Sub\AuthController($model))->displayLogin();
}
return (new Sub\AuthController($model))->confirmLogin($_POST, $session);
}
}

@ -1,14 +1,12 @@
<?php <?php
namespace App\Controller\Sub; namespace App\Controller;
use App\Http\HttpCodes; use App\Http\HttpCodes;
use App\Http\HttpResponse; use App\Http\HttpResponse;
use App\Http\JsonHttpResponse;
use App\Http\ViewHttpResponse; use App\Http\ViewHttpResponse;
use App\Model\TacticModel; use App\Model\TacticModel;
use App\Session\SessionHandle; use App\Session\SessionHandle;
use App\Validation\ValidationFail;
use App\Validator\TacticValidator; use App\Validator\TacticValidator;
class VisualizerController { class VisualizerController {
@ -17,7 +15,6 @@ class VisualizerController {
/** /**
* @param TacticModel $tacticModel * @param TacticModel $tacticModel
*/ */
public function __construct(TacticModel $tacticModel) { public function __construct(TacticModel $tacticModel) {
$this->tacticModel = $tacticModel; $this->tacticModel = $tacticModel;
} }

@ -16,9 +16,6 @@ class Color {
*/ */
private function __construct(string $value) { private function __construct(string $value) {
if ($value < 0 || $value > 0xFFFFFF) {
throw new InvalidArgumentException("int color value is invalid, must be positive and lower than 0xFFFFFF");
}
$this->hex = $value; $this->hex = $value;
} }

@ -73,7 +73,7 @@
<div class="container"> <div class="container">
<h2>Ajouter un membre à votre équipe</h2> <h2>Ajouter un membre à votre équipe</h2>
<form action="/user/addMember" method="POST"> <form action="/team/members/add" method="POST">
<div class="form-group"> <div class="form-group">
<label for="team">Team où ajouter le membre :</label> <label for="team">Team où ajouter le membre :</label>
<input type="text" id="team" name="team" required> <input type="text" id="team" name="team" required>

@ -56,7 +56,7 @@
<div class="container"> <div class="container">
<h2>Supprimez un membre de votre équipe</h2> <h2>Supprimez un membre de votre équipe</h2>
<form action="/user/deleteMember" method="POST"> <form action="/team/members/remove" method="POST">
<div class="form-group"> <div class="form-group">
<label for="team">Team où supprimer le membre :</label> <label for="team">Team où supprimer le membre :</label>
<input type="text" id="team" name="team" required> <input type="text" id="team" name="team" required>

@ -10,7 +10,7 @@
<p>Aucune équipe n'a été trouvée</p> <p>Aucune équipe n'a été trouvée</p>
<div class="container"> <div class="container">
<h2>Chercher une équipe</h2> <h2>Chercher une équipe</h2>
<form action="/user/listTeams" method="post"> <form action="/team/search" method="post">
<div class="form-group"> <div class="form-group">
<label for="name">Nom de l'équipe :</label> <label for="name">Nom de l'équipe :</label>
<input type="text" id="name" name="name" required> <input type="text" id="name" name="name" required>
@ -22,7 +22,7 @@
</div> </div>
{% else %} {% else %}
{% for t in teams %} {% for t in teams %}
<div class="team" onclick="window.location.href = '/user/getTeam/{{ t.id }}'"> <div class="team" onclick="window.location.href = '/team/{{ t.id }}'">
<p>Nom de l'équipe : {{ t.name }}</p> <p>Nom de l'équipe : {{ t.name }}</p>
<img src="{{ t.picture }}" alt="logo de l'équipe"> <img src="{{ t.picture }}" alt="logo de l'équipe">
</div> </div>

@ -52,9 +52,9 @@
<body> <body>
<div id="bandeau"> <div id="bandeau">
<h1>IQ Ball</h1> <h1>IQ Ball</h1>
<div id="account" onclick="location.pathname='/user/settings'"> <div id="account" onclick="location.pathname='/settings'">
<img <img
src="img/welcomePage/account.svg" src="front/assets/icon/account.svg"
alt="Account logo" alt="Account logo"
/> />
<p>Mon profil<p> <p>Mon profil<p>
@ -63,7 +63,7 @@
<h2>Mes équipes</h2> <h2>Mes équipes</h2>
<button onclick="location.pathname='/user/createTeam'"> Créer une nouvelle équipe </button> <button onclick="location.pathname='/team/new'"> Créer une nouvelle équipe </button>
{% if recentTeam != null %} {% if recentTeam != null %}
{% for team in recentTeam %} {% for team in recentTeam %}
@ -77,13 +77,13 @@
<h2> Mes strategies </h2> <h2> Mes strategies </h2>
<button onclick="location.pathname='/user/create'"> Créer une nouvelle tactique </button> <button onclick="location.pathname='/tactic/new'"> Créer une nouvelle tactique </button>
{% if recentTactic != null %} {% if recentTactic != null %}
{% for tactic in recentTactic %} {% for tactic in recentTactic %}
<div onclick="location.pathname=/user/edit/{{ strategie.id }}"> <div onclick="location.pathname=/tactic/{{ strategie.id }}/edit">
<p> {{tactic.id}} - {{tactic.name}} - {{tactic.creation_date}} </p> <p> {{tactic.id}} - {{tactic.name}} - {{tactic.creation_date}} </p>
<button onclick="location.pathname='/user/edit/{{ tactic.id }}'"> Editer la stratégie {{tactic.id}} </button> <button onclick="location.pathname='/tactic/{{ tactic.id }}/edit'"> Editer la stratégie {{tactic.id}} </button>
</div> </div>
{% endfor %} {% endfor %}
{% else %} {% else %}

@ -64,7 +64,7 @@
<div class="container"> <div class="container">
<h2>Créer une équipe</h2> <h2>Créer une équipe</h2>
<form action="/user/createTeam" method="post"> <form action="/team/new" method="post">
<div class="form-group"> <div class="form-group">
<label for="name">Nom de l'équipe :</label> <label for="name">Nom de l'équipe :</label>
<input type="text" id="name" name="name" required> <input type="text" id="name" name="name" required>

@ -62,7 +62,7 @@
<div class="container"> <div class="container">
<h2>Chercher une équipe</h2> <h2>Chercher une équipe</h2>
<form action="/user/listTeams" method="post"> <form action="/team/search" method="post">
<div class="form-group"> <div class="form-group">
<label for="name">Nom de l'équipe :</label> <label for="name">Nom de l'équipe :</label>
<input type="text" id="name" name="name" required> <input type="text" id="name" name="name" required>

Loading…
Cancel
Save