);
}
function ContentAccountSettings({user} : {user : User}) {
// Utilisez useState pour gérer l'état du champ de saisie
- const [username, setUsername] = useState({user.username});
+ // const [username, setUsername] = useState({user.username});
- // Fonction pour mettre à jour l'état lorsqu'il y a un changement dans le champ de saisie
- const handleUsernameChange = (event : ChangeEvent) => {
- setUsername(event.target.value);
- };
+ // // Fonction pour mettre à jour l'état lorsqu'il y a un changement dans le champ de saisie
+ // const handleUsernameChange = (event : ChangeEvent) => {
+ // setUsername(event.target.value);
+ // };
+
+ // return (
+ //
+ // );
return (
-
+
+
+ Nom d'utilisateur
+
+
+
+ Adresse mail
+
+
+
+
+
+
);
}
diff --git a/front/views/model/User.tsx b/front/views/model/User.tsx
index 36bbb67..ff4c757 100644
--- a/front/views/model/User.tsx
+++ b/front/views/model/User.tsx
@@ -3,4 +3,4 @@ export interface User {
name: string
email: string
profilePicture: string
-}
+}
\ No newline at end of file
diff --git a/package.json b/package.json
index 1380d59..f831e60 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,9 @@
"@types/node": "^16.18.59",
"@types/react": "^18.2.31",
"@types/react-dom": "^18.2.14",
+ "bootstrap": "^5.3.2",
"react": "^18.2.0",
+ "react-bootstrap": "^2.10.0",
"react-dom": "^18.2.0",
"react-draggable": "^4.4.6",
"typescript": "^5.2.2",
diff --git a/public/api/index.php b/public/api/index.php
index da25013..0331ca8 100644
--- a/public/api/index.php
+++ b/public/api/index.php
@@ -8,6 +8,7 @@ require "../../src/index-utils.php";
use IQBall\Api\API;
use IQBall\Api\Controller\APIAuthController;
use IQBall\Api\Controller\APITacticController;
+use IQBall\Api\Controller\APIUserController;
use IQBall\App\Session\PhpSessionHandle;
use IQBall\Core\Action;
use IQBall\Core\Connection;
@@ -25,6 +26,10 @@ function getAuthController(): APIAuthController {
return new APIAuthController(new AuthModel(new AccountGateway(new Connection(get_database()))));
}
+function getAPIUserController(): APIUserController {
+ return new APIUserController(new AuthModel(new AccountGateway(new Connection(get_database()))));
+}
+
function getRoutes(): AltoRouter {
$router = new AltoRouter();
$router->setBasePath(get_public_path(__DIR__));
@@ -32,6 +37,7 @@ function getRoutes(): AltoRouter {
$router->map("POST", "/auth", Action::noAuth(fn() => getAuthController()->authorize()));
$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]/save", Action::auth(fn(int $id, Account $acc) => getTacticController()->saveContent($id, $acc)));
+ $router->map("POST", "/update/profil", Action::auth(fn(Account $acc) => getAPIUserController()->updateProfil($acc)));
return $router;
}
diff --git a/public/index.php b/public/index.php
index 82dd37f..beae9b7 100644
--- a/public/index.php
+++ b/public/index.php
@@ -85,8 +85,7 @@ function getRoutes(): AltoRouter {
$ar->map("GET", "/home", Action::auth(fn(SessionHandle $s) => getUserController()->home($s)));
$ar->map("GET", "/settings", Action::auth(fn(SessionHandle $s) => getUserController()->settings($s)));
$ar->map("GET", "/disconnect", Action::auth(fn(MutableSessionHandle $s) => getUserController()->disconnect($s)));
-
-
+
//tactic-related
$ar->map("GET", "/tactic/[i:id]/view", Action::auth(fn(int $id, SessionHandle $s) => getVisualizerController()->openVisualizer($id, $s)));
$ar->map("GET", "/tactic/[i:id]/edit", Action::auth(fn(int $id, SessionHandle $s) => getEditorController()->openEditor($id, $s)));
@@ -109,7 +108,6 @@ function getRoutes(): AltoRouter {
$ar->map("GET", "/team/[i:id]/edit", Action::auth(fn(int $idTeam, SessionHandle $s) => getTeamController()->displayEditTeam($idTeam, $s)));
$ar->map("POST", "/team/[i:id]/edit", Action::auth(fn(int $idTeam, SessionHandle $s) => getTeamController()->editTeam($idTeam, $_POST, $s)));
-
return $ar;
}
diff --git a/sql/setup-tables.sql b/sql/setup-tables.sql
index 0d157d9..5e8c155 100644
--- a/sql/setup-tables.sql
+++ b/sql/setup-tables.sql
@@ -49,4 +49,4 @@ CREATE TABLE Member
role text CHECK (role IN ('COACH', 'PLAYER')) NOT NULL,
FOREIGN KEY (id_team) REFERENCES Team (id),
FOREIGN KEY (id_user) REFERENCES Account (id)
-);
+);
\ No newline at end of file
diff --git a/src/Api/Controller/APIUserController.php b/src/Api/Controller/APIUserController.php
new file mode 100644
index 0000000..a117122
--- /dev/null
+++ b/src/Api/Controller/APIUserController.php
@@ -0,0 +1,49 @@
+model = $model;
+ }
+
+ /**
+ * @param Account $account
+ * @return HttpResponse
+ */
+ public function updateProfil(Account $account): HttpResponse {
+ return Control::runChecked([
+ "username" => [Validators::name()],
+ "email" => [Validators::email()]
+ ], function (HttpRequest $request) use ($account) {
+
+ $failures = $this->model->updateProfil($request["username"], $request["email"], $account->getUser()->getId());
+
+ if (!empty($failures)) {
+ //TODO find a system to handle Unauthorized error codes more easily from failures.
+ return new JsonHttpResponse($failures, HttpCodes::BAD_REQUEST);
+ }
+
+ return HttpResponse::fromCode(HttpCodes::OK);
+ });
+ }
+}
diff --git a/src/App/Controller/EditorController.php b/src/App/Controller/EditorController.php
index 4bdcfae..293ef7c 100644
--- a/src/App/Controller/EditorController.php
+++ b/src/App/Controller/EditorController.php
@@ -84,4 +84,4 @@ class EditorController {
return $this->openEditorFor($tactic);
}
-}
+}
\ No newline at end of file
diff --git a/src/App/Controller/UserController.php b/src/App/Controller/UserController.php
index 6f56128..650e56b 100644
--- a/src/App/Controller/UserController.php
+++ b/src/App/Controller/UserController.php
@@ -13,7 +13,6 @@ class UserController {
private TacticModel $tactics;
private ?TeamModel $teams;
-
/**
* @param TacticModel $tactics
* @param TeamModel|null $teams
@@ -54,12 +53,13 @@ class UserController {
* @return ViewHttpResponse account settings page
*/
public function settings(SessionHandle $session): ViewHttpResponse {
- return ViewHttpResponse::react("views/Settings.tsx", []);
+ return ViewHttpResponse::react("views/Settings.tsx", [
+ "user" => $session->getAccount()->getUser()
+ ]);
}
public function disconnect(MutableSessionHandle $session): HttpResponse {
$session->destroy();
return HttpResponse::redirect("/");
}
-
-}
+}
\ No newline at end of file
diff --git a/src/Core/Gateway/AccountGateway.php b/src/Core/Gateway/AccountGateway.php
index a9c3e18..02350b1 100644
--- a/src/Core/Gateway/AccountGateway.php
+++ b/src/Core/Gateway/AccountGateway.php
@@ -82,5 +82,9 @@ class AccountGateway {
return new Account($acc["token"], new User($acc["email"], $acc["username"], $acc["id"], $acc["profilePicture"]));
}
+ public void updateProfil() {
+
+ }
+
}
diff --git a/src/Core/Model/AuthModel.php b/src/Core/Model/AuthModel.php
index bc29248..ff45af8 100644
--- a/src/Core/Model/AuthModel.php
+++ b/src/Core/Model/AuthModel.php
@@ -6,6 +6,7 @@ use Exception;
use IQBall\Core\Data\Account;
use IQBall\Core\Data\User;
use IQBall\Core\Gateway\AccountGateway;
+use IQBall\Core\Http\HttpResponse;
use IQBall\Core\Validation\FieldValidationFail;
use IQBall\Core\Validation\ValidationFail;
@@ -50,6 +51,10 @@ class AuthModel {
return new Account($token, new User($email, $username, $accountId, self::DEFAULT_PROFILE_PICTURE));
}
+ public function updateProfil(string $username, string $mail, Account $account) {
+ $gateway->
+ }
+
/**
* Generate a random base 64 string
* @return string