public function myKingboard(array $parameters) { $user = Kingboard_Auth::getUser(); $activeKeys = false; $pendingKeys = false; $context = array(); if (isset($_POST['XSRF']) && Kingboard_Form::getXSRFToken() == $_POST['XSRF']) { try { $pheal = new Pheal($_POST['apiuserid'], $_POST['apikey']); $pheal->accountScope->AccountStatus(); if (!isset($user['keys'])) { $keys = array(); } else { $keys = $user['keys']; } // ensure to remove existing activation keys if this is an update if ($activationkey = Kingboard_ApiActivationToken::findOneByUseridAndApiUserid($user->_id, $_POST['apiuserid'])) { $activationkey->delete(); } $activationkey = Kingboard_ApiActivationToken::create($user->_id, $_POST['apiuserid']); $keys[$_POST['apiuserid']] = array('apiuserid' => $_POST['apiuserid'], 'apikey' => $_POST['apikey'], 'active' => false); $user['keys'] = $keys; $user->save(); // ensure user is refreshed in session Kingboard_Auth::getUser(); } catch (PhealApiException $e) { $context = $_POST; $context['error'] = "the key could not be validated as a full apikey"; } } elseif (isset($_POST['XSRF'])) { die('XSRF detected'); } if (isset($user['keys'])) { foreach ($user['keys'] as $key) { if ($key['active']) { if (!is_array($activeKeys)) { $activeKeys = array(); } $activeKeys[] = $key; } else { if (!is_array($pendingKeys)) { $pendingKeys = array(); } $key['activationkey'] = (string) Kingboard_ApiActivationToken::findOneByUseridAndApiUserid($user->_id, $key['apiuserid']); $pendingKeys[] = $key; } } } $charkeylist = array(); foreach ($activeKeys as $key) { $pheal = new Pheal($key['apiuserid'], $key['apikey']); $chars = $pheal->accountScope->Characters()->characters->toArray(); foreach ($chars as $char) { $charkeylist[$key['apiuserid'] . "|" . $char['characterID']] = $char['name']; } } $context = array_merge($context, array('active_keys' => $activeKeys, 'pending_keys' => $pendingKeys, 'apimailreceiver' => King23_Registry::getInstance()->apimailreceiver, 'active_characters' => $charkeylist)); $this->render('user/index.html', $context); }
public function __construct($loginrequired = false) { if ($loginrequired && !Kingboard_Auth::isLoggedIn()) { $this->redirect("/login"); } parent::__construct(); $reg = King23_Registry::getInstance(); $this->_context['images'] = $reg->imagePaths; $this->_context['baseHost'] = $reg->baseHost; // ownerID, if this is an owned board, this should be filled, for public boards this doesn't matter $this->_context['ownerID'] = $reg->ownerID; // when user is logged in we provide user object to all pages, false otherwise $this->_context['user'] = Kingboard_Auth::getUser(); // make sure all views have the XSRF Token available $this->_context['XSRF'] = Kingboard_Form::getXSRFToken(); }
public function create(array $params) { if (!Kingboard_BattleCreate_Form::validate($_POST)) { // @todo handle invalid die; } $user = Kingboard_Auth::getUser(); list($key, $character) = explode('|', $_POST['character']); $key = $user["keys"][$key]; $pheal = new Pheal($key['apiuserid'], $key['apikey'], 'corp'); $contacts = $pheal->ContactList(array('characterID' => $character)); $positives = array(); foreach ($contacts->corporateContactList as $contact) { // accumulate postive standings if ($contact->standing > 0) { $positives[$contact->contactID] = $contact->contactName; } } // alliance standings override corp standings foreach ($contacts->allianceContactList as $contact) { if ($contact->standing > 0) { $positives[$contact->contactID] = $contact->contactName; } else { // negative standings, we only need those if corp has positive, but alliance negative if (isset($positives[$contact->contactID])) { unset($positives[$contact->contactID]); } } } $battleSetting = new Kingboard_BattleSettings(); $battleSetting->startdate = new MongoDate(strtotime($_POST['startdate'])); $battleSetting->user = $user->_id; $battleSetting->enddate = new MongoDate(strtotime($_POST['enddate'])); $battleSetting->system = $_POST['system']; $battleSetting->key = $key; $battleSetting->character = $character; $battleSetting->positives = $positives; $battleSetting->runs = 0; $battleSetting->nextRun = new MongoDate(time()); $battleSetting->save(); // we are done here, lets redirect to the battle! $this->redirect("/battle/" . $battleSetting->_id); }
public function logout($request) { Kingboard_Auth::logout(); $this->redirect("/"); }