- #84 CREST Login (WIP)
- New CREST controller - Database restructuring - improved type-casting for some controller functions - New login process - Fixed some bugs during the setup process (/setup root) - Added CREST request caching by response headers
This commit is contained in:
@@ -7,27 +7,26 @@
|
||||
*/
|
||||
|
||||
namespace Controller\Api;
|
||||
use Controller;
|
||||
use Model;
|
||||
|
||||
class Connection extends \Controller\AccessController{
|
||||
class Connection extends Controller\AccessController{
|
||||
|
||||
/**
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
function beforeroute($f3) {
|
||||
|
||||
parent::beforeroute($f3);
|
||||
|
||||
function beforeroute(\Base $f3) {
|
||||
// set header for all routes
|
||||
header('Content-type: application/json');
|
||||
parent::beforeroute($f3);
|
||||
}
|
||||
|
||||
/**
|
||||
* save a new connection or updates an existing (drag/drop) between two systems
|
||||
* if a connection is changed (drag&drop) to another system. -> this function is called for update
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function save($f3){
|
||||
public function save(\Base $f3){
|
||||
$postData = (array)$f3->get('POST');
|
||||
$newConnectionData = [];
|
||||
|
||||
@@ -38,10 +37,15 @@ class Connection extends \Controller\AccessController{
|
||||
$mapData = (array)$postData['mapData'];
|
||||
$connectionData = (array)$postData['connectionData'];
|
||||
|
||||
$user = $this->_getUser();
|
||||
$activeCharacter = $this->getCharacter();
|
||||
|
||||
if($activeCharacter){
|
||||
$user = $activeCharacter->getUser();
|
||||
|
||||
if($user){
|
||||
// get map model and check map access
|
||||
/**
|
||||
* @var Model\MapModel $map
|
||||
*/
|
||||
$map = Model\BasicModel::getNew('MapModel');
|
||||
$map->getById( (int)$mapData['id'] );
|
||||
|
||||
@@ -90,16 +94,22 @@ class Connection extends \Controller\AccessController{
|
||||
echo json_encode($newConnectionData);
|
||||
}
|
||||
|
||||
public function delete($f3){
|
||||
/**
|
||||
* delete connection
|
||||
* @param \Base $f3
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(\Base $f3){
|
||||
$connectionIds = $f3->get('POST.connectionIds');
|
||||
$activeCharacter = $this->getCharacter();
|
||||
|
||||
$user = $this->_getUser();
|
||||
/**
|
||||
* @var Model\ConnectionModel $connection
|
||||
*/
|
||||
$connection = Model\BasicModel::getNew('ConnectionModel');
|
||||
|
||||
foreach($connectionIds as $connectionId){
|
||||
|
||||
$connection->getById($connectionId);
|
||||
$connection->delete($user);
|
||||
$connection->delete( $activeCharacter->getUser() );
|
||||
|
||||
$connection->reset();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
namespace Controller\Api;
|
||||
use Controller;
|
||||
use Model;
|
||||
|
||||
/**
|
||||
@@ -14,25 +15,23 @@ use Model;
|
||||
* Class Map
|
||||
* @package Controller\Api
|
||||
*/
|
||||
class Map extends \Controller\AccessController {
|
||||
class Map extends Controller\AccessController {
|
||||
|
||||
/**
|
||||
* event handler
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
function beforeroute($f3) {
|
||||
|
||||
function beforeroute(\Base $f3) {
|
||||
// set header for all routes
|
||||
header('Content-type: application/json');
|
||||
|
||||
parent::beforeroute($f3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all required static config data for program initialization
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function init($f3){
|
||||
public function init(\Base $f3){
|
||||
|
||||
// expire time in seconds
|
||||
$expireTimeHead = 60 * 60 * 12;
|
||||
@@ -143,9 +142,9 @@ class Map extends \Controller\AccessController {
|
||||
|
||||
/**
|
||||
* import new map data
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function import($f3){
|
||||
public function import(\Base $f3){
|
||||
$importData = (array)$f3->get('POST');
|
||||
|
||||
$return = (object) [];
|
||||
@@ -155,13 +154,24 @@ class Map extends \Controller\AccessController {
|
||||
isset($importData['typeId']) &&
|
||||
count($importData['mapData']) > 0
|
||||
){
|
||||
$user = $this->_getUser();
|
||||
$activeCharacter = $this->getCharacter();
|
||||
|
||||
if($user){
|
||||
$activeCharacter = $user->getActiveUserCharacter();
|
||||
if($activeCharacter){
|
||||
$user = $activeCharacter->getUser();
|
||||
|
||||
/**
|
||||
* @var $map Model\MapModel
|
||||
*/
|
||||
$map = Model\BasicModel::getNew('MapModel');
|
||||
|
||||
/**
|
||||
* @var $system Model\SystemModel
|
||||
*/
|
||||
$system = Model\BasicModel::getNew('SystemModel');
|
||||
|
||||
/**
|
||||
* @var $connection Model\ConnectionModel
|
||||
*/
|
||||
$connection = Model\BasicModel::getNew('ConnectionModel');
|
||||
|
||||
foreach($importData['mapData'] as $mapData){
|
||||
@@ -194,8 +204,8 @@ class Map extends \Controller\AccessController {
|
||||
|
||||
$system->setData($systemData);
|
||||
$system->mapId = $map;
|
||||
$system->createdCharacterId = $activeCharacter->characterId;
|
||||
$system->updatedCharacterId = $activeCharacter->characterId;
|
||||
$system->createdCharacterId = $activeCharacter;
|
||||
$system->updatedCharacterId = $activeCharacter;
|
||||
$system->save();
|
||||
|
||||
$tempSystemIdMapping[$oldId] = $system->id;
|
||||
@@ -228,13 +238,11 @@ class Map extends \Controller\AccessController {
|
||||
if($map->isPrivate()){
|
||||
$map->setAccess($user);
|
||||
}elseif($map->isCorporation()){
|
||||
$corporation = $activeCharacter->getCharacter()->getCorporation();
|
||||
if($corporation){
|
||||
if($corporation = $activeCharacter->getCorporation()){
|
||||
$map->setAccess($corporation);
|
||||
}
|
||||
}elseif($map->isAlliance()){
|
||||
$alliance = $activeCharacter->getCharacter()->getAlliance();
|
||||
if($alliance){
|
||||
if($alliance = $activeCharacter->getAlliance()){
|
||||
$map->setAccess($alliance);
|
||||
}
|
||||
}
|
||||
@@ -260,7 +268,7 @@ class Map extends \Controller\AccessController {
|
||||
}
|
||||
}else{
|
||||
// user not found
|
||||
$return->error[] = $this->getUserLoggedOffError();
|
||||
$return->error[] = $this->getLogoutError();
|
||||
}
|
||||
}else{
|
||||
// map data missing
|
||||
@@ -276,19 +284,23 @@ class Map extends \Controller\AccessController {
|
||||
|
||||
/**
|
||||
* save a new map or update an existing map
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function save($f3){
|
||||
public function save(\Base $f3){
|
||||
$formData = (array)$f3->get('POST.formData');
|
||||
|
||||
$return = (object) [];
|
||||
$return->error = [];
|
||||
|
||||
if( isset($formData['id']) ){
|
||||
$activeCharacter = $this->getCharacter(0);
|
||||
|
||||
$user = $this->_getUser(0);
|
||||
if($activeCharacter){
|
||||
$user = $activeCharacter->getUser();
|
||||
|
||||
if($user){
|
||||
/**
|
||||
* @var $map Model\MapModel
|
||||
*/
|
||||
$map = Model\BasicModel::getNew('MapModel');
|
||||
$map->getById( (int)$formData['id'] );
|
||||
|
||||
@@ -311,6 +323,9 @@ class Map extends \Controller\AccessController {
|
||||
// clear map access. In case something has removed from access list
|
||||
$map->clearAccess();
|
||||
|
||||
/**
|
||||
* @var $tempUser Model\UserModel
|
||||
*/
|
||||
$tempUser = Model\BasicModel::getNew('UserModel');
|
||||
|
||||
foreach($accessUsers as $userId){
|
||||
@@ -331,90 +346,86 @@ class Map extends \Controller\AccessController {
|
||||
// just in case he removed himself :)
|
||||
$map->setAccess($user);
|
||||
}elseif($map->isCorporation()){
|
||||
$activeCharacter = $user->getActiveUserCharacter();
|
||||
$corporation = $activeCharacter->getCorporation();
|
||||
|
||||
if($activeCharacter){
|
||||
$corporation = $activeCharacter->getCharacter()->getCorporation();
|
||||
if($corporation){
|
||||
// the current user has to have a corporation when
|
||||
// working on corporation maps!
|
||||
|
||||
if($corporation){
|
||||
// the current user has to have a corporation when
|
||||
// working on corporation maps!
|
||||
// share map between corporations -> set access
|
||||
if(isset($formData['mapCorporations'])){
|
||||
// avoid abuse -> respect share limits
|
||||
$accessCorporations = array_slice( $formData['mapCorporations'], 0, $f3->get('PATHFINDER.MAX_SHARED_CORPORATION') );
|
||||
|
||||
// share map between corporations -> set access
|
||||
if(isset($formData['mapCorporations'])){
|
||||
// avoid abuse -> respect share limits
|
||||
$accessCorporations = array_slice( $formData['mapCorporations'], 0, $f3->get('PATHFINDER.MAX_SHARED_CORPORATION') );
|
||||
// clear map access. In case something has removed from access list
|
||||
$map->clearAccess();
|
||||
|
||||
// clear map access. In case something has removed from access list
|
||||
$map->clearAccess();
|
||||
/**
|
||||
* @var $tempCorporation Model\CorporationModel
|
||||
*/
|
||||
$tempCorporation = Model\BasicModel::getNew('CorporationModel');
|
||||
|
||||
$tempCorporation = Model\BasicModel::getNew('CorporationModel');
|
||||
foreach($accessCorporations as $corporationId){
|
||||
$tempCorporation->getById( (int)$corporationId );
|
||||
|
||||
foreach($accessCorporations as $corporationId){
|
||||
$tempCorporation->getById( (int)$corporationId );
|
||||
|
||||
if(
|
||||
!$tempCorporation->dry() &&
|
||||
$tempCorporation->shared == 1 // check if map shared is enabled
|
||||
){
|
||||
$map->setAccess($tempCorporation);
|
||||
}
|
||||
|
||||
$tempCorporation->reset();
|
||||
if(
|
||||
!$tempCorporation->dry() &&
|
||||
$tempCorporation->shared == 1 // check if map shared is enabled
|
||||
){
|
||||
$map->setAccess($tempCorporation);
|
||||
}
|
||||
}
|
||||
|
||||
// the corporation of the current user should always have access
|
||||
$map->setAccess($corporation);
|
||||
$tempCorporation->reset();
|
||||
}
|
||||
}
|
||||
|
||||
// the corporation of the current user should always have access
|
||||
$map->setAccess($corporation);
|
||||
}
|
||||
}elseif($map->isAlliance()){
|
||||
$activeCharacter = $user->getActiveUserCharacter();
|
||||
$alliance = $activeCharacter->getAlliance();
|
||||
|
||||
if($activeCharacter){
|
||||
$alliance = $activeCharacter->getCharacter()->getAlliance();
|
||||
if($alliance){
|
||||
// the current user has to have a alliance when
|
||||
// working on alliance maps!
|
||||
|
||||
if($alliance){
|
||||
// the current user has to have a alliance when
|
||||
// working on alliance maps!
|
||||
// share map between alliances -> set access
|
||||
if(isset($formData['mapAlliances'])){
|
||||
// avoid abuse -> respect share limits
|
||||
$accessAlliances = array_slice( $formData['mapAlliances'], 0, $f3->get('PATHFINDER.MAX_SHARED_ALLIANCE') );
|
||||
|
||||
// share map between alliances -> set access
|
||||
if(isset($formData['mapAlliances'])){
|
||||
// avoid abuse -> respect share limits
|
||||
$accessAlliances = array_slice( $formData['mapAlliances'], 0, $f3->get('PATHFINDER.MAX_SHARED_ALLIANCE') );
|
||||
// clear map access. In case something has removed from access list
|
||||
$map->clearAccess();
|
||||
|
||||
// clear map access. In case something has removed from access list
|
||||
$map->clearAccess();
|
||||
/**
|
||||
* @var $tempAlliance Model\AllianceModel
|
||||
*/
|
||||
$tempAlliance = Model\BasicModel::getNew('AllianceModel');
|
||||
|
||||
$tempAlliance = Model\BasicModel::getNew('AllianceModel');
|
||||
foreach($accessAlliances as $allianceId){
|
||||
$tempAlliance->getById( (int)$allianceId );
|
||||
|
||||
foreach($accessAlliances as $allianceId){
|
||||
$tempAlliance->getById( (int)$allianceId );
|
||||
|
||||
if(
|
||||
!$tempAlliance->dry() &&
|
||||
$tempAlliance->shared == 1 // check if map shared is enabled
|
||||
){
|
||||
$map->setAccess($tempAlliance);
|
||||
}
|
||||
|
||||
$tempAlliance->reset();
|
||||
if(
|
||||
!$tempAlliance->dry() &&
|
||||
$tempAlliance->shared == 1 // check if map shared is enabled
|
||||
){
|
||||
$map->setAccess($tempAlliance);
|
||||
}
|
||||
|
||||
$tempAlliance->reset();
|
||||
}
|
||||
|
||||
// the alliance of the current user should always have access
|
||||
$map->setAccess($alliance);
|
||||
}
|
||||
|
||||
// the alliance of the current user should always have access
|
||||
$map->setAccess($alliance);
|
||||
}
|
||||
}
|
||||
// reload the same map model (refresh)
|
||||
// this makes sure all data is up2date
|
||||
$map->getById( $map->id, 0 );
|
||||
|
||||
|
||||
$return->mapData = $map->getData();
|
||||
|
||||
}else{
|
||||
// map access denied
|
||||
$captchaError = (object) [];
|
||||
@@ -423,7 +434,6 @@ class Map extends \Controller\AccessController {
|
||||
$return->error[] = $captchaError;
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
// map id field missing
|
||||
$idError = (object) [];
|
||||
@@ -437,17 +447,19 @@ class Map extends \Controller\AccessController {
|
||||
|
||||
/**
|
||||
* delete a map and all dependencies
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function delete($f3){
|
||||
public function delete(\Base $f3){
|
||||
$mapData = (array)$f3->get('POST.mapData');
|
||||
$activeCharacter = $this->getCharacter();
|
||||
|
||||
$user = $this->_getUser();
|
||||
|
||||
if($user){
|
||||
if($activeCharacter){
|
||||
/**
|
||||
* @var $map Model\MapModel
|
||||
*/
|
||||
$map = Model\BasicModel::getNew('MapModel');
|
||||
$map->getById($mapData['id']);
|
||||
$map->delete($user);
|
||||
$map->delete( $activeCharacter->getUser() );
|
||||
}
|
||||
|
||||
echo json_encode([]);
|
||||
@@ -455,34 +467,28 @@ class Map extends \Controller\AccessController {
|
||||
|
||||
/**
|
||||
* update map data
|
||||
* function is called continuously
|
||||
* @param $f3
|
||||
* -> function is called continuously (trigger) by any active client
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function updateData($f3){
|
||||
|
||||
// cache time(s) per user should be equal or less than this function is called
|
||||
// prevent request flooding
|
||||
$responseTTL = $f3->get('PATHFINDER.TIMER.UPDATE_SERVER_MAP.DELAY') / 1000;
|
||||
public function updateData(\Base $f3){
|
||||
$mapData = (array)$f3->get('POST.mapData');
|
||||
|
||||
$user = $this->_getUser();
|
||||
$activeCharacter = $this->getCharacter();
|
||||
|
||||
$return = (object) [];
|
||||
$return->error = [];
|
||||
|
||||
if($user){
|
||||
// -> get active character
|
||||
$activeCharacter = $user->getActiveUserCharacter();
|
||||
if($activeCharacter){
|
||||
|
||||
$cacheKey = 'user_map_data_' . $activeCharacter->id;
|
||||
|
||||
// if there is any system/connection change data submitted -> save new data
|
||||
if(
|
||||
$f3->exists($cacheKey) === false ||
|
||||
!$f3->exists($cacheKey) ||
|
||||
!empty($mapData)
|
||||
){
|
||||
|
||||
// get current map data ========================================================
|
||||
$maps = $user->getMaps();
|
||||
$maps = $activeCharacter->getUser()->getMaps();
|
||||
|
||||
// loop all submitted map data that should be saved
|
||||
// -> currently there will only be ONE map data change submitted -> single loop
|
||||
@@ -532,7 +538,7 @@ class Map extends \Controller\AccessController {
|
||||
unset($systemData['updated']);
|
||||
$system = $filteredMap->systems->current();
|
||||
$system->setData($systemData);
|
||||
$system->updatedCharacterId = $activeCharacter->characterId;
|
||||
$system->updatedCharacterId = $activeCharacter;
|
||||
$system->save();
|
||||
|
||||
// a system belongs to ONE map -> speed up for multiple maps
|
||||
@@ -561,7 +567,7 @@ class Map extends \Controller\AccessController {
|
||||
unset($connectionData['updated']);
|
||||
$connection = $filteredMap->connections->current();
|
||||
$connection->setData($connectionData);
|
||||
$connection->save($user);
|
||||
$connection->save();
|
||||
|
||||
// a connection belongs to ONE map -> speed up for multiple maps
|
||||
unset($connectionData[$i]);
|
||||
@@ -574,6 +580,11 @@ class Map extends \Controller\AccessController {
|
||||
|
||||
// format map Data for return
|
||||
$return->mapData = self::getFormattedMapData($maps);
|
||||
|
||||
// cache time(s) per user should be equal or less than this function is called
|
||||
// prevent request flooding
|
||||
$responseTTL = $f3->get('PATHFINDER.TIMER.UPDATE_SERVER_MAP.DELAY') / 1000;
|
||||
|
||||
$f3->set($cacheKey, $return, $responseTTL);
|
||||
}else{
|
||||
// get from cache
|
||||
@@ -582,23 +593,24 @@ class Map extends \Controller\AccessController {
|
||||
|
||||
}else{
|
||||
// user logged off
|
||||
$return->error[] = $this->getUserLoggedOffError();
|
||||
$return->error[] = $this->getLogoutError();
|
||||
}
|
||||
|
||||
echo json_encode( $return );
|
||||
}
|
||||
|
||||
/**
|
||||
* get formatted map data
|
||||
* @param $mapModels
|
||||
* @return Model\MapModel[]
|
||||
* @return array
|
||||
*/
|
||||
public static function getFormattedMapData($mapModels){
|
||||
|
||||
$mapData = [];
|
||||
foreach($mapModels as $mapModel){
|
||||
|
||||
foreach($mapModels as &$mapModel){
|
||||
/**
|
||||
* @var $mapModel Model\MapModel
|
||||
*/
|
||||
$allMapData = $mapModel->getData();
|
||||
|
||||
$mapData[] = [
|
||||
'config' => $allMapData->mapData,
|
||||
'data' => [
|
||||
@@ -613,33 +625,23 @@ class Map extends \Controller\AccessController {
|
||||
|
||||
/**
|
||||
* update map data api
|
||||
* function is called continuously
|
||||
* @param $f3
|
||||
* -> function is called continuously by any active client
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function updateUserData($f3){
|
||||
|
||||
// cache time(s) should be equal or less than request trigger time
|
||||
// prevent request flooding
|
||||
$responseTTL = $f3->get('PATHFINDER.TIMER.UPDATE_SERVER_USER_DATA.DELAY') / 1000;
|
||||
|
||||
// if the cache key will be set -> cache request
|
||||
$cacheKey = null;
|
||||
|
||||
public function updateUserData(\Base $f3){
|
||||
$return = (object) [];
|
||||
$return->error = [];
|
||||
$activeCharacter = $this->getCharacter();
|
||||
|
||||
$user = $this->_getUser();
|
||||
|
||||
if($user){
|
||||
if($activeCharacter){
|
||||
$user = $activeCharacter->getUser();
|
||||
|
||||
if( !empty($f3->get('POST.mapIds')) ){
|
||||
$mapIds = (array)$f3->get('POST.mapIds');
|
||||
// check if data for specific system is requested
|
||||
$systemData = (array)$f3->get('POST.systemData');
|
||||
|
||||
|
||||
// update current location (IGB data)
|
||||
$user->updateCharacterLog(60 * 5);
|
||||
// update current location
|
||||
$activeCharacter->updateLog();
|
||||
|
||||
// if data is requested extend the cache key in order to get new data
|
||||
$requestSystemData = (object) [];
|
||||
@@ -649,12 +651,11 @@ class Map extends \Controller\AccessController {
|
||||
// IMPORTANT for now -> just update a single map (save performance)
|
||||
$mapIds = array_slice($mapIds, 0, 1);
|
||||
|
||||
// the userMasData is cached per map (this must be changed if multiple maps
|
||||
// the userMapData is cached per map (this must be changed if multiple maps
|
||||
// will be allowed in future...
|
||||
$tempId = (int)$mapIds[0];
|
||||
$cacheKey = 'user_data_' . $tempId . '_' . $requestSystemData->systemId;
|
||||
|
||||
if( $f3->exists($cacheKey) === false ){
|
||||
if( !$f3->exists($cacheKey) ){
|
||||
foreach($mapIds as $mapId){
|
||||
$map = $user->getMap($mapId);
|
||||
|
||||
@@ -666,7 +667,7 @@ class Map extends \Controller\AccessController {
|
||||
$system = $map->getSystem( $requestSystemData->systemId );
|
||||
|
||||
if( !is_null($system) ){
|
||||
// data for the current selected system
|
||||
// data for currently selected system
|
||||
$return->system = $system->getData();
|
||||
$return->system->signatures = $system->getSignaturesData();
|
||||
}
|
||||
@@ -674,6 +675,10 @@ class Map extends \Controller\AccessController {
|
||||
}
|
||||
}
|
||||
|
||||
// cache time (seconds) should be equal or less than request trigger time
|
||||
// prevent request flooding
|
||||
$responseTTL = $f3->get('PATHFINDER.TIMER.UPDATE_SERVER_USER_DATA.DELAY') / 1000;
|
||||
|
||||
// cache response
|
||||
$f3->set($cacheKey, $return, $responseTTL);
|
||||
}else{
|
||||
@@ -683,17 +688,14 @@ class Map extends \Controller\AccessController {
|
||||
$return = $f3->get($cacheKey);
|
||||
}
|
||||
}
|
||||
|
||||
// get current user data -> this should not be cached because each user has different personal data
|
||||
// even if they have multiple characters using the same map!
|
||||
$return->userData = $user->getData();
|
||||
|
||||
}else{
|
||||
// user logged off
|
||||
$return->error[] = $this->getUserLoggedOffError();
|
||||
$return->error[] = $this->getLogoutError();
|
||||
}
|
||||
|
||||
|
||||
echo json_encode( $return );
|
||||
}
|
||||
|
||||
|
||||
@@ -14,14 +14,12 @@ class Signature extends \Controller\AccessController{
|
||||
|
||||
/**
|
||||
* event handler
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
function beforeroute($f3) {
|
||||
|
||||
parent::beforeroute($f3);
|
||||
|
||||
function beforeroute(\Base $f3) {
|
||||
// set header for all routes
|
||||
header('Content-type: application/json');
|
||||
parent::beforeroute($f3);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,18 +29,18 @@ class Signature extends \Controller\AccessController{
|
||||
public function getAll($f3){
|
||||
$signatureData = [];
|
||||
$systemIds = $f3->get('POST.systemIds');
|
||||
$activeCharacter = $this->getCharacter();
|
||||
|
||||
$user = $this->_getUser();
|
||||
|
||||
/**
|
||||
* @var Model\SystemModel $system
|
||||
*/
|
||||
$system = Model\BasicModel::getNew('SystemModel');
|
||||
|
||||
foreach($systemIds as $systemId){
|
||||
$system->getById($systemId);
|
||||
|
||||
if(!$system->dry()){
|
||||
|
||||
// check access
|
||||
if($system->hasAccess($user)){
|
||||
if( $system->hasAccess($activeCharacter->getUser()) ){
|
||||
$signatureData = $system->getSignaturesData();
|
||||
}
|
||||
}
|
||||
@@ -74,11 +72,14 @@ class Signature extends \Controller\AccessController{
|
||||
}
|
||||
|
||||
if( !is_null($signatureData) ){
|
||||
$user = $this->_getUser();
|
||||
$activeCharacter = $this->getCharacter();
|
||||
|
||||
if($user){
|
||||
$activeUserCharacter = $user->getActiveUserCharacter();
|
||||
$activeCharacter = $activeUserCharacter->getCharacter();
|
||||
if($activeCharacter){
|
||||
$user = $activeCharacter->getUser();
|
||||
|
||||
/**
|
||||
* @var Model\SystemModel $system
|
||||
*/
|
||||
$system = Model\BasicModel::getNew('SystemModel');
|
||||
|
||||
// update/add all submitted signatures
|
||||
@@ -173,23 +174,23 @@ class Signature extends \Controller\AccessController{
|
||||
|
||||
/**
|
||||
* delete signatures
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function delete($f3){
|
||||
$signatureIds = $f3->get('POST.signatureIds');
|
||||
$activeCharacter = $this->getCharacter();
|
||||
|
||||
$user = $this->_getUser();
|
||||
/**
|
||||
* @var Model\SystemSignatureModel $signature
|
||||
*/
|
||||
$signature = Model\BasicModel::getNew('SystemSignatureModel');
|
||||
|
||||
foreach($signatureIds as $signatureId){
|
||||
$signature->getById($signatureId);
|
||||
|
||||
$signature->delete($user);
|
||||
$signature->delete( $activeCharacter->getUser() );
|
||||
$signature->reset();
|
||||
}
|
||||
|
||||
echo json_encode([]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -63,9 +63,9 @@ class System extends \Controller\AccessController {
|
||||
private $limitQuery = "";
|
||||
|
||||
/**
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
function beforeroute($f3) {
|
||||
function beforeroute(\Base $f3) {
|
||||
|
||||
parent::beforeroute($f3);
|
||||
|
||||
@@ -92,7 +92,8 @@ class System extends \Controller\AccessController {
|
||||
* get static system Data from CCPs Static DB export
|
||||
* search column for IDs can be (solarSystemID, regionID, constellationID)
|
||||
* @param array $columnIDs
|
||||
* @return null
|
||||
* @param string $column
|
||||
* @return Model\SystemModel[]
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function _getSystemModelByIds($columnIDs = [], $column = 'solarSystemID'){
|
||||
@@ -110,10 +111,12 @@ class System extends \Controller\AccessController {
|
||||
|
||||
// format result
|
||||
$mapper = new Mapper\CcpSystemsMapper($rows);
|
||||
|
||||
$ccpSystemsData = $mapper->getData();
|
||||
|
||||
foreach($ccpSystemsData as $ccpSystemData){
|
||||
/**
|
||||
* @var Model\SystemModel $system
|
||||
*/
|
||||
$system = Model\BasicModel::getNew('SystemModel');
|
||||
$system->setData($ccpSystemData);
|
||||
$systemModels[] = $system;
|
||||
@@ -142,10 +145,10 @@ class System extends \Controller\AccessController {
|
||||
|
||||
/**
|
||||
* search systems by name
|
||||
* @param $f3
|
||||
* @param $params
|
||||
* @param \Base $f3
|
||||
* @param array $params
|
||||
*/
|
||||
public function search($f3, $params){
|
||||
public function search(\Base $f3, $params){
|
||||
|
||||
$ccpDB = $this->getDB('CCP');
|
||||
|
||||
@@ -172,10 +175,9 @@ class System extends \Controller\AccessController {
|
||||
|
||||
/**
|
||||
* save a new system to a a map
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function save($f3){
|
||||
|
||||
public function save(\Base $f3){
|
||||
$newSystemData = [];
|
||||
|
||||
$postData = (array)$f3->get('POST');
|
||||
@@ -187,20 +189,21 @@ class System extends \Controller\AccessController {
|
||||
isset($postData['systemData']) &&
|
||||
isset($postData['mapData'])
|
||||
){
|
||||
$user = $this->_getUser();
|
||||
$activeCharacter = $this->getCharacter();
|
||||
|
||||
if($user){
|
||||
if($activeCharacter){
|
||||
$user = $activeCharacter->getUser();
|
||||
$systemData = (array)$postData['systemData'];
|
||||
$mapData = (array)$postData['mapData'];
|
||||
|
||||
$activeCharacter = $user->getActiveUserCharacter();
|
||||
|
||||
if( isset($systemData['id']) ){
|
||||
// update existing system
|
||||
|
||||
/**
|
||||
* @var $system Model\SystemModel
|
||||
*/
|
||||
$system = Model\BasicModel::getNew('SystemModel');
|
||||
$system->getById($systemData['id']);
|
||||
|
||||
if( !$system->dry() ){
|
||||
if( $system->hasAccess($user) ){
|
||||
// system model found
|
||||
@@ -210,9 +213,11 @@ class System extends \Controller\AccessController {
|
||||
}elseif( isset($mapData['id']) ){
|
||||
// save NEW system
|
||||
|
||||
/**
|
||||
* @var $map Model\MapModel
|
||||
*/
|
||||
$map = Model\BasicModel::getNew('MapModel');
|
||||
$map->getById($mapData['id']);
|
||||
|
||||
if( !$map->dry() ){
|
||||
if( $map->hasAccess($user) ){
|
||||
|
||||
@@ -221,7 +226,7 @@ class System extends \Controller\AccessController {
|
||||
// get static system data (CCP DB)
|
||||
$systemModel = array_values( $this->_getSystemModelByIds([$systemData['systemId']]) )[0];
|
||||
|
||||
$systemModel->createdCharacterId = $activeCharacter->characterId;
|
||||
$systemModel->createdCharacterId = $activeCharacter;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -229,50 +234,23 @@ class System extends \Controller\AccessController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( !is_null($systemModel) ){
|
||||
// set/update system
|
||||
|
||||
$systemModel->setData($systemData);
|
||||
$systemModel->updatedCharacterId = $activeCharacter->characterId;
|
||||
$systemModel->updatedCharacterId = $activeCharacter;
|
||||
$systemModel->save();
|
||||
|
||||
$newSystemData = $systemModel->getData();
|
||||
}
|
||||
|
||||
echo json_encode($newSystemData);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete systems and all its connections
|
||||
* @param $f3
|
||||
*/
|
||||
public function delete($f3){
|
||||
$systemIds = $f3->get('POST.systemIds');
|
||||
|
||||
$user = $this->_getUser();
|
||||
|
||||
if($user){
|
||||
$system = Model\BasicModel::getNew('SystemModel');
|
||||
|
||||
foreach((array)$systemIds as $systemId){
|
||||
|
||||
$system->getById($systemId);
|
||||
$system->delete($user);
|
||||
|
||||
$system->reset();
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* get system log data from CCP API import
|
||||
* system Kills, Jumps,....
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function graphData($f3){
|
||||
public function graphData(\Base $f3){
|
||||
$graphData = [];
|
||||
$systemIds = $f3->get('POST.systemIds');
|
||||
|
||||
@@ -288,7 +266,6 @@ class System extends \Controller\AccessController {
|
||||
];
|
||||
|
||||
foreach($systemIds as $systemId){
|
||||
|
||||
foreach($logTables as $label => $ModelClass){
|
||||
$systemLogModel = Model\BasicModel::getNew($ModelClass);
|
||||
|
||||
@@ -313,7 +290,6 @@ class System extends \Controller\AccessController {
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,25 +298,22 @@ class System extends \Controller\AccessController {
|
||||
|
||||
/**
|
||||
* get system data for all systems within a constellation
|
||||
* @param $f3
|
||||
* @param $params
|
||||
* @param \Base $f3
|
||||
* @param array $params
|
||||
*/
|
||||
public function constellationData($f3, $params){
|
||||
|
||||
public function constellationData(\Base $f3, $params){
|
||||
$return = (object) [];
|
||||
$return->error = [];
|
||||
$return->systemData = [];
|
||||
|
||||
$constellationId = 0;
|
||||
$activeCharacter = $this->getCharacter();
|
||||
|
||||
$user = $this->_getUser();
|
||||
|
||||
if($user){
|
||||
if($activeCharacter){
|
||||
// check for search parameter
|
||||
if( isset($params['arg1']) ){
|
||||
$constellationId = (int)$params['arg1'];
|
||||
}
|
||||
|
||||
$cacheKey = 'CACHE_CONSTELLATION_SYSTEMS_' . self::formatHiveKey($constellationId);
|
||||
|
||||
if($f3->exists($cacheKey)){
|
||||
@@ -361,7 +334,29 @@ class System extends \Controller\AccessController {
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete systems and all its connections
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function delete(\Base $f3){
|
||||
$systemIds = $f3->get('POST.systemIds');
|
||||
$activeCharacter = $this->getCharacter();
|
||||
|
||||
if($activeCharacter){
|
||||
$user = $activeCharacter->getUser();
|
||||
/**
|
||||
* @var Model\SystemModel $system
|
||||
*/
|
||||
$system = Model\BasicModel::getNew('SystemModel');
|
||||
foreach((array)$systemIds as $systemId){
|
||||
$system->getById($systemId);
|
||||
$system->delete($user);
|
||||
$system->reset();
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode([]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,87 +15,76 @@ use DB;
|
||||
|
||||
class User extends Controller\Controller{
|
||||
|
||||
// user specific session keys
|
||||
const SESSION_KEY_USER = 'SESSION.USER';
|
||||
const SESSION_KEY_USER_ID = 'SESSION.USER.ID';
|
||||
const SESSION_KEY_USER_NAME = 'SESSION.USER.NAME';
|
||||
|
||||
// character specific session keys
|
||||
const SESSION_KEY_CHARACTER = 'SESSION.CHARACTER';
|
||||
const SESSION_KEY_CHARACTER_ID = 'SESSION.CHARACTER.ID';
|
||||
const SESSION_KEY_CHARACTER_NAME = 'SESSION.CHARACTER.NAME';
|
||||
const SESSION_KEY_CHARACTER_TIME = 'SESSION.CHARACTER.TIME';
|
||||
|
||||
const SESSION_KEY_CHARACTER_ACCESS_TOKEN = 'SESSION.CHARACTER.ACCESS_TOKEN';
|
||||
const SESSION_KEY_CHARACTER_REFRESH_TOKEN = 'SESSION.CHARACTER.REFRESH_TOKEN';
|
||||
|
||||
// log text
|
||||
const LOG_LOGGED_IN = 'userId: %s, userName: %s, charId: %s, charName: %s';
|
||||
|
||||
/**
|
||||
* valid reasons for captcha images
|
||||
* @var array
|
||||
* @var string array
|
||||
*/
|
||||
private static $captchaReason = ['createAccount', 'deleteAccount'];
|
||||
|
||||
/**
|
||||
* login function
|
||||
* @param $f3
|
||||
* login a valid character
|
||||
* @param Model\CharacterModel $characterModel
|
||||
* @return bool
|
||||
*/
|
||||
public function logIn($f3){
|
||||
$data = $data = $f3->get('POST');
|
||||
protected function loginByCharacter(Model\CharacterModel &$characterModel){
|
||||
$login = false;
|
||||
|
||||
$return = (object) [];
|
||||
|
||||
$user = null;
|
||||
|
||||
if($data['loginData']){
|
||||
$loginData = $data['loginData'];
|
||||
$user = $this->logUserIn( $loginData['userName'], $loginData['userPassword'] );
|
||||
}
|
||||
|
||||
// set "vague" error
|
||||
if(is_null($user)){
|
||||
$return->error = [];
|
||||
$loginError = (object) [];
|
||||
$loginError->type = 'login';
|
||||
$return->error[] = $loginError;
|
||||
}else{
|
||||
// update/check api data
|
||||
$user->updateApiData();
|
||||
|
||||
// route user to map app
|
||||
$return->reroute = rtrim(self::getEnvironmentData('URL'), '/') . $f3->alias('map');
|
||||
}
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* core function for user login
|
||||
* @param $userName
|
||||
* @param $password
|
||||
* @return Model\UserModel|null
|
||||
*/
|
||||
private function logUserIn($userName, $password){
|
||||
|
||||
// try to verify user
|
||||
$user = $this->_verifyUser($userName, $password);
|
||||
|
||||
if( !is_null($user)){
|
||||
// user is verified -> ready for login
|
||||
|
||||
// set Session login
|
||||
$dateTime = new \DateTime();
|
||||
|
||||
$this->f3->set('SESSION.user', [
|
||||
'time' => $dateTime->getTimestamp(),
|
||||
'name' => $user->name,
|
||||
'id' => $user->id
|
||||
if($user = $characterModel->getUser()){
|
||||
// set user/character data to session -------------------
|
||||
$this->f3->set(self::SESSION_KEY_USER, [
|
||||
'ID' => $user->_id,
|
||||
'NAME' => $user->name
|
||||
]);
|
||||
|
||||
// save user login information
|
||||
$user->touch('lastLogin');
|
||||
$user->save();
|
||||
$dateTime = new \DateTime();
|
||||
$this->f3->set(self::SESSION_KEY_CHARACTER, [
|
||||
'ID' => $characterModel->_id,
|
||||
'NAME' => $characterModel->name,
|
||||
'TIME' => $dateTime->getTimestamp()
|
||||
]);
|
||||
|
||||
// save log
|
||||
$logText = "id: %s, name: %s, ip: %s";
|
||||
// save user login information ---------------------------
|
||||
$characterModel->touch('lastLogin');
|
||||
$characterModel->save();
|
||||
|
||||
// write login log --------------------------------------
|
||||
self::getLogger( $this->f3->get('PATHFINDER.LOGFILES.LOGIN') )->write(
|
||||
sprintf($logText, $user->id, $user->name, $this->f3->get('IP'))
|
||||
sprintf(self::LOG_LOGGED_IN,
|
||||
$user->_id,
|
||||
$user->name,
|
||||
$characterModel->_id,
|
||||
$characterModel->name
|
||||
)
|
||||
);
|
||||
|
||||
$login = true;
|
||||
}
|
||||
|
||||
return $user;
|
||||
return $login;
|
||||
}
|
||||
|
||||
/**
|
||||
* get captcha image and store key to session
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function getCaptcha($f3){
|
||||
public function getCaptcha(\Base $f3){
|
||||
$data = $f3->get('POST');
|
||||
|
||||
$return = (object) [];
|
||||
@@ -136,29 +125,22 @@ class User extends Controller\Controller{
|
||||
|
||||
/**
|
||||
* delete the character log entry for the current active (main) character
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function deleteLog($f3){
|
||||
|
||||
$user = $this->_getUser();
|
||||
if($user){
|
||||
$activeUserCharacter = $user->getActiveUserCharacter();
|
||||
|
||||
if($activeUserCharacter){
|
||||
$character = $activeUserCharacter->getCharacter();
|
||||
|
||||
if($characterLog = $character->getLog()){
|
||||
$characterLog->erase();
|
||||
}
|
||||
public function deleteLog(\Base $f3){
|
||||
$activeCharacter = $this->getCharacter();
|
||||
if($activeCharacter){
|
||||
if($characterLog = $activeCharacter->getLog()){
|
||||
$characterLog->erase();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* log the current user out + clear character system log data
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function logOut($f3){
|
||||
public function logOut(\Base $f3){
|
||||
$this->deleteLog($f3);
|
||||
parent::logOut($f3);
|
||||
}
|
||||
@@ -166,9 +148,9 @@ class User extends Controller\Controller{
|
||||
/**
|
||||
* save/update "map sharing" configurations for all map types
|
||||
* the user has access to
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function saveSharingConfig($f3){
|
||||
public function saveSharingConfig(\Base $f3){
|
||||
$data = $f3->get('POST');
|
||||
|
||||
$return = (object) [];
|
||||
@@ -177,9 +159,10 @@ class User extends Controller\Controller{
|
||||
$corporationSharing = 0;
|
||||
$allianceSharing = 0;
|
||||
|
||||
$user = $this->_getUser();
|
||||
$activeCharacter = $this->getCharacter();
|
||||
|
||||
if($user){
|
||||
if($activeCharacter){
|
||||
$user = $activeCharacter->getUser();
|
||||
|
||||
// form values
|
||||
if(isset($data['formData'])){
|
||||
@@ -202,22 +185,17 @@ class User extends Controller\Controller{
|
||||
$user->save();
|
||||
|
||||
// update corp/ally ---------------------------------------------------------------
|
||||
$corporation = $activeCharacter->getCorporation();
|
||||
$alliance = $activeCharacter->getAlliance();
|
||||
|
||||
$activeUserCharacter = $user->getActiveUserCharacter();
|
||||
if(is_object($corporation)){
|
||||
$corporation->shared = $corporationSharing;
|
||||
$corporation->save();
|
||||
}
|
||||
|
||||
if(is_object($activeUserCharacter)){
|
||||
$corporation = $activeUserCharacter->getCharacter()->getCorporation();
|
||||
$alliance = $activeUserCharacter->getCharacter()->getAlliance();
|
||||
|
||||
if(is_object($corporation)){
|
||||
$corporation->shared = $corporationSharing;
|
||||
$corporation->save();
|
||||
}
|
||||
|
||||
if(is_object($alliance)){
|
||||
$alliance->shared = $allianceSharing;
|
||||
$alliance->save();
|
||||
}
|
||||
if(is_object($alliance)){
|
||||
$alliance->shared = $allianceSharing;
|
||||
$alliance->save();
|
||||
}
|
||||
|
||||
$return->userData = $user->getData();
|
||||
@@ -282,9 +260,9 @@ class User extends Controller\Controller{
|
||||
|
||||
/**
|
||||
* save/update user account data
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function saveAccount($f3){
|
||||
public function saveAccount(\Base $f3){
|
||||
$data = $f3->get('POST');
|
||||
|
||||
$return = (object) [];
|
||||
@@ -308,7 +286,8 @@ class User extends Controller\Controller{
|
||||
$settingsData = $data['settingsData'];
|
||||
|
||||
try{
|
||||
$user = $this->_getUser(0);
|
||||
$activeCharacter = $this->getCharacter(0);
|
||||
$user = $activeCharacter->getUser();
|
||||
|
||||
// captcha is send -> check captcha
|
||||
if(
|
||||
@@ -320,7 +299,7 @@ class User extends Controller\Controller{
|
||||
if($settingsData['captcha'] === $captcha){
|
||||
// change/set sensitive user data requires captcha!
|
||||
|
||||
if($user === false){
|
||||
if(is_null($user)){
|
||||
|
||||
// check if registration key invite function is enabled
|
||||
if($f3->get('PATHFINDER.REGISTRATION.INVITE') === 1 ){
|
||||
@@ -332,7 +311,7 @@ class User extends Controller\Controller{
|
||||
}
|
||||
|
||||
// new user registration
|
||||
$user = $mapType = Model\BasicModel::getNew('UserModel');
|
||||
$user = Model\BasicModel::getNew('UserModel');
|
||||
$loginAfterSave = true;
|
||||
|
||||
// set username
|
||||
@@ -429,7 +408,7 @@ class User extends Controller\Controller{
|
||||
}
|
||||
|
||||
// get fresh updated user object (API info may have has changed)
|
||||
$user = $this->_getUser(0);
|
||||
//$user = $this->_getUser(0);
|
||||
}
|
||||
|
||||
// set main character
|
||||
@@ -457,14 +436,13 @@ class User extends Controller\Controller{
|
||||
|
||||
// log user in (in case he is new
|
||||
if($loginAfterSave){
|
||||
$this->logUserIn( $user->name, $settingsData['password'] );
|
||||
$this->logInByData( $user->name, $settingsData['password'] );
|
||||
|
||||
// return reroute path
|
||||
$return->reroute = rtrim(self::getEnvironmentData('URL'), '/') . $this->f3->alias('map');
|
||||
}
|
||||
|
||||
// get fresh updated user object
|
||||
$user = $this->_getUser(0);
|
||||
$newUserData = $user->getData();
|
||||
}
|
||||
}catch(Exception\ValidationException $e){
|
||||
@@ -491,10 +469,10 @@ class User extends Controller\Controller{
|
||||
/**
|
||||
* send mail with registration key
|
||||
* -> check INVITE in pathfinder.ini
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendInvite($f3){
|
||||
public function sendInvite(\Base $f3){
|
||||
$data = $f3->get('POST.settingsData');
|
||||
$return = (object) [];
|
||||
|
||||
@@ -593,9 +571,9 @@ class User extends Controller\Controller{
|
||||
|
||||
/**
|
||||
* delete current user account from DB
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function deleteAccount($f3){
|
||||
public function deleteAccount(\Base $f3){
|
||||
$data = $f3->get('POST.formData');
|
||||
$return = (object) [];
|
||||
|
||||
@@ -609,8 +587,8 @@ class User extends Controller\Controller{
|
||||
!empty($data['captcha']) &&
|
||||
$data['captcha'] === $captcha
|
||||
){
|
||||
$user = $this->_getUser(0);
|
||||
|
||||
$activeCharacter = $this->getCharacter(0);
|
||||
$user = $activeCharacter->getUser();
|
||||
$validUser = $this->_verifyUser( $user->name, $data['password']);
|
||||
|
||||
if(
|
||||
|
||||
Reference in New Issue
Block a user