Example #1
0
 /**
  * search user/corporation or alliance by name
  * @param $f3
  * @param $params
  */
 public function search($f3, $params)
 {
     $accessData = [];
     if (array_key_exists('arg1', $params) && array_key_exists('arg2', $params)) {
         $searchType = strtolower($params['arg1']);
         $searchToken = strtolower($params['arg2']);
         $accessModel = null;
         switch ($searchType) {
             case 'user':
                 $accessModel = Model\BasicModel::getNew('UserModel');
                 break;
             case 'corporation':
                 $accessModel = Model\BasicModel::getNew('CorporationModel');
                 break;
             case 'alliance':
                 $accessModel = Model\BasicModel::getNew('AllianceModel');
                 break;
         }
         if (is_object($accessModel)) {
             // find "active" entries that have their "sharing" option activated
             $accessList = $accessModel->find(array("LOWER(name) LIKE :token AND " . "active = 1 AND " . "shared = 1 ", ':token' => '%' . $searchToken . '%'));
             if ($accessList) {
                 foreach ($accessList as $accessObject) {
                     $accessData[] = $accessObject->getData();
                 }
             }
         }
     }
     echo json_encode($accessData);
 }
 /**
  * overwrites parent
  * @param null $db
  * @param null $table
  * @param null $fields
  * @return bool
  */
 public static function setup($db = null, $table = null, $fields = null)
 {
     $status = parent::setup($db, $table, $fields);
     if ($status === true) {
         $status = parent::setMultiColumnIndex(['corporationId', 'mapId'], true);
     }
     return $status;
 }
 /**
  * overwrites parent
  * @param null $db
  * @param null $table
  * @param null $fields
  * @return bool
  */
 public static function setup($db = null, $table = null, $fields = null)
 {
     $status = parent::setup($db, $table, $fields);
     if ($status === true) {
         $status = parent::setMultiColumnIndex(['systemId', 'typeId', 'groupId']);
     }
     return $status;
 }
Example #4
0
 /**
  * overwrites parent
  * @param null $db
  * @param null $table
  * @param null $fields
  * @return bool
  */
 public static function setup($db = null, $table = null, $fields = null)
 {
     $status = parent::setup($db, $table, $fields);
     // set static default values
     if ($status === true) {
         $model = self::getNew(self::getClassName(), 0);
         $model->importStaticData(self::$tableData);
     }
     return $status;
 }
Example #5
0
 /**
  * see parent
  */
 public function clearCacheData()
 {
     parent::clearCacheData();
     // delete log cache key as well
     $f3 = self::getF3();
     $character = $this->characterId;
     $character->clearCacheData();
     $f3->clear('LOGGED.user.character.id_' . $character->id);
     return true;
 }
Example #6
0
 public function delete($f3)
 {
     $connectionIds = $f3->get('POST.connectionIds');
     $user = $this->_getUser();
     $connection = Model\BasicModel::getNew('ConnectionModel');
     foreach ($connectionIds as $connectionId) {
         $connection->getById($connectionId);
         $connection->delete($user);
         $connection->reset();
     }
     echo json_encode([]);
 }
Example #7
0
 /**
  * delete all character log data
  * >> php index.php "/cron/deleteLogData"
  * @param $f3
  */
 function deleteLogData($f3)
 {
     $characterLogModel = Model\BasicModel::getNew('CharacterLogModel');
     // find "old" character logs
     $characterLogs = $characterLogModel->find(['TIMESTAMPDIFF(SECOND, updated, NOW() ) > :lifetime', ':lifetime' => (int) $f3->get('PATHFINDER.CACHE.CHARACTER_LOG')]);
     if (is_object($characterLogs)) {
         foreach ($characterLogs as $characterLog) {
             // delete log and all cached values
             $characterLog->erase();
         }
     }
 }
Example #8
0
 /**
  * delete expired character authentication data
  * authentication data is used for cookie based login
  * >> php index.php "/cron/deleteAuthenticationData"
  * @param $f3
  */
 function deleteAuthenticationData($f3)
 {
     DB\Database::instance()->getDB('PF');
     /**
      * @var $authenticationModel Model\CharacterAuthenticationModel
      */
     $authenticationModel = Model\BasicModel::getNew('CharacterAuthenticationModel', 0);
     // find expired authentication data
     $authentications = $authenticationModel->find(['(expires - NOW()) <= 0']);
     if (is_object($authentications)) {
         foreach ($authentications as $authentication) {
             $authentication->erase();
         }
     }
 }
