parent
3d7eb7bbb1
commit
982acf5e09
@ -0,0 +1,30 @@
|
|||||||
|
<?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 {
|
||||||
|
|
||||||
|
|
||||||
|
public final 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final 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,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Gateway;
|
|
||||||
|
|
||||||
use PDO;
|
|
||||||
use App\Connexion;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A sample gateway, that stores the sample form's result.
|
|
||||||
*/
|
|
||||||
class FormResultGateway {
|
|
||||||
private Connexion $con;
|
|
||||||
|
|
||||||
public function __construct(Connexion $con) {
|
|
||||||
$this->con = $con;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function insert(string $username, string $description): void {
|
|
||||||
$this->con->exec(
|
|
||||||
"INSERT INTO FormEntries VALUES (:name, :description)",
|
|
||||||
[
|
|
||||||
":name" => [$username, PDO::PARAM_STR],
|
|
||||||
"description" => [$description, PDO::PARAM_STR],
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function listResults(): array {
|
|
||||||
return $this->con->fetch("SELECT * FROM FormEntries", []);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Validator;
|
||||||
|
|
||||||
|
use App\Data\TacticInfo;
|
||||||
|
use App\Validation\ValidationFail;
|
||||||
|
|
||||||
|
class TacticValidator {
|
||||||
|
|
||||||
|
public static function validateAccess(?TacticInfo $tactic, int $ownerId): ?ValidationFail {
|
||||||
|
if ($tactic == null) {
|
||||||
|
return ValidationFail::notFound("La tactique " . $tactic->getId() . " n'existe pas");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($tactic->getOwnerId() != $ownerId) {
|
||||||
|
return new ValidationFail("Unauthorized", "Vous ne pouvez pas accéder à cette tactique.",);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue