From f3f36b333c570faac1334cdcd8a2cfc5661266ba Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Thu, 23 May 2024 22:39:38 -0400 Subject: [PATCH] Add success page. --- app/src/Bootstrap.php | 20 +++++++++++-- .../Controller/User/RegisterUserAction.php | 4 ++- app/src/Domain/Repository/UserRepository.php | 28 +++++++++++++++++++ .../Repository/UserRepositoryInterface.php | 1 + app/templates/layouts/skeleton.twig | 1 + app/templates/users/success.twig | 7 +++++ 6 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 app/templates/users/success.twig diff --git a/app/src/Bootstrap.php b/app/src/Bootstrap.php index 81e49d7..a2d97cd 100644 --- a/app/src/Bootstrap.php +++ b/app/src/Bootstrap.php @@ -24,6 +24,13 @@ class Bootstrap // set all configuration details + $config->merge([ + 'site' => [ + 'name' => "Slovocast", + 'description' => "A no-bullshit podcast hosting platform." + ], + ]); + return $config; } @@ -39,8 +46,9 @@ class Bootstrap $config = self::initConfig(); $containerBuilder->addDefinitions([ - 'conifg' => $config, + 'config' => $config, // more DI stuff + ]); return $containerBuilder->build(); @@ -66,6 +74,10 @@ class Bootstrap */ protected static function establishMiddleware(App $app): void { + /** + * @var Configuration + */ + $config = $app->get('config'); $app->addErrorMiddleware(true, true, true); // Twig @@ -73,8 +85,10 @@ class Bootstrap $templateCache = false; $twig = Twig::create($templatePath, [ 'cache' => $templateCache ]); // Add the global variables - $twig->getEnvironment()->addGlobal('site_name', "Slovocast"); - $twig->getEnvironment()->addGlobal('site_description', "A no-bullshit podcast hosting service"); + $twig->getEnvironment() + ->addGlobal('site_name', $config->get('site.name')); + $twig->getEnvironment() + ->addGlobal('site_description', $config->get('site.description')); $app->add(TwigMiddleware::create($app, $twig)); } diff --git a/app/src/Controller/User/RegisterUserAction.php b/app/src/Controller/User/RegisterUserAction.php index 5286942..2c72c24 100644 --- a/app/src/Controller/User/RegisterUserAction.php +++ b/app/src/Controller/User/RegisterUserAction.php @@ -9,6 +9,8 @@ class RegisterUserAction extends Controller { public function respond(): Response { - return $this->respond('users/register/success.twig'); + // get user Data + + return $this->render('user/success.twig'); } } diff --git a/app/src/Domain/Repository/UserRepository.php b/app/src/Domain/Repository/UserRepository.php index 704a6bd..bb8d91e 100644 --- a/app/src/Domain/Repository/UserRepository.php +++ b/app/src/Domain/Repository/UserRepository.php @@ -93,6 +93,34 @@ class UserRepository implements UserRepositoryInterface public function update(User $user): bool { + $connection = $this->database->getConnection(); + $query = "UPDATE users + SET email = :email, + name = :name, + password = :password + WHERE id = :id"; + $statement = $connection->prepare($query); + return $statement->execute([ + 'email' => $user->getEmail(), + 'name' => $user->getName(), + 'password' => $this->userAuth->hash($user->getPassword()), + 'id' => $user->getId() + ]); + } + + /** + * @param string $email + * @param string $password + * @return bool + */ + public function verifyPassword(string $email, string $password): bool + { + try { + $user = $this->getFromEmail($email); + return $this->authUser->verify($password, $user->getPassword()); + } catch (\Exception $e) { + return false; + } } } diff --git a/app/src/Domain/Repository/UserRepositoryInterface.php b/app/src/Domain/Repository/UserRepositoryInterface.php index e01503e..81152d9 100644 --- a/app/src/Domain/Repository/UserRepositoryInterface.php +++ b/app/src/Domain/Repository/UserRepositoryInterface.php @@ -10,4 +10,5 @@ interface UserRepositoryInterface public function getFromEmail(string $email): User; public function save(User $user): bool; public function update(User $user): bool; + public function verifyPassword(string $email, string $password): bool; } diff --git a/app/templates/layouts/skeleton.twig b/app/templates/layouts/skeleton.twig index 4e617e8..10961d2 100644 --- a/app/templates/layouts/skeleton.twig +++ b/app/templates/layouts/skeleton.twig @@ -2,6 +2,7 @@ {% block page_title %}{% endblock %} +
diff --git a/app/templates/users/success.twig b/app/templates/users/success.twig new file mode 100644 index 0000000..f8d7ff1 --- /dev/null +++ b/app/templates/users/success.twig @@ -0,0 +1,7 @@ +{% extends 'layouts/skeleton.twig' %} + +{% block content %} +
+

Successfully registered {{ email }}.

+
+{% endblock %}