diff --git a/front/views/Editor.tsx b/front/views/Editor.tsx index cbb2da5..28e88c8 100644 --- a/front/views/Editor.tsx +++ b/front/views/Editor.tsx @@ -116,7 +116,6 @@ function EditorView({ courtType, }: EditorViewProps) { const isInGuestMode = id == -1 - const [titleStyle, setTitleStyle] = useState({}) const [content, setContent, saveState] = useContentState( initialContent, diff --git a/front/views/Settings.tsx b/front/views/Settings.tsx index f4c1115..29d6546 100644 --- a/front/views/Settings.tsx +++ b/front/views/Settings.tsx @@ -49,6 +49,7 @@ function ContentAccountSettings({user} : {user : User}) { {/* Utilisez la valeur de l'état et la fonction onChange */}
+ ); } diff --git a/public/api/index.php b/public/api/index.php index 94532d7..57f18be 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,7 +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", "/user/username/[name]", Action::auth(fn(string $username, Account $acc) => getUserController()->)) + $router->map("POST", "/user/username", Action::auth(fn(Account $acc) => getAPIUserController()->changeUsername($acc))); return $router; } diff --git a/src/Api/Controller/APIUserController.php b/src/Api/Controller/APIUserController.php index 3477122..9894f85 100644 --- a/src/Api/Controller/APIUserController.php +++ b/src/Api/Controller/APIUserController.php @@ -2,8 +2,13 @@ namespace IQBall\Api\Controller; +use IQBall\App\Control; use IQBall\Core\Model\AuthModel; use IQBall\Core\Data\Account; +use IQBall\Core\Http\HttpCodes; +use IQBall\Core\Http\HttpRequest; +use IQBall\Core\Http\HttpResponse; +use IQBall\Core\Validation\Validators; class APIUserController { private AuthModel $model; @@ -12,8 +17,14 @@ class APIUserController { $this->model = $model; } - public function changeUsername(Account $acc, string $newUsername,) { - $this->model->changeUsername($acc->getUser()->getId(), $newUsername); + public function changeUsername(Account $acc) { + return Control::runChecked([ + "username" => [Validators::name()] + ], function(HttpRequest $request) use ($acc) { + $this->model->changeUsername($acc->getUser()->getId(), $request["username"]); + + return HttpResponse::fromCode(HttpCodes::OK); + }); } }