diff --git a/app/db/migrations/20241122022752_add_time_stamps_to_users.php b/app/db/migrations/20241122022752_add_time_stamps_to_users.php index 9bf1904..a71793f 100644 --- a/app/db/migrations/20241122022752_add_time_stamps_to_users.php +++ b/app/db/migrations/20241122022752_add_time_stamps_to_users.php @@ -19,6 +19,7 @@ final class AddTimeStampsToUsers extends AbstractMigration */ public function change(): void { - + $table = $this->table("users")->addTimestamps(); + $table->update(); } } diff --git a/app/src/Controller/Controller.php b/app/src/Controller/Controller.php index 8b2ac0a..7b61c2e 100644 --- a/app/src/Controller/Controller.php +++ b/app/src/Controller/Controller.php @@ -58,6 +58,19 @@ abstract class Controller ->withHeader('Content-Type', 'text/html'); } + /** + * Redirect helper for sending the client elsewhere. + * + * @param string $route The route to redirect doe + * @param int $code Default `301`, the code to respond with + */ + public function redirect(string $route, int $code = 301): Response + { + return $this->response + ->withHeader('Location', $route) + ->withStatus($code); + } + /** * @param string $html The raw Twig HTML to render * @param array $data The data to injext into the HTML diff --git a/app/src/Controller/User/LoginUserAction.php b/app/src/Controller/User/LoginUserAction.php index 4e9a159..7735e83 100644 --- a/app/src/Controller/User/LoginUserAction.php +++ b/app/src/Controller/User/LoginUserAction.php @@ -35,6 +35,6 @@ class LoginUserAction extends Controller // start the session $this->session->set('user', [ 'id' => $user->getId(), 'authenticated' => true ]); - return $this->render('dashboard.twig', [ 'logged_in' => true ]); + return $this->redirect('/dashboard', 302); } }