Skip to content

Commit

Permalink
Merge pull request #51 from exodus4d/develop
Browse files Browse the repository at this point in the history
v0.0.13
  • Loading branch information
exodus4d committed Oct 15, 2015
2 parents 633b817 + 074daf2 commit bc1e8e6
Show file tree
Hide file tree
Showing 59 changed files with 719 additions and 323 deletions.
2 changes: 1 addition & 1 deletion app/cron.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ deactivateMapData = Cron\MapUpdate->deactivateMapData, @hourly
deleteMapData = Cron\MapUpdate->deleteMapData, @downtime

; delete character log data
deleteLogData = Cron\CharacterUpdate->deleteLogData, @downtime
deleteLogData = Cron\CharacterUpdate->deleteLogData, @instant
17 changes: 9 additions & 8 deletions app/main/controller/api/route.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,18 @@ private function setSystemJumpData(){
$this->f3->exists($cacheKeyIdArray)
){
// get cached values

$this->nameArray = $this->f3->get($cacheKeyNamedArray);
$this->jumpArray = $this->f3->get($cacheKeyJumpArray);
$this->idArray = $this->f3->get($cacheKeyIdArray);
}else{
// nothing cached

$query = "SELECT * FROM system_neighbour";
$pfDB = $this->getDB('PF');

$rows = $this->f3->get('DB')->exec($query, null, $this->jumpDataCacheTime);
$query = "SELECT * FROM system_neighbour";

$rows = $pfDB->exec($query, null, $this->jumpDataCacheTime);

foreach($rows as $row){
$regionId = $row['regionId'];
Expand Down Expand Up @@ -202,8 +204,8 @@ private function graph_find_path(&$G, $A, $B, $M = 50000){
*/
private function setupSystemJumpTable(){

// switch DB
$this->setDB('CCP');
$pfDB = $this->getDB('PF');
$ccpDB = $this->getDB('CCP');

$query = "SELECT
map_sys.solarSystemID system_id,
Expand All @@ -228,18 +230,17 @@ private function setupSystemJumpTable(){
system_neighbours IS NOT NULL
";

$rows = $this->f3->get('DB')->exec($query);
$rows = $ccpDB->exec($query);

if(count($rows) > 0){
// switch DB back to pathfinder DB
$this->setDB('PF');

// clear cache table
$query = "TRUNCATE system_neighbour";
$this->f3->get('DB')->exec($query);
$pfDB->exec($query);

foreach($rows as $row){
$this->f3->get('DB')->exec("
$pfDB->exec("
INSERT INTO
system_neighbour(
regionId,
Expand Down
19 changes: 6 additions & 13 deletions app/main/controller/api/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,20 @@ protected function _getSystemModelByIds($columnIDs = [], $column = 'solarSystemI

$systemModels = [];

// switch DB
$this->setDB('CCP');
$ccpDB = $this->getDB('CCP');

$this->whereQuery = "WHERE
map_sys." . $column . " IN (" . implode(',', $columnIDs) . ")";

$query = $this->_getQuery();

$rows = $this->f3->get('DB')->exec($query, null, 60 * 60 * 24);
$rows = $ccpDB->exec($query, null, 60 * 60 * 24);

// format result
$mapper = new Mapper\CcpSystemsMapper($rows);

$ccpSystemsData = $mapper->getData();

// switch DB
$this->setDB('PF');

foreach($ccpSystemsData as $ccpSystemData){
$system = Model\BasicModel::getNew('SystemModel');
$system->setData($ccpSystemData);
Expand All @@ -132,12 +128,11 @@ protected function _getSystemModelByIds($columnIDs = [], $column = 'solarSystemI
*/
public function getSystems(){

// switch DB
$this->setDB('CCP');
$ccpDB = $this->getDB('CCP');

$query = $this->_getQuery();

$rows = $this->f3->get('DB')->exec($query, null, 60 * 60 * 24);
$rows = $ccpDB->exec($query, null, 60 * 60 * 24);

// format result
$mapper = new Mapper\CcpSystemsMapper($rows);
Expand All @@ -152,9 +147,7 @@ public function getSystems(){
*/
public function search($f3, $params){

// switch DB
\DB\Database::instance();
$this->setDB('CCP');
$ccpDB = $this->getDB('CCP');

$searchToken = '';
// check for search parameter
Expand All @@ -167,7 +160,7 @@ public function search($f3, $params){

$query = $this->_getQuery();

$rows = $f3->get('DB')->exec($query);
$rows = $ccpDB->exec($query);

// format result
$mapper = new Mapper\CcpSystemsMapper($rows);
Expand Down
19 changes: 6 additions & 13 deletions app/main/controller/api/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use controller\MailController;
use Model;
use Exception;
use DB;

class User extends Controller\Controller{

Expand Down Expand Up @@ -70,10 +71,12 @@ private function logUserIn($userName, $password){

// set Session login
$dateTime = new \DateTime();
$this->f3->set('SESSION.user.time', $dateTime->getTimestamp());
$this->f3->set('SESSION.user.name', $user->name);
$this->f3->set('SESSION.user.id', $user->id);

$this->f3->set('SESSION.user', [
'time' => $dateTime->getTimestamp(),
'name' => $user->name,
'id' => $user->id
]);

// save user login information
$user->touch('lastLogin');
Expand Down Expand Up @@ -144,19 +147,9 @@ public function deleteLog($f3){

if($characterLog = $character->getLog()){
$characterLog->erase();
$characterLog->save();

$character->clearCacheData();

// delete log cache key as well
$f3->clear('LOGGED.user.character.id_' . $characterLog->characterId->id . '.systemId');
$f3->clear('LOGGED.user.character.id_' . $characterLog->characterId->id . '.shipId');

}
}
}


}

/**
Expand Down
122 changes: 63 additions & 59 deletions app/main/controller/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ function afterroute() {
/**
* set change the DB connection
* @param string $database
* @return mixed|void
*/
protected function setDB($database = 'PF'){
DB\Database::instance()->setDB($database);
protected function getDB($database = 'PF'){
return DB\Database::instance()->getDB($database);
}

/**
Expand All @@ -79,20 +80,72 @@ protected function setDB($database = 'PF'){
protected function _getUser($ttl = 5){

$user = false;
$userId = $this->f3->get('SESSION.user.id');

if($userId > 0){
$userModel = Model\BasicModel::getNew('UserModel');
$userModel->getById($userId, $ttl);
if( $this->f3->exists('SESSION.user.id') ){
$userId = (int)$this->f3->get('SESSION.user.id');

if( !$userModel->dry() ){
$user = $userModel;
if($userId > 0){
$userModel = Model\BasicModel::getNew('UserModel');
$userModel->getById($userId, $ttl);

if( !$userModel->dry() ){
$user = $userModel;
}
}
}

return $user;
}

/**
* log the current user out
* @param $f3
*/
public function logOut($f3){

// destroy session
$f3->clear('SESSION');

if( !$f3->get('AJAX') ){
// redirect to landing page
$f3->reroute('@landing');
}else{
$return = (object) [];
$return->reroute = self::getEnvironmentData('URL') . $f3->alias('landing');
$return->error[] = $this->getUserLoggedOffError();

echo json_encode($return);
die();
}
}

/**
* 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;
}

/**
* check weather the page is IGB trusted or not
* @return mixed
Expand Down Expand Up @@ -152,55 +205,6 @@ static function isIGB(){
return $isIGB;
}

/**
* 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;
}

/**
* log the current user out
* @param $f3
*/
public function logOut($f3){

// destroy session
$f3->clear('SESSION.user');
$f3->sync('SESSION');

if( !$f3->get('AJAX') ){
// redirect to landing page
$f3->reroute('@landing');
}else{
$return = (object) [];
$return->reroute = self::getEnvironmentData('URL') . $f3->alias('landing');
$return->error[] = $this->getUserLoggedOffError();

echo json_encode($return);
die();
}
}

/**
* get error object is a user is not found/logged of
Expand Down Expand Up @@ -238,8 +242,8 @@ static function getLogger($loggerType){
* @return mixed
*/
static function formatHiveKey($key){
$illegalCharacters = ['-'];
return str_replace($illegalCharacters, '', $key);
$illegalCharacters = ['-', ' '];
return strtolower( str_replace($illegalCharacters, '', $key) );
}

/**
Expand Down
Loading

0 comments on commit bc1e8e6

Please sign in to comment.