/** * Destroy session variables that keep the user logged in. */ public function doLogOut() { if ($this->isAuthorized()) { $now = date("Y-m-d H:i:s"); $user = self::$_userId; file_put_contents("login.log", "{$now}: Logout detected for {$user}." . PHP_EOL, FILE_APPEND); } if (isset($_SESSION['auth_username'])) { unset($_SESSION['auth_username']); } if (isset($_SESSION['auth_password'])) { unset($_SESSION['auth_password']); } if (isset($_SESSION['auth_ticket'])) { $atm = new AuthTicketModel(); $atm->setAuthTicket($_SESSION['auth_ticket']); $atc = new AuthTicketController(); $atc->delete($atm); unset($_SESSION['auth_ticket']); } }
/** * Returns all auth_ticket records even those that have expired but not removed yet. * * @return AuthTicketModel[] * @throws ControllerException * @SuppressWarnings indentation */ public function getAll() { $models = array(); $sql = <<<SQL SELECT auth_ticket , created , updated , expires FROM auth_ticket ORDER BY expires DESC SQL; $stmt = $this->_dbh->prepare($sql); if (!$stmt) { throw new ControllerException('Failed to prepare SELECT statement. (' . $this->_dbh->error . ')'); } if (!$stmt->execute()) { throw new ControllerException('Failed to execute SELECT statement. (' . $this->_dbh->error . ')'); } $auth_ticket = $created = $updated = $expires = null; $stmt->bind_result($auth_ticket, $created, $updated, $expires); while ($stmt->fetch()) { $model = new AuthTicketModel(); $model->setAuthTicket($auth_ticket); $model->setCreated($created); $model->setUpdated($updated); $model->setExpires($expires); $models[] = $model; } return $models; }