close #41 Added support for multiple API-Keys matching the same character

This commit is contained in:
Exodus4D
2015-10-05 20:57:28 +02:00
parent 413992b38e
commit 62654401ce
2 changed files with 18 additions and 11 deletions

View File

@@ -157,7 +157,7 @@ class UserModel extends BasicModel {
* @return array|FALSE
*/
public function getByName($name){
return $this->getByForeignKey('name', $name);
return $this->getByForeignKey('name', $name, [], 0);
}
/**
@@ -281,10 +281,11 @@ class UserModel extends BasicModel {
$userCharacter->save();
}
// set random main character
if(! $mainSet ){
$userCharacters[0]->setMain(1);
$userCharacters[0]->save();
// set first character as "main"
if( !$mainSet ){
$userCharacter = reset($userCharacters);
$userCharacter->setMain(1);
$userCharacter->save();
}
}
}
@@ -299,6 +300,8 @@ class UserModel extends BasicModel {
$this->filter('apis', ['active = ?', 1]);
// if a user has multiple API keys saved for ONE character,
// skip double characters!
$userCharacters = [];
if($this->apis){
@@ -306,14 +309,18 @@ class UserModel extends BasicModel {
while($this->apis->valid()){
$this->apis->current()->filter('userCharacters', ['active = ?', 1]);
if($this->apis->current()->userCharacters){
$this->apis->current()->userCharacters->rewind();
while($this->apis->current()->userCharacters->valid()){
$userCharacters[] = $this->apis->current()->userCharacters->current();
$tempCharacterId = $this->apis->current()->userCharacters->current()->characterId->get('id');
if( !isset($userCharacters[ $tempCharacterId ]) ){
$userCharacters[ $tempCharacterId ] = $this->apis->current()->userCharacters->current();
}
$this->apis->current()->userCharacters->next();
}
}
$this->apis->next();
}
}
@@ -347,17 +354,17 @@ class UserModel extends BasicModel {
public function getActiveUserCharacter(){
$activeUserCharacter = null;
$apiController = Controller\CcpApiController::getIGBHeaderData();
$headerData = Controller\CcpApiController::getIGBHeaderData();
// check if IGB Data is available
if( !empty($apiController->values) ){
if( !empty($headerData->values) ){
// search for the active character by IGB Header Data
$this->filter('userCharacters',
[
'active = :active AND characterId = :characterId',
':active' => 1,
':characterId' => intval($apiController->values['charid'])
':characterId' => intval($headerData->values['charid'])
],
['limit' => 1]
);

View File

@@ -227,7 +227,7 @@
Don't have one? - Create a new key with an empty 'Access Mask'.
</p>
<small>Get your new/custom API Key from
<a href="https://support.eveonline.com/api" target="_blank">here</a>
<a href="https://community.eveonline.com/support/api-key/" target="_blank">here</a>
and come back to this page.
</small>
</blockquote>