Add timestamps to teh user since its also an entity, and test the login. Add a redirect helper for the responses.

This commit is contained in:
Dave Smith-Hayes 2024-11-21 21:44:18 -05:00
parent aab1138163
commit 38cdd1bfb2
3 changed files with 16 additions and 2 deletions

View File

@ -19,6 +19,7 @@ final class AddTimeStampsToUsers extends AbstractMigration
*/
public function change(): void
{
$table = $this->table("users")->addTimestamps();
$table->update();
}
}

View File

@ -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

View File

@ -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);
}
}