session = $session; $this->userDataCache = $userDataCache; $this->header = $header; } public function logInUser($email, $password) { $userData = $this->userDataCache->getUserByLogin($email, $password); if(!$userData) { return; } $this->session->set("isLoggedIn", true); $this->session->set("userId", $userData['user_id']); } public function logOutUser() { $this->session->unsetKey("userId"); $this->session->unsetKey("isLoggedIn"); } public function isLoggedIn() { return $this->session->getDefault("isLoggedIn", false) === true; } public function rejectIfNotAuthorized() { if($this->isLoggedIn()) { return; } $this->header->location("/"); } }