Esempio n. 1
0
 /**
  * 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']);
     }
 }
Esempio n. 2
0
 /**
  * Get rid of an AuthTicket - usually at logout.
  *
  * @param AuthTicketModel $model
  * @throws ControllerException
  */
 public function delete($model)
 {
     $authTicket = $model->getAuthTicket();
     $sql = "DELETE FROM auth_ticket" . " WHERE auth_ticket = ?";
     $stmt = $this->_dbh->prepare($sql);
     if (!$stmt) {
         throw new ControllerException('Prepared statement failed for ' . $sql);
     }
     if (!$stmt->bind_param('s', $authTicket)) {
         throw new ControllerException('Binding parameters for prepared statement failed.');
     }
     if (!$stmt->execute()) {
         throw new ControllerException('Failed to execute DELETE statement. (' . $this->_dbh->error . ')');
     }
     /**
      * @SuppressWarnings checkAliases
      */
     if (!$stmt->close()) {
         throw new ControllerException('Something broke while trying to close the prepared statement.');
     }
     return;
 }