From e038467a4b4e90231b9702974bf9f38dac6367fd Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Wed, 15 May 2024 21:42:24 -0400 Subject: [PATCH] Add some controllers and actions for user registration. --- code/src/Controller/Controller.php | 57 +++++++++++++++++++ .../Controller/User/RegisterUserAction.php | 14 +++++ code/src/Controller/User/RegisterUserPage.php | 14 +++++ code/src/Routes.php | 24 ++++++++ 4 files changed, 109 insertions(+) create mode 100644 code/src/Controller/Controller.php create mode 100644 code/src/Controller/User/RegisterUserAction.php create mode 100644 code/src/Controller/User/RegisterUserPage.php create mode 100644 code/src/Routes.php diff --git a/code/src/Controller/Controller.php b/code/src/Controller/Controller.php new file mode 100644 index 0000000..4fefc92 --- /dev/null +++ b/code/src/Controller/Controller.php @@ -0,0 +1,57 @@ +request = $request; + $this->response = $response; + $this->args = $args; + $this->routeContext = RouteContext::fromRequest($this->request); + + return $this->respond($request, $response); + } + + /** + * Implement this method for handling the request. + * + * @return Response + */ + abstract public function respond(): Response; + + /** + * Render the given Template. + * + * @param string $templateName The name of the template + * @param array $data The data for the template + * @return Response + */ + public function render(string $templateName, array $data = []): Response + { + $view = Twig::fromRequest($this->request); + return $view->render($this->response, $templateName, $data); + } +} diff --git a/code/src/Controller/User/RegisterUserAction.php b/code/src/Controller/User/RegisterUserAction.php new file mode 100644 index 0000000..5f3d3a6 --- /dev/null +++ b/code/src/Controller/User/RegisterUserAction.php @@ -0,0 +1,14 @@ +respond('user/register/success'); + } +} diff --git a/code/src/Controller/User/RegisterUserPage.php b/code/src/Controller/User/RegisterUserPage.php new file mode 100644 index 0000000..02f60ce --- /dev/null +++ b/code/src/Controller/User/RegisterUserPage.php @@ -0,0 +1,14 @@ +render('user/register'); + } +} diff --git a/code/src/Routes.php b/code/src/Routes.php new file mode 100644 index 0000000..fcd6c42 --- /dev/null +++ b/code/src/Routes.php @@ -0,0 +1,24 @@ +get('/users/register', RegisterUserPage::class); + $app->post('/users/register', RegisterUserAction::class); + } +}