function beforeroute(){
// Check for logged-in user
if($this->f3->get('SESSION.email') === null ) {
$this->f3->reroute('/login');
exit;
}
}
This is in my UserController.php
function authenticate() {
// Get POST data
$email = $this->f3->get('POST.email');
$password = $this->f3->get('POST.password');
// Load the user from the DB via their Email
$user = new User($this->db);
$user->getByemail($email);
// Check if any records were found, if not redirect.
if($user->dry()) {
$this->f3->reroute('/login');
}
// At this point the user was found, check password and proceed.
if(password_verify($password, $user->password)) {
$this->f3->set('SESSION.email', $user->email);
$this->f3->reroute('/');
} else {
$this->f3->reroute('/login');
}
}
And this is in my index.php (although, if I remove this line, the sessions work and the session file lands where php.ini says it should. I have not been able to get it into /tmp/cfg at all, due to the error noted above when I call New Session(); )
// Start Session
new Session();
// Run it!
$f3->run();
I'm also curious if I should be calling session_regenerate_id() at all to prevent fixation, as a best practice after login?