Merge Wednesday Rush and remove Salva's imposed conception aberrations #22

Merged
maxime.batista merged 48 commits from salva into master 1 year ago

Merge the "salva" branch, that contains all the work from wednesday.
We made an alternative branch instead of merging directly to master in order to present the salva branch with the imposed route and controller conception.
This Pull request restores a more safer, simple to use and extensible router, and remove the controller heritages as it integrates very poorly in the application.

This pull request also had significant organization changes as the src folder
now contains Api, App and Core subdirs.

  • src/Api contains everything related with the Api, such as controllers.
  • src/App contains everything related with the App, such as controllers and twig views
  • src/Core contains the main project logic and definitions.

routes

before :

$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);

(absolutly hideous)

now:

    //authentication
    $ar->map("GET", "/login", AppAction::noAuth(fn() => getAuthController()->displayLogin()));
    $ar->map("GET", "/register", AppAction::noAuth(fn() => getAuthController()->displayRegister()));
    $ar->map("POST", "/login", AppAction::noAuth(fn(SessionHandle $s) => getAuthController()->confirmLogin($_POST, $s)));
    $ar->map("POST", "/register", AppAction::noAuth(fn(SessionHandle $s) => getAuthController()->confirmRegister($_POST, $s)));

    //user-related
    $ar->map("GET", "/home", AppAction::auth(fn(SessionHandle $s) => getUserController()->home($s)));
	... etc

(much better and efficient)

