/** * @return bool Is user logged into ThinkUp an admin */ public static function isAdmin() { if (SessionCache::isKeySet('user_is_admin')) { return SessionCache::get('user_is_admin'); } else { return false; } }
public static function isSuperAdmin() { if (SessionCache::isKeySet('user_type')) { $config = App::getInstance('UserType'); //Profiler::debugPoint(true,__METHOD__, __FILE__, __LINE__); if (SessionCache::get('user_type') == $config->getValue('SUPER_ADMIN')) { return true; } } else { return false; } }
public function __construct($session_started = false) { parent::__construct($session_started); $config = Config::getInstance(); Loader::definePathConstants(); $this->setViewTemplate(THINKUP_WEBAPP_PATH . 'plugins/twitter/view/auth.tpl'); $this->setPageTitle('Authorizing Your Twitter Account'); if (!isset($_GET['oauth_token']) || $_GET['oauth_token'] == '') { $this->addInfoMessage('No OAuth token specified.'); $this->is_missing_param = true; } if (!SessionCache::isKeySet('oauth_request_token_secret') || SessionCache::get('oauth_request_token_secret') == '') { $this->addInfoMessage('Secret token not set.'); $this->is_missing_param = true; } }
public function authControl() { if (!$this->is_missing_param) { $username = $_GET['u']; $network = $_GET['n']; $user_dao = DAOFactory::getDAO('UserDAO'); $page = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1; if ($user_dao->isUserInDBByName($username, $network)) { $this->setPageTitle('User Details: ' . $username); $user = $user_dao->getUserByName($username, $network); $owner_dao = DAOFactory::getDAO('OwnerDAO'); $owner = $owner_dao->getByEmail($this->getLoggedInUser()); $instance_dao = DAOFactory::getDAO('InstanceDAO'); $this->addToView('instances', $instance_dao->getByOwner($owner)); $this->addToView('profile', $user); $post_dao = DAOFactory::getDAO('PostDAO'); $user_posts = $post_dao->getAllPosts($user->user_id, $user->network, 20, $page); $this->addToView('user_statuses', $user_posts); if (sizeof($user_posts) == 20) { $this->addToView('next_page', $page + 1); } $this->addToView('last_page', $page - 1); $this->addToView('sources', $post_dao->getStatusSources($user->user_id, $user->network)); if (SessionCache::isKeySet('selected_instance_username') && SessionCache::isKeySet('selected_instance_network')) { $i = $instance_dao->getByUsername(SessionCache::get('selected_instance_username'), SessionCache::get('selected_instance_network')); if (isset($i)) { $this->addToView('instance', $i); $exchanges = $post_dao->getExchangesBetweenUsers($i->network_user_id, $i->network, $user->user_id); $this->addToView('exchanges', $exchanges); $this->addToView('total_exchanges', count($exchanges)); $follow_dao = DAOFactory::getDAO('FollowDAO'); $mutual_friends = $follow_dao->getMutualFriends($user->user_id, $i->network_user_id, $i->network); $this->addToView('mutual_friends', $mutual_friends); $this->addToView('total_mutual_friends', count($mutual_friends)); } } } else { $this->addErrorMessage($username . ' is not in the system.'); } } return $this->generateView(); }
public function testPutGetIsset() { $config = Config::getInstance(); //nothing is set $this->assertNull(SessionCache::get('my_key')); $this->assertFalse(SessionCache::isKeySet('my_key')); //set a key SessionCache::put('my_key', 'my_value'); $this->assertTrue(isset($_SESSION[$config->getValue('source_root_path')])); $this->assertEqual($_SESSION[$config->getValue('source_root_path')]['my_key'], 'my_value'); $this->assertEqual(SessionCache::get('my_key'), 'my_value'); //overwrite existing key SessionCache::put('my_key', 'my_value2'); $this->assertTrue($_SESSION[$config->getValue('source_root_path')]['my_key'] != 'my_value'); $this->assertEqual($_SESSION[$config->getValue('source_root_path')]['my_key'], 'my_value2'); //set another key SessionCache::put('my_key2', 'my_other_value'); $this->assertEqual($_SESSION[$config->getValue('source_root_path')]['my_key2'], 'my_other_value'); //unset first key SessionCache::unsetKey('my_key'); $this->assertNull(SessionCache::get('my_key')); $this->assertFalse(SessionCache::isKeySet('my_key')); }
/** * Sets/deletes in the session to let us know we needed to run the Snowflake migration. * @param bool $delete Delete the session if true * @param mixed $value Session value, defaults to false * @return mixed Boolean true if successful, else contents of session key */ public function setSnowflakeSession($value = false, $delete = false) { $key = 'runnig_snowflake_uprade'; if ($delete) { if (SessionCache::isKeySet($key)) { SessionCache::unsetKey($key); return true; } } else { if ($value) { SessionCache::put($key, $value); return true; } else { if (SessionCache::isKeySet($key)) { return SessionCache::get($key); } else { return false; } } } return false; }
public function testSession() { $optiondao = new OptionMySQLDAO(); $config = Config::getInstance(); $app_path = $config->getValue('source_root_path'); // set session data $optiondao->setSessionData('bla', array('name' => 'value')); $key = 'options_data:bla'; $this->assertIdentical(array('name' => 'value'), SessionCache::get($key)); // clear session data $optiondao->clearSessionData('bla'); $this->assertFalse(SessionCache::isKeySet($key)); // get session data $this->assertFalse($optiondao->getSessionData('bla')); // no data // with data SessionCache::put($key, array('name' => 'value')); $this->assertIdentical(array('name' => 'value'), $optiondao->getSessionData('bla')); // test updates $data1 = array('namespace' => 'test', 'option_name' => 'testname', 'option_value' => 'test_value'); $builder1 = FixtureBuilder::build(self::TEST_TABLE, $data1); $options = $optiondao->getOptions('test'); $this->assertNotNull($options); # update by name $optiondao->updateOptionByName('test', 'testname', 'test_value123'); $options = $optiondao->getOptions('test'); $this->assertEqual($options['testname']->option_value, 'test_value123'); # update by id $optiondao->updateOption($options['testname']->option_id, 'test_value1234'); $options = $optiondao->getOptions('test'); $this->assertEqual($options['testname']->option_value, 'test_value1234'); # delete by name $optiondao->deleteOptionByName('test', 'testname'); $options = $optiondao->getOptions('test'); $this->assertNull($options); # delete by id $builder1 = null; $builder1 = FixtureBuilder::build(self::TEST_TABLE, $data1); $optiondao->deleteOption($builder1->columns['last_insert_id']); $options = $optiondao->getOptions('test'); $this->assertNull($options); }
/** * Constructs ThinkUpController * * Adds email address of currently logged in ThinkUp user, '' if not logged in, to view * {$logged_in_user} * @return ThinkUpController */ public function __construct($session_started = false) { try { $config = Config::getInstance(); $this->profiler_enabled = Profiler::isEnabled(); if ($this->profiler_enabled) { $this->start_time = microtime(true); } if ($config->getValue('timezone')) { date_default_timezone_set($config->getValue('timezone')); } if (!$session_started) { SessionCache::init(); } $this->view_mgr = new ViewManager(); if (SessionCache::isKeySet('selected_instance_network') && SessionCache::isKeySet('selected_instance_username')) { $this->addToView('selected_instance_network', SessionCache::get('selected_instance_network')); $this->addToView('selected_instance_username', SessionCache::get('selected_instance_username')); } if ($this->isLoggedIn()) { $this->addToView('logged_in_user', $this->getLoggedInUser()); } if ($this->isAdmin()) { $this->addToView('user_is_admin', true); } $THINKUP_VERSION = $config->getValue('THINKUP_VERSION'); $this->addToView('thinkup_version', $THINKUP_VERSION); } catch (Exception $e) { Loader::definePathConstants(); //echo 'sending this to Smarty:'.THINKUP_WEBAPP_PATH.'data/'; $cfg_array = array('site_root_path' => Utils::getSiteRootPathFromFileSystem(), 'source_root_path' => THINKUP_ROOT_PATH, 'datadir_path' => THINKUP_WEBAPP_PATH . 'data/', 'debug' => false, 'app_title_prefix' => "", 'cache_pages' => false); $this->view_mgr = new ViewManager($cfg_array); } }
public function testProcessSnowflakeMigration() { $config = Config::getInstance(); $app_path = $config->getValue('source_root_path'); $snowflakekey = 'runnig_snowflake_uprade'; // no snowflake update needed... $this->pdo->query("truncate table " . $this->table_prefix . "options"); $this->simulateLogin('*****@*****.**', true); $this->assertFalse(SessionCache::isKeySet($snowflakekey)); $config = Config::getInstance(); $config->setValue('THINKUP_VERSION', '0.4'); $controller = new UpgradeDatabaseController(true); $results = $controller->go(); //print $results; $this->assertPattern('/needs 1 database update/', $results); // snowflake update needed... $this->pdo->query("drop table " . $this->table_prefix . "options"); $this->testdb_helper->runSQL('ALTER TABLE ' . $this->table_prefix . 'instances CHANGE last_post_id last_status_id bigint(11) NOT NULL'); $this->testdb_helper->runSQL('ALTER TABLE ' . $this->table_prefix . 'links ADD post_id BIGINT( 20 ) NOT NULL,' . 'ADD network VARCHAR( 20 ) NOT NULL'); $controller = new UpgradeDatabaseController(true); $results = $controller->go(); $this->assertPattern('/needs 2 database updates/', $results); $v_mgr = $controller->getViewManager(); $queries = $v_mgr->getTemplateDataItem('migrations'); $this->assertEqual(2, count($queries), 'two migration queries'); $this->assertTrue(SessionCache::isKeySet($snowflakekey)); // run snowflake migration $_GET['migration_index'] = 1; $controller = new UpgradeDatabaseController(true); $results = $controller->go(); $obj = json_decode($results); $this->assertTrue($obj->processed); $stmt = $this->pdo->query("desc " . $this->table_prefix . "instances last_post_id"); $data = $stmt->fetch(); $this->assertEqual($data['Field'], 'last_post_id'); $this->assertPattern('/bigint\\(20\\)\\s+unsigned/i', $data['Type']); $this->assertTrue(SessionCache::isKeySet($snowflakekey)); // run version 4 upgrade $_GET['migration_index'] = 2; $controller = new UpgradeDatabaseController(true); $results = $controller->go(); $this->assertTrue($obj->processed); $stmt = $this->pdo->query("desc " . $this->table_prefix . "instances last_post_id"); $data = $stmt->fetch(); $this->assertEqual($data['Field'], 'last_post_id'); $this->assertPattern('/bigint\\(20\\)\\s+unsigned/i', $data['Type']); // no snowflake session data when complete $config = Config::getInstance(); unset($_GET['migration_index']); $_GET['migration_done'] = true; $results = $controller->go(); $obj = json_decode($results); $this->assertTrue($obj->migration_complete); $this->assertFalse(SessionCache::isKeySet($snowflakekey)); }
/** * Constructs ThinkUpController * * Adds email address of currently logged in ThinkUp user, '' if not logged in, to view * {$logged_in_user} * @return ThinkUpController */ public function __construct($session_started = false) { if (!$session_started) { session_start(); } try { $config = Config::getInstance(); $this->profiler_enabled = Profiler::isEnabled(); if ($this->profiler_enabled) { $this->start_time = microtime(true); } $this->view_mgr = new SmartyThinkUp(); if ($this->isLoggedIn()) { $this->addToView('logged_in_user', $this->getLoggedInUser()); } if ($this->isAdmin()) { $this->addToView('user_is_admin', true); } $THINKUP_VERSION = $config->getValue('THINKUP_VERSION'); $this->addToView('thinkup_version', $THINKUP_VERSION); if (SessionCache::isKeySet('selected_instance_network') && SessionCache::isKeySet('selected_instance_username')) { $this->addToView('selected_instance_network', SessionCache::get('selected_instance_network')); $this->addToView('selected_instance_username', SessionCache::get('selected_instance_username')); $this->addToView('logo_link', '?u=' . urlencode(SessionCache::get('selected_instance_username')) . '&n=' . urlencode(SessionCache::get('selected_instance_network'))); } } catch (Exception $e) { Utils::defineConstants(); $cfg_array = array('site_root_path' => THINKUP_BASE_URL, 'source_root_path' => THINKUP_ROOT_PATH, 'debug' => false, 'app_title' => "ThinkUp", 'cache_pages' => false); $this->view_mgr = new SmartyThinkUp($cfg_array); } }
/** * Clears session data by namespace * @param $namespace */ public function clearSessionData($namespace) { $key = 'options_data:' . $namespace; if (SessionCache::isKeySet($key)) { SessionCache::unsetKey($key); } }
/** * Constructs ThinkUpController * * Adds email address of currently logged in ThinkUp user, '' if not logged in, to view * {$logged_in_user} * @return ThinkUpController */ public function __construct($session_started = false) { try { $config = Config::getInstance(); $this->profiler_enabled = Profiler::isEnabled(); if ($this->profiler_enabled) { $this->start_time = microtime(true); } if ($config->getValue('timezone')) { date_default_timezone_set($config->getValue('timezone')); } if (!$session_started) { SessionCache::init(); } $this->view_mgr = new ViewManager(); if (SessionCache::isKeySet('selected_instance_network') && SessionCache::isKeySet('selected_instance_username')) { $this->addToView('selected_instance_network', SessionCache::get('selected_instance_network')); $this->addToView('selected_instance_username', SessionCache::get('selected_instance_username')); } if ($this->isLoggedIn()) { $this->addToView('logged_in_user', $this->getLoggedInUser()); } if ($this->isAdmin()) { $this->addToView('user_is_admin', true); } $THINKUP_VERSION = $config->getValue('THINKUP_VERSION'); $this->addToView('thinkup_version', $THINKUP_VERSION); if (Utils::isThinkUpLLC()) { $thinkupllc_endpoint = $config->getValue('thinkupllc_endpoint'); $this->addToView('thinkupllc_endpoint', $thinkupllc_endpoint); } if (SessionCache::isKeySet('selected_instance_network') && SessionCache::isKeySet('selected_instance_username')) { $this->addToView('selected_instance_network', SessionCache::get('selected_instance_network')); $this->addToView('selected_instance_username', SessionCache::get('selected_instance_username')); } } catch (Exception $e) { Loader::definePathConstants(); //echo 'sending this to Smarty:'.THINKUP_WEBAPP_PATH.'data/'; $cfg_array = array('site_root_path' => Utils::getSiteRootPathFromFileSystem(), 'source_root_path' => THINKUP_ROOT_PATH, 'datadir_path' => THINKUP_WEBAPP_PATH . 'data/', 'debug' => false, 'app_title_prefix' => "", 'cache_pages' => false); $this->view_mgr = new ViewManager($cfg_array); $this->setErrorTemplateState(); $this->addToView('error_type', get_class($e)); $disable_xss = false; // if we are an installer exception, don't filter XSS, we have markup, and we trust this content if (get_class($e) == 'InstallerException') { $disable_xss = true; } $this->addErrorMessage($e->getMessage(), null, $disable_xss); } }
/** * Add user who just returned from Twitter.com OAuth authorization and populate view with error/success messages. * @param str $oauth_consumer_key * @param str $oauth_consumer_secret * @param str $num_twitter_errors * @return void */ private function addAuthorizedUser($oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors) { if (isset($_GET['oauth_token']) && SessionCache::isKeySet('oauth_request_token_secret')) { $request_token = $_GET['oauth_token']; $request_token_secret = SessionCache::get('oauth_request_token_secret'); $twitter_oauth = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret, $request_token, $request_token_secret); if (isset($_GET['oauth_verifier'])) { $tok = $twitter_oauth->getAccessToken($_GET['oauth_verifier']); } else { $tok = null; } if (isset($tok['oauth_token']) && isset($tok['oauth_token_secret'])) { $api = new TwitterAPIAccessorOAuth($tok['oauth_token'], $tok['oauth_token_secret'], $oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors, false); $authed_twitter_user = $api->verifyCredentials(); // echo "User ID: ". $authed_twitter_user['user_id']."<br>"; // echo "User name: ". $authed_twitter_user['user_name']."<br>"; $owner_dao = DAOFactory::getDAO('OwnerDAO'); $owner = $owner_dao->getByEmail($this->getLoggedInUser()); if (isset($authed_twitter_user) && isset($authed_twitter_user['user_name']) && isset($authed_twitter_user['user_id'])) { $instance_dao = DAOFactory::getDAO('TwitterInstanceDAO'); $instance = $instance_dao->getByUsername($authed_twitter_user['user_name'], 'twitter'); $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO'); if (isset($instance)) { $owner_instance = $owner_instance_dao->get($owner->id, $instance->id); if ($owner_instance != null) { $owner_instance_dao->updateTokens($owner->id, $instance->id, $tok['oauth_token'], $tok['oauth_token_secret']); $this->addSuccessMessage($authed_twitter_user['user_name'] . " on Twitter is already set up in ThinkUp! To add a different Twitter account, " . "log out of Twitter.com in your browser and authorize ThinkUp again.", 'user_add'); } else { if ($owner_instance_dao->insert($owner->id, $instance->id, $tok['oauth_token'], $tok['oauth_token_secret'])) { $this->addSuccessMessage("Success! " . $authed_twitter_user['user_name'] . " on Twitter has been added to ThinkUp!", "user_add"); } else { $this->addErrorMessage("Error: Could not create an owner instance.", "user_add"); } } } else { $instance_dao->insert($authed_twitter_user['user_id'], $authed_twitter_user['user_name']); $instance = $instance_dao->getByUsername($authed_twitter_user['user_name']); if ($owner_instance_dao->insert($owner->id, $instance->id, $tok['oauth_token'], $tok['oauth_token_secret'])) { $this->addSuccessMessage("Success! " . $authed_twitter_user['user_name'] . " on Twitter has been added to ThinkUp!", "user_add"); } else { $this->addErrorMessage("Error: Could not create an owner instance.", "user_add"); } } } } else { $msg = "Error: Twitter authorization did not complete successfully. Check if your account already " . " exists. If not, please try again."; $this->addErrorMessage($msg, "user_add"); } $this->view_mgr->clear_all_cache(); } }
/** * Constructs EFCController * * Adds email address of currently logged in EFC user, '' if not logged in, to view * {$logged_in_user} * @return EFCController */ public function __construct($session_started = false) { try { //$this->baseMem = memory_get_usage(true); $this->redis = new Redis(); $this->redis->connect('127.0.0.1', 6379); $this->memcache = new Memcache(); $this->memcache->connect('127.0.0.1', 11211); $config = Config::getInstance(); $this->profiler_enabled = Profiler::isEnabled(); if ($this->profiler_enabled) { $this->start_time = microtime(true); } if ($config->getValue('timezone')) { date_default_timezone_set($config->getValue('timezone')); } if (!$session_started) { SessionCache::init(); } $this->view_mgr = new ViewManager(); $this->facebook = new Facebook\Facebook(['app_id' => $config->getValue('fb_app_id'), 'app_secret' => $config->getValue('fb_app_secret'), 'default_graph_version' => 'v2.2']); if ($this->isLoggedIn()) { $this->addToView('logged_in_user', $this->getLoggedInUser()); } if ($this->isSuperAdmin()) { $this->addToView('user_is_admin', true); } $EFC_VERSION = $config->getValue('EFC_VERSION'); $this->addToView('EFC_VERSION', $EFC_VERSION); if (Utils::isEmpoddyLabs()) { $empoddy_endpoint = $config->getValue('empoddy_endpoint'); $this->addToView('empoddy_endpoint', $empoddy_endpoint); } if (SessionCache::isKeySet('selected_instance_network') && SessionCache::isKeySet('selected_instance_username')) { $this->addToView('selected_instance_network', SessionCache::get('selected_instance_network')); $this->addToView('selected_instance_username', SessionCache::get('selected_instance_username')); } } catch (Exception $e) { Loader::definePathConstants(); //echo 'sending this to Smarty:'.EFC_WEBAPP_PATH.'data/'; $cfg_array = array('site_root_path' => Utils::getSiteRootPathFromFileSystem(), 'source_root_path' => EFC_ROOT_PATH, 'datadir_path' => EFC_WEBAPP_PATH . 'data/', 'debug' => false, 'app_title_prefix' => "", 'cache_pages' => false); $this->view_mgr = new ViewManager($cfg_array); $this->setErrorTemplateState(); $this->addToView('error_type', get_class($e)); $disable_xss = false; // if we are an installer exception, don't filter XSS, we have markup, and we trust this content if (get_class($e) == 'InstallerException') { $disable_xss = true; } $this->addErrorMessage($e->getMessage(), null, $disable_xss); } }