From d58f61770463aab2c71464c11f902f0074b49b62 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Mon, 15 Jan 2024 15:50:43 +0100 Subject: http catch-up --- src/http/Controller/User.php | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/http/Controller/User.php (limited to 'src/http/Controller/User.php') diff --git a/src/http/Controller/User.php b/src/http/Controller/User.php new file mode 100644 index 0000000..c47e32e --- /dev/null +++ b/src/http/Controller/User.php @@ -0,0 +1,57 @@ + $_SESSION['user']['id']])->fetch(); + + return new Response(View::render('account.twig', [ + 'user' => $user, + ])); + } + #[Route(path: '/account', methods: ['POST'])] + public function accountSave(Request $request): Response + { + $username = $request->get('username'); + $email = $request->get('email'); + + if ($request->get('password')) { + $password = password_hash($request->get('password'), PASSWORD_DEFAULT); + DB::query( + 'update users set username=:username, email=:email, password=:password where id=:id', + [ + 'username' => $username, + 'email' => $email, + 'password' => $password, + 'id' => $_SESSION['user']['id'], + ] + ); + } else { + DB::query( + 'update users set username=:username, email=:email where id=:id', + [ + 'username' => $username, + 'email' => $email, + 'id' => $_SESSION['user']['id'], + ] + ); + } + + $_SESSION['user']['username'] = $request->get('username'); + + + return new RedirectResponse(Router::generate('user.account')); + } +} -- cgit v1.2.3