Пример #1
0
 private function login($sUserName, $sPassword)
 {
     if ($this->oConfig->get('demoMode') && $sUserName == 'demo' && $sPassword == 'demo' || $this->oUser->loginLdap($sUserName, $sPassword)) {
         return [self::RESPONSE_SUCCESS => true, self::RESPONSE_TOKEN => $this->oUser->generateToken(sha1($sUserName . $sPassword))];
     }
     return [self::RESPONSE_SUCCESS => false];
 }
Пример #2
0
 /**
  *
  * @return array
  */
 public function getCharacterList()
 {
     /**
      * @var Character
      */
     $oCharacter = new Character();
     $aSchema = $oCharacter->getSchema();
     if ($oDb = new \SQLite3($this->oConfig->get('sqlite.file'), SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE)) {
         foreach ($aSchema as $sTableName => $aTable) {
             $oQuery = @$oDb->query(sprintf('SELECT * FROM %s;', $sTableName));
             if ($oQuery === false) {
                 // got no chars or database error, handle individually
                 return [];
             }
             $aChars = [];
             while ($aChar = $oQuery->fetchArray(SQLITE3_ASSOC)) {
                 array_push($aChars, $aChar);
             }
             return $aChars;
         }
     }
     return [];
 }
Пример #3
0
 /**
  *
  * @todo: save/update or insert
  * @todo: map types from schema on SqlData to automatically cast types / add quotes / prepare
  *
  * @return boolean
  */
 public function save()
 {
     $aSchema = $this->getSchema();
     $aSqlData = $this->getSqlData();
     // @refactor: write code more readble -> this functional stuff is quite hard to understand
     foreach ($aSchema as $sTableName => $aTable) {
         if ($oDb = new \SQLite3($this->oConfig->get('sqlite.file'), SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE)) {
             $sSqlStatement = sprintf('INSERT INTO %s (%s) VALUES (%s)', $sTableName, implode(",", array_map(function (DbColumn $oColumn) {
                 return $oColumn->getName();
             }, $aTable)), implode(",", array_map(function (DbColumn $oColumn) use($aSqlData) {
                 // @todo: validation if column has data in input array
                 return "'" . $aSqlData[$oColumn->getName()] . "'";
             }, $aTable)));
             if (!$oDb->query($sSqlStatement)) {
                 throw new \RuntimeException(sprintf("could not insert into table %s\n\nStatement: %s", $sTableName, $sSqlStatement));
             }
         }
     }
     return true;
 }