public function key_activation(array $options) { $this->cli->header('updating key activates'); $reg = King23_Registry::getInstance(); $pheal = new Pheal($reg->apimailreceiverApiUserID, $reg->apimailreceiverApiKey, 'char'); $messages = $pheal->MailMessages(array('characterID' => $reg->apimailreceiverCharacterID))->messages; foreach ($messages as $message) { if ($message->toCharacterIDs != $reg->apimailreceiverCharacterID) { continue; } $token = trim($message->title); if (strlen($token) != Kingboard_ApiActivationToken::TOKEN_LENGTH) { continue; } if (!($token = Kingboard_ApiActivationToken::findOneByToken($token))) { continue; } $user = Kingboard_User::getById($token['userid']); $keys = $user['keys']; $apiuserid = $token['apiuserid']; $phealactivate = new Pheal($keys[$apiuserid]['apiuserid'], $keys[$apiuserid]['apikey']); $characters = $phealactivate->Characters()->characters; foreach ($characters as $character) { if ($character->characterID == $message->senderID) { $keys[$apiuserid]['active'] = true; $user['keys'] = $keys; $user->save(); $token->delete(); $body = King23_Registry::getInstance()->sith->cachedGet('mails/activate_apikey.html')->render(array('username' => $user['username'], 'apiuserid' => $apiuserid), King23_Registry::getInstance()->sith); mail($user['username'], "Kingboard API Key Activation", $body); break; } } } }
public function registerForm($request) { if (isset($_POST['XSRF'])) { if (Kingboard_Form::getXSRFToken() == $_POST['XSRF']) { if (!isset($_POST['passwd']) || !isset($_POST['passwd2']) || !isset($_POST['login'])) { $this->_context['registration_failed'] = 'Please fill in all fields'; } elseif ($_POST['passwd'] != $_POST['passwd2']) { $this->_context['registration_failed'] = 'both Password fields need to have the same value'; } elseif (!is_null(Kingboard_User::findOne(array('username' => $_POST['login'])))) { $this->_context['registration_failed'] = 'email/login allready in use'; } elseif (!Kingboard_Form::isEmail($_POST['login'])) { $this->_context['registration_failed'] = 'not a valid email adresse'; } else { $validationCode = sha1(mktime() . $_POST['login']); $user = new Kingboard_User(); $user->username = $_POST['login']; $user->password = $_POST['passwd']; $user->status = Kingboard_User::STATUS_NEW; $user->validationCode = $validationCode; $user->save(); $body = King23_Registry::getInstance()->sith->cachedGet('mails/verify_email.html')->render(array('username' => $_POST['login'], 'hostname' => $_SERVER['SERVER_NAME'], 'activationkey' => $validationCode), King23_Registry::getInstance()->sith); mail($_POST['login'], "Kingboard Activation", $body); $this->redirect('/'); } } else { $this->_context['registration_failed'] = 'XSRF Token Invalid.'; } } $this->render('user/registration.html', $_POST); }
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(); }
/** * setup all indexes for Kingboard * @param array $options * @return */ public function setup_indexes(array $options) { if (count($options) != 0) { $this->cli->error('this task takes no arguments'); return; } $reg = King23_Registry::getInstance(); $this->cli->message("Setting Killmail_Kill indexes"); // Kingboard_Kill indexes $col = $reg->mongo['db']->Kingboard_Kill; // idHash, index unique $col->ensureIndex(array('idHash' => 1), array("unique" => true)); // victim Names $col->ensureIndex(array('victim.characterName' => 1)); // attacker Names $col->ensureIndex(array('attackers.characterName' => 1)); // victim ID $col->ensureIndex(array('victim.characterID' => 1)); // attacker ID $col->ensureIndex(array('attackers.characterID' => 1)); // corporation victim id $col->ensureIndex(array('victim.corporationID' => 1)); // corporation attacker id $col->ensureIndex(array('attackers.corporationID' => 1)); // corporation victim name $col->ensureIndex(array('victim.corporationName' => 1)); // corporation attacker name $col->ensureIndex(array('attackers.corporationNAme' => 1)); // alliance victim id $col->ensureIndex(array('victim.allianceID' => 1)); // alliance attacker id $col->ensureIndex(array('attackers.allianceID' => 1)); // alliance victim name $col->ensureIndex(array('victim.allianceName' => 1)); // alliance attacker name $col->ensureIndex(array('attackers.allianceName' => 1)); // indexes for the battle queries // battle kills $col->ensureIndex(array('killTime' => 1, 'location.solarSystem' => 1, 'attackers.corporationID' => 1, 'attackers.allianceID' => 1, 'victim.corporationID' => 1, 'victim.allianceID' => 1)); // battle losses $col->ensureIndex(array('killTime' => 1, 'location.solarSystem' => 1, 'victim.corporationID' => 1, 'victim.allianceID' => 1)); // killtime Index $col->ensureIndex(array('killTime' => 1)); // location.solarSystem $col->ensureIndex(array('location.solarSystem' => 1)); $col->ensureIndex(array('killID' => 1)); $this->cli->message("Setting Killmail_EveItem indexes"); // Kingboard_EveItem $col = $reg->mongo['db']->Kingboard_EveItem; // typeID $col->ensureIndex(array('typeID' => 1), array('unique' => true)); // typeName $col->ensureIndex(array('typeName' => 1)); $this->cli->message("Setting Killmail_EveSolarSystem indexes"); // Kingboard_EveSolarSystem $col = $reg->mongo['db']->Kingboard_EveSolarSystem; // itemID $col->ensureIndex(array('itemID' => 1), array('unique' => true)); // itemName $col->ensureIndex(array('itemName' => 1)); }
<?php if (!defined("APP_PATH")) { define("APP_PATH", realpath(dirname(__FILE__) . "/..")); } King23_Classloader::init(APP_PATH . "/lib/King23/lib"); King23_Classloader::init(APP_PATH . "/views"); King23_Classloader::init(APP_PATH . "/lib/Kingboard"); King23_Classloader::init(APP_PATH . "/lib/PHPMarkdown"); King23_Classloader::init(APP_PATH . "/model"); $reg = King23_Registry::getInstance(); // set this to your host $reg->baseHost = "kings-of-eve.com"; $connection = new Mongo('localhost'); $reg->mongo = array('connection' => $connection, 'db' => $connection->Kingboard); King23_Classloader::init(APP_PATH . "/lib/Pheal"); $pc = PhealConfig::getInstance(); $pc->cache = new PhealFileCache(APP_PATH . "/cache/"); // Sith Template configuration require_once APP_PATH . "/lib/SithTemplate/lib/SithTemplate.php"; $reg->sith = new TemplateEnviron(array('inputPrefix' => APP_PATH . "/templates/", 'outputPrefix' => APP_PATH . "/templates_c/", 'loadPlugins' => true, 'useDefaultPluginsPath' => true, 'pluginsPaths' => array(APP_PATH . "/lib/Kingboard/SithPlugin/"), 'recompilationMode' => 1, 'defaultIODriver' => "file", 'autoEscape' => false)); $reg->imagePaths = array('ships' => 'http://image.eveonline.com/Render/', 'items' => 'http://image.eveonline.com/Type/', 'characters' => 'http://image.eveonline.com/Character/', 'corporations' => 'http://image.eveonline.com/Corporation/', 'alliances' => 'http://image.eveonline.com/Alliance/'); $reg->apimailreceiver = "CHARACTERNAME"; $reg->apimailreceiverCharacterID = 123456; $reg->apimailreceiverApiUserID = "123456"; $reg->apimailreceiverApiKey = "APIKEYHERE"; // this can be fetched from a specific ownerID provider // which maps host to id for example on hosted boards $reg->ownerID = 99000289; require_once "routes.php"; session_start();