updated editor's mvc conception
continuous-integration/drone/push Build is passing Details

pull/93/head
Maël DAIM 1 year ago
parent e1056f4ade
commit f71835352d

@ -64,7 +64,7 @@ et de reporter le plus d'erreurs possibles lorsqu'une requête ne valide pas le
public function doPostAction(array $form): HttpResponse { public function doPostAction(array $form): HttpResponse {
$failures = []; $failures = [];
$req = HttpRequest::from($form, $failures, [ $req = HttpRequest::from($form, $failures, [
'email' => [Validators::email(), Validators::isLenBetween(6, 64)] 'email' => [DefaultValidators::email(), DefaultValidators::isLenBetween(6, 64)]
]); ]);
if (!empty($failures)) { //ou $req == null if (!empty($failures)) { //ou $req == null

@ -35,4 +35,10 @@ class TacticInfoGateway{
TacticInfoGateway *--"- con" Connexion TacticInfoGateway *--"- con" Connexion
class TacticValidator{
+ validateAccess(tacticId:int, tactic:?TacticInfo, ownerId:int): ?ValidationFail {static}
}
EditorController ..> TacticValidator
@enduml @enduml

@ -53,7 +53,7 @@ class Validation {
Validation ..> Validator Validation ..> Validator
class Validators { class DefaultValidators {
+ <u>nonEmpty(): Validator + <u>nonEmpty(): Validator
+ <u>shorterThan(limit: int): Validator + <u>shorterThan(limit: int): Validator
+ <u>userString(maxLen: int): Validator + <u>userString(maxLen: int): Validator
@ -68,7 +68,7 @@ class Validators {
+ <u>isURL(): Validator + <u>isURL(): Validator
} }
Validators ..> Validator DefaultValidators ..> Validator

@ -8,7 +8,7 @@ use IQBall\Core\Http\HttpRequest;
use IQBall\Core\Http\HttpResponse; use IQBall\Core\Http\HttpResponse;
use IQBall\Core\Http\JsonHttpResponse; use IQBall\Core\Http\JsonHttpResponse;
use IQBall\Core\Model\AuthModel; use IQBall\Core\Model\AuthModel;
use IQBall\Core\Validation\Validators; use IQBall\Core\Validation\DefaultValidators;
class APIAuthController { class APIAuthController {
private AuthModel $model; private AuthModel $model;
@ -27,8 +27,8 @@ class APIAuthController {
*/ */
public function authorize(): HttpResponse { public function authorize(): HttpResponse {
return Control::runChecked([ return Control::runChecked([
"email" => [Validators::email(), Validators::lenBetween(5, 256)], "email" => [DefaultValidators::email(), DefaultValidators::lenBetween(5, 256)],
"password" => [Validators::lenBetween(6, 256)], "password" => [DefaultValidators::lenBetween(6, 256)],
], function (HttpRequest $req) { ], function (HttpRequest $req) {
$failures = []; $failures = [];
$account = $this->model->login($req["email"], $req["password"], $failures); $account = $this->model->login($req["email"], $req["password"], $failures);

@ -10,7 +10,7 @@ use IQBall\Core\Http\HttpResponse;
use IQBall\Core\Http\JsonHttpResponse; use IQBall\Core\Http\JsonHttpResponse;
use IQBall\Core\Model\TacticModel; use IQBall\Core\Model\TacticModel;
use IQBall\Core\Validation\FieldValidationFail; use IQBall\Core\Validation\FieldValidationFail;
use IQBall\Core\Validation\Validators; use IQBall\Core\Validation\DefaultValidators;
/** /**
* API endpoint related to tactics * API endpoint related to tactics
@ -33,7 +33,7 @@ class APITacticController {
*/ */
public function updateName(int $tactic_id, Account $account): HttpResponse { public function updateName(int $tactic_id, Account $account): HttpResponse {
return Control::runChecked([ return Control::runChecked([
"name" => [Validators::lenBetween(1, 50), Validators::nameWithSpaces()], "name" => [DefaultValidators::lenBetween(1, 50), DefaultValidators::nameWithSpaces()],
], function (HttpRequest $request) use ($tactic_id, $account) { ], function (HttpRequest $request) use ($tactic_id, $account) {
$failures = $this->model->updateName($tactic_id, $request["name"], $account->getUser()->getId()); $failures = $this->model->updateName($tactic_id, $request["name"], $account->getUser()->getId());

@ -11,7 +11,7 @@ use IQBall\Core\Validation\Validator;
class Control { class Control {
/** /**
* Runs given callback, if the request's json validates the given schema. * Runs given callback, if the request's json validates the given schema.
* @param array<string, Validator[]> $schema an array of `fieldName => Validators` which represents the request object schema * @param array<string, Validator[]> $schema an array of `fieldName => DefaultValidators` which represents the request object schema
* @param callable(HttpRequest): HttpResponse $run the callback to run if the request is valid according to the given schema. * @param callable(HttpRequest): HttpResponse $run the callback to run if the request is valid according to the given schema.
* THe callback must accept an HttpRequest, and return an HttpResponse object. * THe callback must accept an HttpRequest, and return an HttpResponse object.
* @return HttpResponse * @return HttpResponse
@ -30,7 +30,7 @@ class Control {
/** /**
* Runs given callback, if the given request data array validates the given schema. * Runs given callback, if the given request data array validates the given schema.
* @param array<string, mixed> $data the request's data array. * @param array<string, mixed> $data the request's data array.
* @param array<string, Validator[]> $schema an array of `fieldName => Validators` which represents the request object schema * @param array<string, Validator[]> $schema an array of `fieldName => DefaultValidators` which represents the request object schema
* @param callable(HttpRequest): HttpResponse $run the callback to run if the request is valid according to the given schema. * @param callable(HttpRequest): HttpResponse $run the callback to run if the request is valid according to the given schema.
* THe callback must accept an HttpRequest, and return an HttpResponse object. * THe callback must accept an HttpRequest, and return an HttpResponse object.
* @return HttpResponse * @return HttpResponse

@ -7,7 +7,7 @@ use IQBall\App\ViewHttpResponse;
use IQBall\Core\Http\HttpRequest; use IQBall\Core\Http\HttpRequest;
use IQBall\Core\Http\HttpResponse; use IQBall\Core\Http\HttpResponse;
use IQBall\Core\Model\AuthModel; use IQBall\Core\Model\AuthModel;
use IQBall\Core\Validation\Validators; use IQBall\Core\Validation\DefaultValidators;
class AuthController { class AuthController {
private AuthModel $model; private AuthModel $model;
@ -32,10 +32,10 @@ class AuthController {
public function register(array $request, MutableSessionHandle $session): HttpResponse { public function register(array $request, MutableSessionHandle $session): HttpResponse {
$fails = []; $fails = [];
$request = HttpRequest::from($request, $fails, [ $request = HttpRequest::from($request, $fails, [
"username" => [Validators::name(), Validators::lenBetween(2, 32)], "username" => [DefaultValidators::name(), DefaultValidators::lenBetween(2, 32)],
"password" => [Validators::lenBetween(6, 256)], "password" => [DefaultValidators::lenBetween(6, 256)],
"confirmpassword" => [Validators::lenBetween(6, 256)], "confirmpassword" => [DefaultValidators::lenBetween(6, 256)],
"email" => [Validators::email(), Validators::lenBetween(5, 256)], "email" => [DefaultValidators::email(), DefaultValidators::lenBetween(5, 256)],
]); ]);
if (!empty($fails)) { if (!empty($fails)) {
return ViewHttpResponse::twig("display_register.html.twig", ['fails' => $fails]); return ViewHttpResponse::twig("display_register.html.twig", ['fails' => $fails]);

@ -11,7 +11,7 @@ use IQBall\Core\Http\HttpResponse;
use IQBall\Core\Model\TeamModel; use IQBall\Core\Model\TeamModel;
use IQBall\Core\Validation\FieldValidationFail; use IQBall\Core\Validation\FieldValidationFail;
use IQBall\Core\Validation\ValidationFail; use IQBall\Core\Validation\ValidationFail;
use IQBall\Core\Validation\Validators; use IQBall\Core\Validation\DefaultValidators;
class TeamController { class TeamController {
private TeamModel $model; private TeamModel $model;
@ -48,10 +48,10 @@ class TeamController {
public function submitTeam(array $request, SessionHandle $session): HttpResponse { public function submitTeam(array $request, SessionHandle $session): HttpResponse {
$failures = []; $failures = [];
$request = HttpRequest::from($request, $failures, [ $request = HttpRequest::from($request, $failures, [
"name" => [Validators::lenBetween(1, 32), Validators::nameWithSpaces()], "name" => [DefaultValidators::lenBetween(1, 32), DefaultValidators::nameWithSpaces()],
"main_color" => [Validators::hexColor()], "main_color" => [DefaultValidators::hexColor()],
"second_color" => [Validators::hexColor()], "second_color" => [DefaultValidators::hexColor()],
"picture" => [Validators::isURL()], "picture" => [DefaultValidators::isURL()],
]); ]);
if (!empty($failures)) { if (!empty($failures)) {
$badFields = []; $badFields = [];
@ -84,7 +84,7 @@ class TeamController {
public function listTeamByName(array $request, SessionHandle $session): 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" => [DefaultValidators::lenBetween(1, 32), DefaultValidators::nameWithSpaces()],
]); ]);
if (!empty($errors) && $errors[0] instanceof FieldValidationFail) { if (!empty($errors) && $errors[0] instanceof FieldValidationFail) {
@ -166,7 +166,7 @@ class TeamController {
], HttpCodes::FORBIDDEN); ], HttpCodes::FORBIDDEN);
} }
$request = HttpRequest::from($request, $errors, [ $request = HttpRequest::from($request, $errors, [
"email" => [Validators::email(), Validators::lenBetween(5, 256)], "email" => [DefaultValidators::email(), DefaultValidators::lenBetween(5, 256)],
]); ]);
if(!empty($errors)) { if(!empty($errors)) {
return ViewHttpResponse::twig('add_member.html.twig', ['badEmail' => true,'idTeam' => $idTeam]); return ViewHttpResponse::twig('add_member.html.twig', ['badEmail' => true,'idTeam' => $idTeam]);
@ -226,10 +226,10 @@ class TeamController {
} }
$failures = []; $failures = [];
$request = HttpRequest::from($request, $failures, [ $request = HttpRequest::from($request, $failures, [
"name" => [Validators::lenBetween(1, 32), Validators::nameWithSpaces()], "name" => [DefaultValidators::lenBetween(1, 32), DefaultValidators::nameWithSpaces()],
"main_color" => [Validators::hexColor()], "main_color" => [DefaultValidators::hexColor()],
"second_color" => [Validators::hexColor()], "second_color" => [DefaultValidators::hexColor()],
"picture" => [Validators::isURL()], "picture" => [DefaultValidators::isURL()],
]); ]);
if (!empty($failures)) { if (!empty($failures)) {
$badFields = []; $badFields = [];

@ -5,7 +5,7 @@ namespace IQBall\Core\Validation;
/** /**
* A collection of standard validators * A collection of standard validators
*/ */
class Validators { class DefaultValidators {
/** /**
* @return Validator a validator that validates a given regex * @return Validator a validator that validates a given regex
*/ */
Loading…
Cancel
Save