Example #9
0
 /**
  * delete a map and all dependencies
  * @param $f3
  */
 public function delete($f3)
 {
     $mapData = (array) $f3->get('POST.mapData');
     $user = $this->_getUser();
     if ($user) {
         $map = Model\BasicModel::getNew('MapModel');
         $map->getById($mapData['id']);
         $map->delete($user);
     }
     echo json_encode([]);
 }
Example #10
0
 /**
  * delete a map and all dependencies
  * @param \Base $f3
  */
 public function delete(\Base $f3)
 {
     $mapData = (array) $f3->get('POST.mapData');
     $activeCharacter = $this->getCharacter();
     /**
      * @var $map Model\MapModel
      */
     $map = Model\BasicModel::getNew('MapModel');
     $map->getById($mapData['id']);
     $map->delete($activeCharacter);
     echo json_encode([]);
 }
Example #11
0
 /**
  * delete connection
  * @param \Base $f3
  * @throws \Exception
  */
 public function delete(\Base $f3)
 {
     $connectionIds = $f3->get('POST.connectionIds');
     $activeCharacter = $this->getCharacter();
     /**
      * @var Model\ConnectionModel $connection
      */
     $connection = Model\BasicModel::getNew('ConnectionModel');
     foreach ($connectionIds as $connectionId) {
         $connection->getById($connectionId);
         $connection->delete($activeCharacter);
         $connection->reset();
     }
     echo json_encode([]);
 }
Example #12
0
 /**
  * get current character model
  * @param int $ttl
  * @return Model\CharacterModel|null
  * @throws \Exception
  */
 public function getCharacter($ttl = 0)
 {
     $character = null;
     if ($this->getF3()->exists(Api\User::SESSION_KEY_CHARACTER_ID)) {
         $characterId = (int) $this->getF3()->get(Api\User::SESSION_KEY_CHARACTER_ID);
         if ($characterId) {
             /**
              * @var $characterModel Model\CharacterModel
              */
             $characterModel = Model\BasicModel::getNew('CharacterModel');
             $characterModel->getById($characterId, $ttl);
             if (!$characterModel->dry() && $characterModel->hasUserCharacter()) {
                 $character =& $characterModel;
             }
         }
     }
     return $character;
 }
Example #13
0
 /**
  * delete systems and all its connections from map
  * -> set "active" flag
  * @param \Base $f3
  */
 public function delete(\Base $f3)
 {
     $systemIds = (array) $f3->get('POST.systemIds');
     $activeCharacter = $this->getCharacter();
     /**
      * @var Model\SystemModel $system
      */
     $system = Model\BasicModel::getNew('SystemModel');
     foreach ($systemIds as $systemId) {
         $system->getById($systemId);
         if ($system->hasAccess($activeCharacter)) {
             $system->setActive(false);
             $system->save();
             $system->reset();
         }
     }
     echo json_encode([]);
 }
