Example #1
0
 /**
  * Checks whether the user is logged in.
  *
  * @return UserRow|bool Object if user is logged in, false otherwise.
  */
 public function isLoggedIn()
 {
     // If user object is not in cache, but user ID is in session,
     // load the object from the database:
     if (!$this->currentUser) {
         if (isset($this->session->userId)) {
             // normal mode
             $results = $this->userTable->select(['id' => $this->session->userId]);
             $this->currentUser = count($results) < 1 ? false : $results->current();
         } else {
             if (isset($this->session->userDetails)) {
                 // privacy mode
                 $results = $this->userTable->createRow();
                 $results->exchangeArray($this->session->userDetails);
                 $this->currentUser = $results;
             } else {
                 // unexpected state
                 $this->currentUser = false;
             }
         }
     }
     return $this->currentUser;
 }