diff --git a/config.php b/config.php
index fdf02a4..697927a 100644
--- a/config.php
+++ b/config.php
@@ -20,4 +20,4 @@ function asset(string $assetURI): string {
global $_data_source_name;
$data_source_name = $_data_source_name;
const DATABASE_USER = _DATABASE_USER;
-const DATABASE_PASSWORD = _DATABASE_PASSWORD;
+const DATABASE_PASSWORD = _DATABASE_PASSWORD;
\ No newline at end of file
diff --git a/front/views/Settings.tsx b/front/views/Settings.tsx
index 2bd53aa..f4c1115 100644
--- a/front/views/Settings.tsx
+++ b/front/views/Settings.tsx
@@ -4,38 +4,38 @@ import {Header} from './template/Header'
import { useState, ChangeEvent } from "react"
import { User } from "./model/User"
-export default function Settings({username} : {username : string}){
+export default function Settings({user} : {user : User}){
return (
-
-
+
+
)
}
-function Body() {
+function Body({user} : {user : User}) {
return (
)
}
-function AccountSettings(){
+function AccountSettings({user} : {user : User}){
return (
-
+
);
}
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.name);
// Fonction pour mettre à jour l'état lorsqu'il y a un changement dans le champ de saisie
const handleUsernameChange = (event : ChangeEvent) => {
diff --git a/public/api/index.php b/public/api/index.php
index da25013..94532d7 100644
--- a/public/api/index.php
+++ b/public/api/index.php
@@ -32,7 +32,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", "/user/username/[name]", Action::auth(fn(string $username, Account $acc) => getUserController()->))
return $router;
}
diff --git a/src/Api/Controller/APIUserController.php b/src/Api/Controller/APIUserController.php
new file mode 100644
index 0000000..3477122
--- /dev/null
+++ b/src/Api/Controller/APIUserController.php
@@ -0,0 +1,20 @@
+model = $model;
+ }
+
+ public function changeUsername(Account $acc, string $newUsername,) {
+ $this->model->changeUsername($acc->getUser()->getId(), $newUsername);
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/src/App/Controller/UserController.php b/src/App/Controller/UserController.php
index 6f56128..b9f0ad2 100644
--- a/src/App/Controller/UserController.php
+++ b/src/App/Controller/UserController.php
@@ -54,7 +54,9 @@ 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 {
diff --git a/src/Core/Gateway/AccountGateway.php b/src/Core/Gateway/AccountGateway.php
index a9c3e18..561cabd 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 function changeUsername(int $id, string $username) {
+ $this->con->exec("UPDATE Account SET username = :username WHERE id = :id", [":username" => [$username, PDO::PARAM_STR], ":id" => [$id, PDO::PARAM_INT]]);
+ }
+
}
diff --git a/src/Core/Model/AuthModel.php b/src/Core/Model/AuthModel.php
index bc29248..22351b1 100644
--- a/src/Core/Model/AuthModel.php
+++ b/src/Core/Model/AuthModel.php
@@ -74,4 +74,8 @@ class AuthModel {
return $this->gateway->getAccountFromMail($email);
}
+ public function changeUsername(int $id, string $newUsername) {
+ $this->gateway->changeUsername($id, $newUsername);
+ }
+
}