Example #14
0
 /**
  * update all character information for a given apiModel
  * @param $userApiModel
  * @return int
  * @throws \Exception
  */
 public function updateCharacters($userApiModel)
 {
     $xml = $this->requestCharacters($userApiModel->keyId, $userApiModel->vCode);
     $characterCount = 0;
     // important -> user API model must be up2date
     // if not -> matched userCharacter cant be found
     $userApiModel->getById($userApiModel->id, 0);
     if ($xml) {
         // request successful
         $rowApiData = $xml->result->key->rowset;
         if (is_object($rowApiData) && $rowApiData->children()) {
             $characterModel = Model\BasicModel::getNew('CharacterModel');
             $corporationModel = Model\BasicModel::getNew('CorporationModel');
             $allianceModel = Model\BasicModel::getNew('AllianceModel');
             foreach ($rowApiData->children() as $characterApiData) {
                 // map attributes to array
                 $attributeData = current($characterApiData->attributes());
                 $newCharacter = true;
                 $characterId = (int) $attributeData['characterID'];
                 $characterModel->getById($characterId);
                 // check if corporation already exists
                 if ($attributeData['corporationID'] > 0) {
                     $corporationModel->getById($attributeData['corporationID']);
                     if ($corporationModel->dry()) {
                         $corporationModel->id = $attributeData['corporationID'];
                         $corporationModel->name = $attributeData['corporationName'];
                         $corporationModel->save();
                     }
                     $corporationModelTemp = $corporationModel;
                 }
                 // check if alliance already exists
                 if ($attributeData['allianceID'] > 0) {
                     $allianceModel->getById($attributeData['allianceID']);
                     if ($allianceModel->dry()) {
                         $allianceModel->id = $attributeData['allianceID'];
                         $allianceModel->name = $attributeData['allianceName'];
                         $allianceModel->save();
                     }
                     $allianceModelTemp = $allianceModel;
                 }
                 if ($userApiModel->userCharacters) {
                     $userApiModel->userCharacters->rewind();
                     while ($userApiModel->userCharacters->valid()) {
                         $tempCharacterModel = $userApiModel->userCharacters->current()->getCharacter();
                         // character already exists -> update
                         if ($tempCharacterModel->id == $characterId) {
                             $characterModel = $tempCharacterModel;
                             // unset userCharacter -> all leftover models are no longer part of this API
                             // --> delete leftover models at the end
                             $userApiModel->userCharacters->offsetUnset($userApiModel->userCharacters->key());
                             $newCharacter = false;
                             break;
                         } else {
                             $userApiModel->userCharacters->next();
                         }
                     }
                     $userApiModel->userCharacters->rewind();
                 }
                 $characterModel->id = $characterId;
                 $characterModel->name = $attributeData['characterName'];
                 $characterModel->corporationId = $corporationModelTemp;
                 $characterModel->allianceId = $allianceModelTemp;
                 $characterModel->factionId = $attributeData['factionID'];
                 $characterModel->factionName = $attributeData['factionName'];
                 $characterModel->save();
                 if ($newCharacter) {
                     // new character for this API
                     $userCharactersModel = Model\BasicModel::getNew('UserCharacterModel', 0);
                     $userCharactersModel->userId = $userApiModel->userId;
                     $userCharactersModel->apiId = $userApiModel;
                     $userCharactersModel->characterId = $characterModel;
                     $userCharactersModel->save();
                 }
                 $corporationModel->reset();
                 $allianceModel->reset();
                 $characterModel->reset();
                 $characterCount++;
             }
         }
         // delete leftover userCharacters from this API
         if (count($userApiModel->userCharacters) > 0) {
             while ($userApiModel->userCharacters->valid()) {
                 $userApiModel->userCharacters->current()->erase();
                 $userApiModel->userCharacters->next();
             }
         }
     }
     return $characterCount;
 }