Merge the "salva" branch, that contains all the work from wednesday. We made an alternative branch instead of merging directly to master in order to present the salva branch with the imposed route and controller conception. This Pull request restores a more safer, simple to use and extensible router, and remove the controller heritages as it integrates very poorly in the application. This pull request also had significant organization changes as the `src` folder now contains `Api`, `App` and `Core` subdirs. * `src/Api` contains everything related with the Api, such as controllers. * `src/App` contains everything related with the App, such as controllers and twig views * `src/Core` contains the main project logic and definitions. ### routes before : ```php $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); ``` (absolutly hideous) now: ```php //authentication $ar->map("GET", "/login", AppAction::noAuth(fn() => getAuthController()->displayLogin())); $ar->map("GET", "/register", AppAction::noAuth(fn() => getAuthController()->displayRegister())); $ar->map("POST", "/login", AppAction::noAuth(fn(SessionHandle $s) => getAuthController()->confirmLogin($_POST, $s))); $ar->map("POST", "/register", AppAction::noAuth(fn(SessionHandle $s) => getAuthController()->confirmRegister($_POST, $s))); //user-related $ar->map("GET", "/home", AppAction::auth(fn(SessionHandle $s) => getUserController()->home($s))); ... etc ``` (much better and efficient)
maxime.batista added 44 commits 1 year ago
continuous-integration/drone/push Build is passing Details
5737bd6e6b
Add start of homepage and FrontControler (don't run it)
continuous-integration/drone/push Build is passing Details
ec47461703
wip FRONT CONTROLLER
continuous-integration/drone/push Build is passing Details
3422ef8780
Corrections conflicts
continuous-integration/drone/push Build is passing Details
61a6b5afd5
wip FrontController
continuous-integration/drone/push Build is failing Details
53584a518e
add salva-like routes and controller architecture
continuous-integration/drone/push Build is passing Details
14612226cd
fix on routes
continuous-integration/drone/push Build is passing Details
5d4bb84368
front-controller (#17)
continuous-integration/drone/push Build is failing Details
55c67cc484
Add a basic display of the tactics in the home page
continuous-integration/drone/push Build is failing Details
66410afa20
Test recentTeam empty in view
continuous-integration/drone/push Build is failing Details
e44ea4721e
Welcome Page done
continuous-integration/drone/push Build is failing Details
b489364cd2
delete css file
continuous-integration/drone/push Build is passing Details
e3875b4f15
add documentation
a11dd2e122
front-controller (#17)
continuous-integration/drone/push Build is failing Details
5b9096ab35
Correction CI
continuous-integration/drone/push Build is failing Details
88e547bfcb
Correction CI
continuous-integration/drone/push Build is passing Details
c696eafa38
Correction CI
continuous-integration/drone/push Build is passing Details
851aa72e2c
fix on routes
continuous-integration/drone/push Build is passing Details
ad4208e6da
fix format
continuous-integration/drone/push Build is passing Details
2b8b29d378
Merge branch 'salva' into session
continuous-integration/drone/push Build is passing Details
84a623ee6a
Merge pull request 'Add Session handling' (#19) from session into salva
continuous-integration/drone/push Build is passing Details
d54559e01d
fix
continuous-integration/drone/push Build is passing Details
28171b35e0
Adaptation welcome page
continuous-integration/drone/push Build is passing Details
19d2ed0199
Merging in progress
continuous-integration/drone/push Build is passing Details
3f15e85a72
Welcome page merged and adapted
continuous-integration/drone/push Build is failing Details
a020811518
team/addMembers (#21)
continuous-integration/drone/push Build is passing Details
34777e70df
Add settings
continuous-integration/drone/push Build is failing Details
704f1272f7
Add button
continuous-integration/drone/push Build is failing Details
36051ebd83
good routes, good controllers
maxime.batista changed title from Merge Yersteday Rush and remove Salva's conception aberrations to Merge Wednesday Rush and remove Salva's conception aberrations 1 year ago
maxime.batista changed title from Merge Wednesday Rush and remove Salva's conception aberrations to Merge Wednesday Rush and remove Salva's imposed conception aberrations 1 year ago
maxime.batista added 1 commit 1 year ago
continuous-integration/drone/push Build is passing Details
d20cfd2486
simplify actions, move ViewHttpResponse into src/App
mael.daim approved these changes 1 year ago
yanis.dahmane-bounoua requested changes 1 year ago
}
public function authorize(): HttpResponse {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
$this->model = $model;
}
public function updateName(int $tactic_id, Account $account): HttpResponse {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
src/App/App.php Outdated
}
}
private static function renderView(ViewHttpResponse $response): void {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
* @param ValidationFail[] $fails
* @return HttpResponse
*/
private function displayBadFields(string $viewName, array $fails): HttpResponse {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
* @param MutableSessionHandle $session
* @return HttpResponse
*/
public function confirmRegister(array $request, MutableSessionHandle $session): HttpResponse {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
$this->model = $model;
}
private function openEditor(TacticInfo $tactic): HttpResponse {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
return ViewHttpResponse::react("views/Editor.tsx", ["name" => $tactic->getName(), "id" => $tactic->getId()]);
}
public function createNew(SessionHandle $session): HttpResponse {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
$this->model = $model;
}
public function displayCreateTeam(SessionHandle $session): HttpResponse {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
}
public function displayAddMember(SessionHandle $session): HttpResponse {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
return ViewHttpResponse::twig("add_member.html.twig", []);
}
public function displayDeleteMember(SessionHandle $session): HttpResponse {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
* @param SessionHandle $session
* @return HttpResponse
*/
public function submitTeam(array $request, SessionHandle $session): HttpResponse {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
return $this->displayTeam($this->model->createTeam($request['name'], $request['picture'], $request['mainColor'], $request['secondColor']), $session);
}
public function displayListTeamByName(SessionHandle $session): HttpResponse {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
* @param array<string , mixed> $request
* @return HttpResponse
*/
public function listTeamByName(array $request, SessionHandle $session): HttpResponse {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
return ViewHttpResponse::twig('display_teams.html.twig', ['teams' => $results]);
}
public function displayTeam(int $id, SessionHandle $session): HttpResponse {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
* @param SessionHandle $session
* @return HttpResponse
*/
public function addMember(array $request, SessionHandle $session): HttpResponse {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
* @param SessionHandle $session
* @return HttpResponse
*/
public function deleteMember(array $request, SessionHandle $session): HttpResponse {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
* @param SessionHandle $session
* @return HttpResponse the home page
*/
public function home(SessionHandle $session): HttpResponse {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
/**
* @return HttpResponse account settings page
*/
public function settings(SessionHandle $session): HttpResponse {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
$this->tacticModel = $tacticModel;
}
public function visualize(int $id, SessionHandle $session): HttpResponse {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
* @param S $session
* @return HttpResponse
*/
public function run(array $params, $session): HttpResponse {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
* @param callable(mixed[], S): HttpResponse $action
* @return Action<S> an action that does not require to have an authorization.
*/
public static function noAuth(callable $action): Action {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
* @param callable(mixed[], S): HttpResponse $action
* @return Action<S> an action that does require to have an authorization.
*/
public static function auth(callable $action): Action {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
}
public function insertAccount(string $name, string $email, string $token, string $hash): int {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
}
public function getHash(string $email): ?string {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
return new Account($email, $acc["username"], $acc["token"], $acc["id"]);
}
public function getAccountFromToken(string $token): ?Account {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
$this->con = $con;
}
public function get(int $id): ?TacticInfo {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
return $res;
}
public function insert(string $name, int $owner): TacticInfo {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
return new TacticInfo(intval($row["id"]), $name, strtotime($row["creation_date"]), $row["owner"]);
}
public function updateName(int $id, string $name): void {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
$this->con = $con;
}
public function insert(string $name, string $picture, string $mainColor, string $secondColor): void {

needs some documentation here plz (

needs some documentation here plz (
maxime.batista marked this conversation as resolved
}
public function insertMember(int $idTeam, int $idMember, string $role): void {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
* @param string $name
* @return array<string, mixed>[]
*/
public function listByName(string $name): array {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
* @param int $id
* @return array<string,mixed>
*/
public function getTeamById(int $id): ?array {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
* @param string $name
* @return int|null
*/
public function getIdTeamByName(string $name): ?int {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
* @param int $id
* @return array<string,mixed>[]
*/
public function getMembersById(int $id): array {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
* @param string $mail
* @return int|null
*/
public function getMemberIdByMail(string $mail): ?int {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
)[0]['id'] ?? null;
}
public function deleteMember(int $idTeam, int $idMember): void {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
return $this->headers;
}
public static function fromCode(int $code): HttpResponse {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
return new HttpResponse($code, []);
}
public static function redirect(string $url, int $code = HttpCodes::FOUND): HttpResponse {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
* @param ValidationFail[] $failures
* @return Account|null the registered account or null if failures occurred
*/
public function register(string $username, string $password, string $confirmPassword, string $email, array &$failures): ?Account {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
* @param ValidationFail[] $failures
* @return Account|null the authenticated account or null if failures occurred
*/
public function login(string $email, string $password, array &$failures): ?Account {

needs some documentation here plz (little description)

needs some documentation here plz (little description)
maxime.batista marked this conversation as resolved
$this->tactics = $tactics;
}
public function makeNew(string $name, int $ownerId): TacticInfo {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
return $this->tactics->insert($name, $ownerId);
}
public function makeNewDefault(int $ownerId): ?TacticInfo {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
return new Team(intval($result['id']), $result['name'], $result['picture'], Color::from($result['mainColor']), Color::from($result['secondColor']), $members);
}
public function deleteMember(string $mail, int $teamId): int {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
return new ValidationFail("Not found", $message);
}
public static function unauthorized(string $message = "Unauthorized"): ValidationFail {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
use IQBall\Core\Validation\ValidationFail;
class TacticValidator {
public static function validateAccess(?TacticInfo $tactic, int $tacticId, int $ownerId): ?ValidationFail {

needs some documentation here plz

needs some documentation here plz
maxime.batista marked this conversation as resolved
clement.freville2 requested changes 1 year ago
clement.freville2 left a comment

maxou.dev is broken :/

[`maxou.dev`](https://maxou.dev/IQBall/salva/public/register) is broken :/
public function authorize(): HttpResponse {
return Control::runChecked([
"email" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"), Validators::lenBetween(5, 256)],

Don't invent your own email validation rules, use filter_var:

filter_var($ermail, FILTER_VALIDATE_EMAIL)
Don't invent your own email validation rules, use [`filter_var`](https://www.php.net/manual/fr/function.filter-var.php): ```php filter_var($ermail, FILTER_VALIDATE_EMAIL) ```
maxime.batista marked this conversation as resolved
if ($account == null) {
// put in the session the initial url the user wanted to get
$session->setInitialTarget($_SERVER['REQUEST_URI']);
return HttpResponse::redirect($basePath . "/login");

Note that the router can generate URIs, that already take care of the base path.

Note that the router can generate URIs, that already take care of the base path.
maxime.batista marked this conversation as resolved
public static function runMatch($match, MutableSessionHandle $session): HttpResponse {
if (!$match) {
return ViewHttpResponse::twig("error.html.twig", [
'failures' => [ValidationFail::notFound("Could not find page ${_SERVER['REQUEST_URI']}.")],
-                'failures' => [ValidationFail::notFound("Could not find page ${_SERVER['REQUEST_URI']}.")], 
+                'failures' => [ValidationFail::notFound("Could not find page {$_SERVER['REQUEST_URI']}.")], 

It is deprecated since PHP 8.2.

```diff - 'failures' => [ValidationFail::notFound("Could not find page ${_SERVER['REQUEST_URI']}.")], + 'failures' => [ValidationFail::notFound("Could not find page {$_SERVER['REQUEST_URI']}.")], ``` It is deprecated since [PHP 8.2](https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation).
maxime.batista marked this conversation as resolved
$request = HttpRequest::from($request, $errors, [
"team" => [Validators::isInteger()],
"mail" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"), Validators::lenBetween(5, 256)],

This is the third time this regex is repeated. Consider using filter_var and defining this elsewhere.

This is the third time this regex is repeated. Consider using `filter_var` and defining this elsewhere.
maxime.batista marked this conversation as resolved
samuel.berion added 2 commits 1 year ago
maxime.batista added 1 commit 1 year ago
continuous-integration/drone/push Build is passing Details
89c3e72c8f
add and edit documentation, clean code
maxime.batista merged commit 53b184afe0 into master 1 year ago
maxime.batista deleted branch salva 1 year ago

Reviewers

mael.daim approved these changes 1 year ago
yanis.dahmane-bounoua requested changes 1 year ago
clement.freville2 requested changes 1 year ago
continuous-integration/drone/push Build is passing
The pull request has been merged as 53b184afe0.
Sign in to join this conversation.
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: IQBall/Application-Web#22
Loading…
There is no content yet.