Merge Wednesday Rush and remove Salva's imposed conception aberrations #22
Merged
maxime.batista
merged 48 commits from salva
into master
1 year ago
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'salva'
Deleting a branch is permanent. It CANNOT be undone. Continue?
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
foldernow contains
Api
,App
andCore
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 viewssrc/Core
contains the main project logic and definitions.routes
before :
(absolutly hideous)
now:
(much better and efficient)
Merge Yersteday Rush and remove Salva's conception aberrationsto Merge Wednesday Rush and remove Salva's conception aberrations 1 year agoMerge Wednesday Rush and remove Salva's conception aberrationsto Merge Wednesday Rush and remove Salva's imposed conception aberrations 1 year ago}
public function authorize(): HttpResponse {
needs some documentation here plz
$this->model = $model;
}
public function updateName(int $tactic_id, Account $account): HttpResponse {
needs some documentation here plz
}
}
private static function renderView(ViewHttpResponse $response): void {
needs some documentation here plz
* @param ValidationFail[] $fails
* @return HttpResponse
*/
private function displayBadFields(string $viewName, array $fails): HttpResponse {
needs some documentation here plz (little description)
* @param MutableSessionHandle $session
* @return HttpResponse
*/
public function confirmRegister(array $request, MutableSessionHandle $session): HttpResponse {
needs some documentation here plz
$this->model = $model;
}
private function openEditor(TacticInfo $tactic): HttpResponse {
needs some documentation here plz
return ViewHttpResponse::react("views/Editor.tsx", ["name" => $tactic->getName(), "id" => $tactic->getId()]);
}
public function createNew(SessionHandle $session): HttpResponse {
needs some documentation here plz
$this->model = $model;
}
public function displayCreateTeam(SessionHandle $session): HttpResponse {
needs some documentation here plz
}
public function displayAddMember(SessionHandle $session): HttpResponse {
needs some documentation here plz
return ViewHttpResponse::twig("add_member.html.twig", []);
}
public function displayDeleteMember(SessionHandle $session): HttpResponse {
needs some documentation here plz
* @param SessionHandle $session
* @return HttpResponse
*/
public function submitTeam(array $request, SessionHandle $session): HttpResponse {
needs some documentation here plz (little description)
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
* @param array<string , mixed> $request
* @return HttpResponse
*/
public function listTeamByName(array $request, SessionHandle $session): HttpResponse {
needs some documentation here plz (little description)
return ViewHttpResponse::twig('display_teams.html.twig', ['teams' => $results]);
}
public function displayTeam(int $id, SessionHandle $session): HttpResponse {
needs some documentation here plz
* @param SessionHandle $session
* @return HttpResponse
*/
public function addMember(array $request, SessionHandle $session): HttpResponse {
needs some documentation here plz (little description)
* @param SessionHandle $session
* @return HttpResponse
*/
public function deleteMember(array $request, SessionHandle $session): HttpResponse {
needs some documentation here plz (little description)
* @param SessionHandle $session
* @return HttpResponse the home page
*/
public function home(SessionHandle $session): HttpResponse {
needs some documentation here plz (little description)
/**
* @return HttpResponse account settings page
*/
public function settings(SessionHandle $session): HttpResponse {
needs some documentation here plz (little description)
$this->tacticModel = $tacticModel;
}
public function visualize(int $id, SessionHandle $session): HttpResponse {
needs some documentation here plz (little description)
* @param S $session
* @return HttpResponse
*/
public function run(array $params, $session): HttpResponse {
needs some documentation here plz (little description)
* @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)
* @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)
}
public function insertAccount(string $name, string $email, string $token, string $hash): int {
needs some documentation here plz
}
public function getHash(string $email): ?string {
needs some documentation here plz
return new Account($email, $acc["username"], $acc["token"], $acc["id"]);
}
public function getAccountFromToken(string $token): ?Account {
needs some documentation here plz
$this->con = $con;
}
public function get(int $id): ?TacticInfo {
needs some documentation here plz
return $res;
}
public function insert(string $name, int $owner): TacticInfo {
needs some documentation here plz
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
$this->con = $con;
}
public function insert(string $name, string $picture, string $mainColor, string $secondColor): void {
needs some documentation here plz (
}
public function insertMember(int $idTeam, int $idMember, string $role): void {
needs some documentation here plz
* @param string $name
* @return array<string, mixed>[]
*/
public function listByName(string $name): array {
needs some documentation here plz (little description)
* @param int $id
* @return array<string,mixed>
*/
public function getTeamById(int $id): ?array {
needs some documentation here plz (little description)
* @param string $name
* @return int|null
*/
public function getIdTeamByName(string $name): ?int {
needs some documentation here plz (little description)
* @param int $id
* @return array<string,mixed>[]
*/
public function getMembersById(int $id): array {
needs some documentation here plz (little description)
* @param string $mail
* @return int|null
*/
public function getMemberIdByMail(string $mail): ?int {
needs some documentation here plz (little description)
)[0]['id'] ?? null;
}
public function deleteMember(int $idTeam, int $idMember): void {
needs some documentation here plz (little description)
return $this->headers;
}
public static function fromCode(int $code): HttpResponse {
needs some documentation here plz
return new HttpResponse($code, []);
}
public static function redirect(string $url, int $code = HttpCodes::FOUND): HttpResponse {
needs some documentation here plz
* @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)
* @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)
$this->tactics = $tactics;
}
public function makeNew(string $name, int $ownerId): TacticInfo {
needs some documentation here plz
return $this->tactics->insert($name, $ownerId);
}
public function makeNewDefault(int $ownerId): ?TacticInfo {
needs some documentation here plz
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
return new ValidationFail("Not found", $message);
}
public static function unauthorized(string $message = "Unauthorized"): ValidationFail {
needs some documentation here plz
use IQBall\Core\Validation\ValidationFail;
class TacticValidator {
public static function validateAccess(?TacticInfo $tactic, int $tacticId, int $ownerId): ?ValidationFail {
needs some documentation here plz
maxou.dev
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
: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.
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']}.")],
It is deprecated since PHP 8.2.
$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.53b184afe0
into master 1 year agoReviewers
53b184afe0
.