Example #15
0
 /**
  * send mail with registration key
  * -> check INVITE in pathfinder.ini
  * @param $f3
  * @throws Exception
  */
 public function sendInvite($f3)
 {
     $data = $f3->get('POST.settingsData');
     $return = (object) [];
     // check invite limit
     // get handed out key count
     $tempRegistrationKeyModel = Model\BasicModel::getNew('RegistrationKeyModel');
     $tempRegistrationKeyModels = $tempRegistrationKeyModel->find(['
         email != "" AND
         active = 1']);
     $totalKeys = 0;
     if (is_object($tempRegistrationKeyModels)) {
         $totalKeys = $tempRegistrationKeyModels->count();
     }
     if ($f3->get('PATHFINDER.REGISTRATION.INVITE') == 1 && $totalKeys < $f3->get('PATHFINDER.REGISTRATION.INVITE_LIMIT')) {
         // key limit not reached
         if (isset($data['email']) && !empty($data['email'])) {
             $email = trim($data['email']);
             // check if mail is valid
             if (\Audit::instance()->email($email)) {
                 // new key for this mail is allowed
                 $registrationKeyModel = $this->findRegistrationKey($email, 0);
                 if ($registrationKeyModel === false) {
                     // check for total number of invites (active and inactive) -> prevent spamming
                     $allRegistrationKeysByMail = $this->findRegistrationKey($email);
                     if ($allRegistrationKeysByMail == false || $allRegistrationKeysByMail->count() < 3) {
                         // get a fresh key
                         $registrationKeyModel = Model\BasicModel::getNew('RegistrationKeyModel');
                         $registrationKeyModel->load(['
                             used = 0 AND
                             active = 1 AND
                             email = "" ', ':email' => $email], ['limit' => 1]);
                     } else {
                         $validationError = (object) [];
                         $validationError->type = 'warning';
                         $validationError->message = 'The number of keys is limited by Email. You can not get more keys';
                         $return->error[] = $validationError;
                     }
                 } else {
                     $registrationKeyModel = $registrationKeyModel[0];
                 }
                 // send "old" key again or send a new key
                 if (is_object($registrationKeyModel)) {
                     $msg = 'Your personal Registration Key: ' . $registrationKeyModel->registrationKey;
                     $mailController = new MailController();
                     $status = $mailController->sendInviteKey($email, $msg);
                     if ($status) {
                         $registrationKeyModel->email = $email;
                         $registrationKeyModel->ip = $this->f3->get('IP');
                         $registrationKeyModel->save();
                     }
                 }
             } else {
                 $validationError = (object) [];
                 $validationError->type = 'error';
                 $validationError->field = 'email';
                 $validationError->message = 'Email is not valid';
                 $return->error[] = $validationError;
             }
         }
     } else {
         $validationError = (object) [];
         $validationError->type = 'warning';
         $validationError->message = 'The pool of beta keys has been exhausted, please try again in a few days/weeks';
         $return->error[] = $validationError;
     }
     echo json_encode($return);
 }
Example #16
0
 /**
  * update character
  * @param $characterData
  * @return \Model\CharacterModel
  * @throws \Exception
  */
 protected function updateCharacter($characterData)
 {
     $characterModel = null;
     $corporationModel = null;
     $allianceModel = null;
     if (isset($characterData->corporation)) {
         /**
          * @var Model\CorporationModel $corporationModel
          */
         $corporationModel = Model\BasicModel::getNew('CorporationModel');
         $corporationModel->getById($characterData->corporation['id'], 0);
         $corporationModel->copyfrom($characterData->corporation);
         $corporationModel->save();
     }
     if (isset($characterData->alliance)) {
         /**
          * @var Model\AllianceModel $allianceModel
          */
         $allianceModel = Model\BasicModel::getNew('AllianceModel');
         $allianceModel->getById($characterData->alliance['id'], 0);
         $allianceModel->copyfrom($characterData->alliance);
         $allianceModel->save();
     }
     if (isset($characterData->character)) {
         /**
          * @var Model\CharacterModel $characterModel
          */
         $characterModel = Model\BasicModel::getNew('CharacterModel');
         $characterModel->getById($characterData->character['id'], 0);
         $characterModel->copyfrom($characterData->character);
         $characterModel->corporationId = $corporationModel;
         $characterModel->allianceId = $allianceModel;
         $characterModel = $characterModel->save();
     }
     return $characterModel;
 }
Example #17
0
 /**
  * search multiple route between two systems
  * @param \Base $f3
  */
 public function search($f3)
 {
     $requestData = (array) $f3->get('POST');
     $activeCharacter = $this->getCharacter();
     $return = (object) [];
     $return->error = [];
     $return->routesData = [];
     if (!empty($requestData['routeData'])) {
         $routesData = (array) $requestData['routeData'];
         //  map data where access was already checked -> cached data
         $validMaps = [];
         /**
          * @var $map Model\MapModel
          */
         $map = Model\BasicModel::getNew('MapModel');
         foreach ($routesData as $key => $routeData) {
             // mapIds are optional. If mapIds is empty or not set
             // route search is limited to CCPs static data
             $mapData = (array) $routeData['mapIds'];
             $mapData = array_flip(array_map('intval', $mapData));
             // check map access (filter requested mapIDs and format) --------------------
             array_walk($mapData, function (&$item, &$key, $data) {
                 if (isset($data[1][$key])) {
                     // character has mas access -> do not check again
                     $item = $data[1][$key];
                 } else {
                     // check map access for current character
                     $data[0]->getById($key);
                     if ($data[0]->hasAccess($data[2])) {
                         $item = ['id' => $key, 'name' => $data[0]->name];
                     } else {
                         $item = false;
                     }
                     $data[0]->reset();
                 }
             }, [$map, $validMaps, $activeCharacter]);
             // filter maps with NO access right
             $mapData = array_filter($mapData);
             $mapIds = array_column($mapData, 'id');
             // add map data to cache array
             $validMaps += $mapData;
             // search route with filter options
             $filterData = ['stargates' => (bool) $routeData['stargates'], 'jumpbridges' => (bool) $routeData['jumpbridges'], 'wormholes' => (bool) $routeData['wormholes'], 'wormholesReduced' => (bool) $routeData['wormholesReduced'], 'wormholesCritical' => (bool) $routeData['wormholesCritical']];
             $returnRoutData = ['systemFromData' => $routeData['systemFromData'], 'systemToData' => $routeData['systemToData'], 'maps' => $mapData, 'mapIds' => $mapIds];
             // add filter options for each route as well
             $returnRoutData += $filterData;
             if (count($mapIds) > 0) {
                 $systemFrom = $routeData['systemFromData']['name'];
                 $systemTo = $routeData['systemToData']['name'];
                 $cacheKey = $this->getRouteCacheKey($mapIds, $systemFrom, $systemTo, $filterData);
                 if ($f3->exists($cacheKey)) {
                     // get data from cache
                     $returnRoutData = $f3->get($cacheKey);
                 } else {
                     // max search depth for search
                     $searchDepth = $f3->get('PATHFINDER.ROUTE.SEARCH_DEPTH');
                     // set jump data for following route search
                     $this->initJumpData($mapIds, $filterData);
                     // no cached route data found
                     $foundRoutData = $this->findRoute($systemFrom, $systemTo, $searchDepth);
                     $returnRoutData = array_merge($returnRoutData, $foundRoutData);
                     // cache if route was found
                     if (isset($returnRoutData['routePossible']) && $returnRoutData['routePossible'] === true) {
                         $f3->set($cacheKey, $returnRoutData, $this->dynamicJumpDataCacheTime);
                     }
                 }
             }
             $return->routesData[] = $returnRoutData;
         }
     }
     echo json_encode($return);
 }
Example #18
0
 /**
  * overwrites parent
  * @param null $db
  * @param null $table
  * @param null $fields
  * @return bool
  */
 public static function setup($db = null, $table = null, $fields = null)
 {
     $status = parent::setup($db, $table, $fields);
     if ($status === true) {
         $status = parent::setMultiColumnIndex(['source', 'target', 'scope']);
     }
     return $status;
 }
Example #19
0
 /**
  * verifies weather a given username and password is valid
  * @param $userName
  * @param $password
  * @return Model\UserModel|null
  */
 protected function _verifyUser($userName, $password)
 {
     $validUser = null;
     $user = Model\BasicModel::getNew('UserModel', 0);
     $user->getByName($userName);
     // check userName is valid
     if (!$user->dry()) {
         // check if password is valid
         $isValid = $user->verify($password);
         if ($isValid === true) {
             $validUser = $user;
         }
     }
     return $validUser;
 }
Example #20
0
 /**
  * delete signatures
  * @param \Base $f3
  */
 public function delete(\Base $f3)
 {
     $signatureIds = $f3->get('POST.signatureIds');
     $activeCharacter = $this->getCharacter();
     /**
      * @var Model\SystemSignatureModel $signature
      */
     $signature = Model\BasicModel::getNew('SystemSignatureModel');
     foreach ($signatureIds as $signatureId) {
         $signature->getById($signatureId);
         $signature->delete($activeCharacter);
         $signature->reset();
     }
     echo json_encode([]);
 }
Example #21
0
 /**
  * save a map
  * @return mixed
  */
 public function save()
 {
     $mapModel = parent::save();
     // check if map type has changed and clear access objects
     if (!$mapModel->dry()) {
         if ($mapModel->isPrivate()) {
             $mapModel->clearAccess(['corporation', 'alliance']);
         } elseif ($mapModel->isCorporation()) {
             $mapModel->clearAccess(['user', 'alliance']);
         } elseif ($mapModel->isAlliance()) {
             $mapModel->clearAccess(['user', 'corporation']);
         }
     }
     return $mapModel;
 }
Example #22
0
 /**
  * update character
  * @param $characterData
  * @return \Model\CharacterModel
  * @throws \Exception
  */
 private function updateCharacter($characterData)
 {
     $characterModel = null;
     $corporationModel = null;
     $allianceModel = null;
     if (!empty($characterData['corporation'])) {
         $corporationModel = Model\BasicModel::getNew('CorporationModel');
         $corporationModel->getById($characterData['corporation']['id'], 0);
         $corporationModel->copyfrom($characterData['corporation']);
         $corporationModel->save();
     }
     if (!empty($characterData['alliance'])) {
         $allianceModel = Model\BasicModel::getNew('AllianceModel');
         $allianceModel->getById($characterData['alliance']['id'], 0);
         $allianceModel->copyfrom($characterData['alliance']);
         $allianceModel->save();
     }
     if (!empty($characterData['character'])) {
         $characterModel = Model\BasicModel::getNew('CharacterModel');
         $characterModel->getById($characterData['character']['id'], 0);
         $characterModel->copyfrom($characterData['character']);
         $characterModel->corporationId = $corporationModel;
         $characterModel->allianceId = $allianceModel;
         $characterModel->save();
     }
     return $characterModel;
 }
Example #23
0
 /**
  * delete signatures
  * @param $f3
  */
 public function delete($f3)
 {
     $signatureIds = $f3->get('POST.signatureIds');
     $user = $this->_getUser();
     $signature = Model\BasicModel::getNew('SystemSignatureModel');
     foreach ($signatureIds as $signatureId) {
         $signature->getById($signatureId);
         $signature->delete($user);
         $signature->reset();
     }
     echo json_encode([]);
 }
Example #24
0
 /**
  * get system log data from CCP API import
  * system Kills, Jumps,....
  * @param $f3
  */
 public function graphData($f3)
 {
     $graphData = [];
     $systemIds = $f3->get('POST.systemIds');
     // number of log entries in each table per system (24 = 24h)
     $logEntryCount = 24;
     // table names with system data
     $logTables = ['jumps' => 'SystemJumpModel', 'shipKills' => 'SystemShipKillModel', 'podKills' => 'SystemPodKillModel', 'factionKills' => 'SystemFactionKillModel'];
     foreach ($systemIds as $systemId) {
         foreach ($logTables as $label => $ModelClass) {
             $systemLogModel = Model\BasicModel::getNew($ModelClass);
             // 10min cache (could be up to 1h cache time)
             $systemLogModel->getByForeignKey('systemId', $systemId, array(), 60 * 10);
             if (!$systemLogModel->dry()) {
                 $counter = 0;
                 for ($i = $logEntryCount; $i >= 1; $i--) {
                     $column = 'value' . $i;
                     // ship and pod kills should be merged into one table
                     if ($label == 'podKills') {
                         $graphData[$systemId]['shipKills'][$counter]['z'] = $systemLogModel->{$column};
                     } else {
                         $dataSet = ['x' => $i - 1 . 'h', 'y' => $systemLogModel->{$column}];
                         $graphData[$systemId][$label][] = $dataSet;
                     }
                     $counter++;
                 }
             }
         }
     }
     echo json_encode($graphData);
 }
Example #25
0
 /**
  * save/update user data
  * @param $f3
  */
 public function saveConfig($f3)
 {
     $data = $f3->get('POST');
     $return = (object) [];
     $return->error = [];
     $captcha = $f3->get('SESSION.captcha_code');
     // reset captcha -> forces user to enter new one
     $f3->clear('SESSION.captcha_code');
     $newUserData = null;
     // check user if if he is new
     $loginAfterSave = false;
     if (isset($data['settingsData'])) {
         $settingsData = $data['settingsData'];
         try {
             $user = $this->_getUser();
             // captcha is send -> check captcha
             if (isset($settingsData['captcha']) && !empty($settingsData['captcha'])) {
                 if ($settingsData['captcha'] === $captcha) {
                     // change/set sensitive user data requires captcha!
                     if ($user === false) {
                         // new user registration
                         $user = $mapType = Model\BasicModel::getNew('UserModel');
                         $loginAfterSave = true;
                         // set username
                         if (isset($settingsData['name']) && !empty($settingsData['name'])) {
                             $user->name = $settingsData['name'];
                         }
                     }
                     // change/set email
                     if (isset($settingsData['email']) && isset($settingsData['email_confirm']) && !empty($settingsData['email']) && !empty($settingsData['email_confirm']) && $settingsData['email'] == $settingsData['email_confirm']) {
                         $user->email = $settingsData['email'];
                     }
                     // change/set password
                     if (isset($settingsData['password']) && isset($settingsData['password_confirm']) && !empty($settingsData['password']) && !empty($settingsData['password_confirm']) && $settingsData['password'] == $settingsData['password_confirm']) {
                         $user->password = $settingsData['password'];
                     }
                 } else {
                     // captcha was send but not valid -> return error
                     $captchaError = (object) [];
                     $captchaError->type = 'error';
                     $captchaError->message = 'Captcha does not match';
                     $return->error[] = $captchaError;
                 }
             }
             // saving additional user info requires valid user object (no captcha required)
             if ($user) {
                 // save API data
                 if (isset($settingsData['keyId']) && isset($settingsData['vCode']) && is_array($settingsData['keyId']) && is_array($settingsData['vCode'])) {
                     // get all existing API models for this user
                     $apiModels = $user->getAPIs();
                     foreach ($settingsData['keyId'] as $i => $keyId) {
                         $api = null;
                         // search for existing API model
                         foreach ($apiModels as $key => $apiModel) {
                             if ($apiModel->keyId == $keyId) {
                                 $api = $apiModel;
                                 // make sure model is up2data -> cast()
                                 $api->cast();
                                 unset($apiModels[$key]);
                                 break;
                             }
                         }
                         if (is_null($api)) {
                             // new API Key
                             $api = Model\BasicModel::getNew('UserApiModel');
                             $api->userId = $user;
                         }
                         $api->keyId = $keyId;
                         $api->vCode = $settingsData['vCode'][$i];
                         $api->save();
                         $characterCount = $api->updateCharacters();
                         if ($characterCount == 0) {
                             // no characters found -> return warning
                             $characterError = (object) [];
                             $characterError->type = 'warning';
                             $characterError->message = 'API verification failed. No Characters found for KeyId ' . $api->keyId;
                             $return->error[] = $characterError;
                         }
                     }
                     // delete API models that no longer exists
                     foreach ($apiModels as $apiModel) {
                         $apiModel->delete();
                     }
                 }
                 // set main character
                 if (isset($settingsData['mainCharacterId'])) {
                     $user->setMainCharacterId((int) $settingsData['mainCharacterId']);
                 }
                 // check if the user already has a main character
                 // if not -> save the next best character as main
                 $mainUserCharacter = $user->getMainUserCharacter();
                 // set main character if no main character exists
                 if (is_null($mainUserCharacter)) {
                     $user->setMainCharacterId();
                 }
                 // save/update user model
                 // this will fail if model validation fails!
                 $user->save();
                 // log user in (in case he is new
                 if ($loginAfterSave) {
                     $this->logUserIn($user->name, $settingsData['password']);
                     // return reroute path
                     $return->reroute = self::getEnvironmentData('URL') . $this->f3->alias('map');
                 }
                 // get fresh updated user object
                 $user = $this->_getUser(0);
                 $newUserData = $user->getData();
             }
         } catch (Exception\ValidationException $e) {
             $validationError = (object) [];
             $validationError->type = 'error';
             $validationError->field = $e->getField();
             $validationError->message = $e->getMessage();
             $return->error[] = $validationError;
         } catch (Exception\RegistrationException $e) {
             $registrationError = (object) [];
             $registrationError->type = 'error';
             $registrationError->message = $e->getMessage();
             $return->error[] = $registrationError;
         }
         // return new/updated user data
         $return->userData = $newUserData;
     }
     echo json_encode($return);
 }
Example #26
0
 /**
  * overwrites parent
  * @param null $db
  * @param null $table
  * @param null $fields
  * @return bool
  */
 public static function setup($db = null, $table = null, $fields = null)
 {
     $status = parent::setup($db, $table, $fields);
     if ($status === true) {
         $status = parent::setMultiColumnIndex(['userId', 'apiId', 'characterId'], true);
         if ($status === true) {
             $status = parent::setMultiColumnIndex(['userId', 'apiId']);
         }
     }
     return $status;
 }
 public function __construct($db = NULL, $table = NULL, $fluid = NULL, $ttl = 0)
 {
     $this->addStaticKillFieldConfig();
     parent::__construct($db, $table, $fluid, $ttl);
 }
Example #28
0
 /**
  * export table data
  * @param $modelClass
  * @throws \Exception
  */
 protected function exportTable($modelClass)
 {
     $this->getDB('PF');
     Model\BasicModel::getNew($modelClass)->exportData();
 }