php Piwik-Plugins-UsersManager-API类(方法)实例源码

下面列出了php Piwik-Plugins-UsersManager-API 类(方法)源码代码实例,从而了解它的用法。

作者:CaptainShar    项目:SSAD_Projec   
/**
  * Authenticates user
  *
  * @return AuthResult
  */
 public function authenticate()
 {
     if (!empty($this->md5Password)) {
         // favor authenticating by password
         $this->token_auth = UsersManagerAPI::getInstance()->getTokenAuth($this->login, $this->getTokenAuthSecret());
     }
     if (is_null($this->login)) {
         $model = new Model();
         $user = $model->getUserByTokenAuth($this->token_auth);
         if (!empty($user['login'])) {
             $code = $user['superuser_access'] ? AuthResult::SUCCESS_SUPERUSER_AUTH_CODE : AuthResult::SUCCESS;
             return new AuthResult($code, $user['login'], $this->token_auth);
         }
     } else {
         if (!empty($this->login)) {
             $model = new Model();
             $user = $model->getUser($this->login);
             if (!empty($user['token_auth']) && (SessionInitializer::getHashTokenAuth($this->login, $user['token_auth']) === $this->token_auth || $user['token_auth'] === $this->token_auth)) {
                 $this->setTokenAuth($user['token_auth']);
                 $code = !empty($user['superuser_access']) ? AuthResult::SUCCESS_SUPERUSER_AUTH_CODE : AuthResult::SUCCESS;
                 return new AuthResult($code, $this->login, $user['token_auth']);
             }
         }
     }
     return new AuthResult(AuthResult::FAILURE, $this->login, $this->token_auth);
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * @expectedException \Exception
  * @expectedExceptionMessage token_auth specified does not have Admin permission for idsite=1
  */
 public function test_authenticateRequests_shouldThrowAnException_IfTokenIsNotValid()
 {
     $dummyToken = API::getInstance()->getTokenAuth('test', UsersManager::getPasswordHash('2'));
     $superUserToken = $this->getSuperUserToken();
     $requests = array($this->buildDummyRequest($superUserToken), $this->buildDummyRequest($dummyToken));
     $this->requests->authenticateRequests($requests);
 }

作者:CaptainShar    项目:SSAD_Projec   
public function configureTopMenu(MenuTop $menu)
 {
     $login = Piwik::getCurrentUserLogin();
     $user = APIUsersManager::getInstance()->getUser($login);
     if (!empty($user['alias'])) {
         $login = $user['alias'];
     }
     if (Plugin\Manager::getInstance()->isPluginActivated('Feedback')) {
         $menu->addItem('General_Help', null, array('module' => 'Feedback', 'action' => 'index'));
     }
     if (Piwik::isUserIsAnonymous()) {
         if (Plugin\Manager::getInstance()->isPluginActivated('Feedback')) {
             $menu->addItem($login, null, array('module' => 'Feedback', 'action' => 'index'), 998);
         } else {
             $menu->addItem($login, null, array('module' => 'API', 'action' => 'listAllAPI'), 998);
         }
     } else {
         $menu->addItem($login, null, array('module' => 'UsersManager', 'action' => 'userSettings'), 998);
     }
     $module = $this->getLoginModule();
     if (Piwik::isUserIsAnonymous()) {
         $menu->addItem('Login_LogIn', null, array('module' => $module, 'action' => false), 999);
     } else {
         $menu->addItem('General_Logout', null, array('module' => $module, 'action' => 'logout', 'idSite' => null), 999);
     }
 }

作者:dorelljame    项目:piwi   
public function configureTopMenu(MenuTop $menu)
 {
     $login = Piwik::getCurrentUserLogin();
     $user = APIUsersManager::getInstance()->getUser($login);
     if (!empty($user['alias'])) {
         $login = $user['alias'];
     }
     if (Plugin\Manager::getInstance()->isPluginActivated('Feedback')) {
         $menu->registerMenuIcon('General_Help', 'icon-help');
         $menu->addItem('General_Help', null, array('module' => 'Feedback', 'action' => 'index'), $order = 990, Piwik::translate('General_Help'));
     }
     $menu->registerMenuIcon($login, 'icon-user');
     if (Piwik::isUserIsAnonymous()) {
         if (Plugin\Manager::getInstance()->isPluginActivated('ScheduledReports')) {
             $menu->addItem($login, null, array('module' => 'ScheduledReports', 'action' => 'index'), 970, Piwik::translate('ScheduledReports_PersonalEmailReports'));
         } else {
             $menu->addItem($login, null, array('module' => 'API', 'action' => 'listAllAPI'), 970, Piwik::translate('API_ReportingApiReference'));
         }
     } else {
         $tooltip = sprintf('%s: %s', Piwik::translate('UsersManager_PersonalSettings'), $login);
         $menu->addItem($login, null, array('module' => 'UsersManager', 'action' => 'userSettings'), 970, $tooltip);
     }
     $module = $this->getLoginModule();
     if (Piwik::isUserIsAnonymous()) {
         $menu->registerMenuIcon('Login_LogIn', 'icon-sign-in');
         $menu->addItem('Login_LogIn', null, array('module' => $module, 'action' => false), 1000, Piwik::translate('Login_LogIn'));
     } else {
         $menu->registerMenuIcon('General_Logout', 'icon-sign-out');
         $menu->addItem('General_Logout', null, array('module' => $module, 'action' => 'logout', 'idSite' => null), 1000, Piwik::translate('General_Logout'));
     }
 }

作者:FluentDevelopmen    项目:piwi   
public function testGetUserPreferenceDefault()
 {
     $this->addSites(1);
     $defaultReportPref = API::PREFERENCE_DEFAULT_REPORT;
     $defaultReportDatePref = API::PREFERENCE_DEFAULT_REPORT_DATE;
     $this->assertEquals(1, $this->api->getUserPreference('someUser', $defaultReportPref));
     $this->assertEquals('yesterday', $this->api->getUserPreference('someUser', $defaultReportDatePref));
 }

作者:FluentDevelopmen    项目:piwi   
public function configureAdminMenu(MenuAdmin $menu)
 {
     if (Piwik::isUserHasSomeAdminAccess()) {
         $menu->addManageItem('UsersManager_MenuUsers', $this->urlForAction('index'), $order = 2);
     }
     if (Piwik::hasUserSuperUserAccess() && API::getInstance()->getSitesAccessFromUser('anonymous')) {
         $menu->addSettingsItem('UsersManager_AnonymousUser', $this->urlForAction('anonymousSettings'), $order = 20);
     }
 }

作者:dorelljame    项目:piwi   
/**
  * Hooks when a website tracker cache is flushed (website/user updated, cache deleted, or empty cache)
  * Will record in the tracker config file the list of Admin token_auth for this website. This
  * will be used when the Tracking API is used with setIp(), setForceDateTime(), setVisitorId(), etc.
  *
  * @param $attributes
  * @param $idSite
  * @return void
  */
 public function recordAdminUsersInCache(&$attributes, $idSite)
 {
     // add the 'hosts' entry in the website array
     $users = API::getInstance()->getUsersWithSiteAccess($idSite, 'admin');
     $tokens = array();
     foreach ($users as $user) {
         $tokens[] = $user['token_auth'];
     }
     $attributes['admin_token_auth'] = $tokens;
 }

作者:FluentDevelopmen    项目:piwi   
public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     DbHelper::createAnonymousUser();
     // the api_internal_call.php uses idSite=7, so we create 7 sites
     for ($i = 0; $i != 7; ++$i) {
         Fixture::createWebsite("2011-01-01 00:00:00", $ecommerce = 1, $siteName = "Site #{$i}");
     }
     // the script uses anonymous token auth, so give the anonymous user access
     \Piwik\Plugins\UsersManager\API::getInstance()->setUserAccess('anonymous', 'view', array(7));
 }

作者:piwi    项目:piwi   
public function configureAdminMenu(MenuAdmin $menu)
 {
     if (Piwik::isUserHasSomeAdminAccess()) {
         $menu->addSystemItem('UsersManager_MenuUsers', $this->urlForAction('index'), $order = 15);
     }
     if (Piwik::hasUserSuperUserAccess() && API::getInstance()->getSitesAccessFromUser('anonymous')) {
         $menu->addSystemItem('UsersManager_AnonymousUser', $this->urlForAction('anonymousSettings'), $order = 16);
     }
     if (!Piwik::isUserIsAnonymous()) {
         $menu->addItem('UsersManager_MenuPersonal', 'General_Settings', $this->urlForAction('userSettings'), 0);
     }
 }

作者:andrzejewsk    项目:plugin-CustomAlert   
public function setUp()
 {
     parent::setUp();
     // make sure templates will be found
     Plugin\Manager::getInstance()->loadPlugin('CustomAlerts');
     Plugin\Manager::getInstance()->loadPlugin('Morpheus');
     Translate::loadAllTranslations();
     \Piwik\Plugins\UsersManager\API::getInstance()->addUser('login1', 'p2kK2msAw1', 'test1@example.com');
     \Piwik\Plugins\UsersManager\API::getInstance()->addUser('login2', 'p2kK2msAw1', 'test2@example.com');
     \Piwik\Plugins\UsersManager\API::getInstance()->addUser('login3', 'p2kK2msAw1', 'test3@example.com');
     $this->notifier = new CustomNotifier();
 }

作者:neff    项目:plugin-LoginHttpAut   
public function setUp()
 {
     parent::setUp();
     UsersManagerAPI::getInstance()->addUser(self::TEST_USER, 'anotherparttimer', 'terry.mcginnis@hamiltonhill.edu');
     UsersManagerAPI::getInstance()->addUser(self::TEST_SUPERUSER, 'streetballet', 'barbara.gordon@gotham.gov');
     UsersManagerAPI::getInstance()->setSuperUserAccess(self::TEST_SUPERUSER, true);
     $this->auth = new Auth();
     $this->backupEnv = $_ENV;
     $_ENV = array();
     $this->backupServer = $_SERVER;
     $_SERVER = array();
 }

作者:TensorWrenchOS    项目:piwi   
public function setUp()
 {
     parent::setUp();
     self::updateDatabase();
     // make sure site has an early enough creation date (for period selector tests)
     Db::get()->update(Common::prefixTable("site"), array('ts_created' => '2011-01-01'), "idsite = 1");
     $this->addOverlayVisits();
     $this->addNewSitesForSiteSelector();
     DbHelper::createAnonymousUser();
     UsersManagerAPI::getInstance()->setSuperUserAccess('superUserLogin', true);
     SitesManagerAPI::getInstance()->updateSite(1, null, null, true);
 }

作者:brienomatt    项目:elmsl   
/**
  * Returns default period type for Piwik reports.
  *
  * @return string `'day'`, `'week'`, `'month'`, `'year'` or `'range'`
  * @api
  */
 public function getDefaultPeriod()
 {
     $userSettingsDate = APIUsersManager::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), APIUsersManager::PREFERENCE_DEFAULT_REPORT_DATE);
     if ($userSettingsDate === false) {
         return Config::getInstance()->General['default_period'];
     }
     if (in_array($userSettingsDate, array('today', 'yesterday'))) {
         return 'day';
     }
     if (strpos($userSettingsDate, 'last') === 0 || strpos($userSettingsDate, 'previous') === 0) {
         return 'range';
     }
     return $userSettingsDate;
 }

作者:pombredann    项目:ArcherSy   
function redirectToCoreHomeIndex()
 {
     $defaultReport = API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), API::PREFERENCE_DEFAULT_REPORT);
     $module = 'CoreHome';
     $action = 'index';
     // User preference: default report to load is the All Websites dashboard
     if ($defaultReport == 'MultiSites' && \Piwik\Plugin\Manager::getInstance()->isPluginActivated('MultiSites')) {
         $module = 'MultiSites';
     }
     if ($defaultReport == Piwik::getLoginPluginName()) {
         $module = Piwik::getLoginPluginName();
     }
     $idSite = Common::getRequestVar('idSite', false, 'int');
     parent::redirectToIndex($module, $action, $idSite);
 }

作者:diosmosi    项目:piwi   
protected function setUpUsers()
 {
     $api = API::getInstance();
     foreach ($this->users as $login => $permissions) {
         $api->addUser($login, 'password', $login . '@example.com');
         foreach ($permissions as $access => $idSites) {
             if (!empty($idSites)) {
                 $api->setUserAccess($login, $access, $idSites);
             }
         }
         $user = $api->getUser($login);
         $this->users[$login]['token'] = $user['token_auth'];
     }
     $api->setSuperUserAccess('login1', true);
 }

作者:carriercom    项目:piwi   
public function setUp()
 {
     parent::setUp();
     // make sure site has an early enough creation date (for period selector tests)
     Db::get()->update(Common::prefixTable("site"), array('ts_created' => '2011-01-01'), "idsite = 1");
     $this->addOverlayVisits();
     $this->addNewSitesForSiteSelector();
     DbHelper::createAnonymousUser();
     UsersManagerAPI::getInstance()->setSuperUserAccess('superUserLogin', true);
     Option::set("Tests.forcedNowTimestamp", $this->now->getTimestamp());
     // launch archiving so tests don't run out of time
     $date = Date::factory($this->dateTime)->toString();
     VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date);
     VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date, urlencode($this->segment));
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * Authenticates the user.
  *
  * Derived classes can override this method to customize authentication logic or impose
  * extra requirements on the user trying to login.
  *
  * @param AuthInterface $auth The Auth implementation to use when authenticating.
  * @return AuthResult
  */
 protected function doAuthenticateSession(AuthInterface $auth)
 {
     $login = $auth->getLogin();
     $tokenAuthSecret = null;
     try {
         $tokenAuthSecret = $auth->getTokenAuthSecret();
     } catch (Exception $ex) {
         Log::debug("SessionInitializer::doAuthenticateSession: token_auth secret for %s not available before user" . " is authenticated.", $login);
     }
     $tokenAuth = empty($tokenAuthSecret) ? null : $this->usersManagerAPI->getTokenAuth($login, $tokenAuthSecret);
     /**
      * @deprecated Create a custom SessionInitializer instead.
      */
     Piwik::postEvent('Login.authenticate', array($auth->getLogin(), $tokenAuth));
     return $auth->authenticate();
 }

作者:FluentDevelopmen    项目:piwi   
public function getDefaultPeriodWithoutValidation($defaultDate = null)
 {
     if (empty($defaultDate)) {
         $defaultDate = $this->api->getUserPreference(Piwik::getCurrentUserLogin(), APIUsersManager::PREFERENCE_DEFAULT_REPORT_DATE);
     }
     if (empty($defaultDate)) {
         return $this->getSystemDefaultPeriod();
     }
     if (in_array($defaultDate, array('today', 'yesterday'))) {
         return 'day';
     }
     if (strpos($defaultDate, 'last') === 0 || strpos($defaultDate, 'previous') === 0) {
         return 'range';
     }
     return $defaultDate;
 }

作者:FluentDevelopmen    项目:piwi   
public function setUp()
 {
     self::downloadGeoIpDbs();
     parent::setUp();
     self::updateDatabase();
     // make sure site has an early enough creation date (for period selector tests)
     Db::get()->update(Common::prefixTable("site"), array('ts_created' => '2011-01-01'), "idsite = 1");
     // for proper geolocation
     LocationProvider::setCurrentProvider(LocationProvider\GeoIp\Php::ID);
     IPAnonymizer::deactivate();
     $this->addOverlayVisits();
     $this->addNewSitesForSiteSelector();
     DbHelper::createAnonymousUser();
     UsersManagerAPI::getInstance()->setSuperUserAccess('superUserLogin', true);
     SitesManagerAPI::getInstance()->updateSite(1, null, null, true);
     // create non super user
     UsersManagerAPI::getInstance()->addUser('oliverqueen', 'smartypants', 'oli@queenindustries.com');
     UsersManagerAPI::getInstance()->setUserAccess('oliverqueen', 'view', array(1));
 }

作者:piwi    项目:piwi   
/**
  * Constructor.
  *
  * @param UsersManagerAPI|null $usersManagerAPI
  * @param string|null $authCookieName
  * @param int|null $authCookieValidTime
  * @param string|null $authCookiePath
  */
 public function __construct($usersManagerAPI = null, $authCookieName = null, $authCookieValidTime = null, $authCookiePath = null)
 {
     if (empty($usersManagerAPI)) {
         $usersManagerAPI = UsersManagerAPI::getInstance();
     }
     $this->usersManagerAPI = $usersManagerAPI;
     if (empty($authCookieName)) {
         $authCookieName = Config::getInstance()->General['login_cookie_name'];
     }
     $this->authCookieName = $authCookieName;
     if (empty($authCookieValidTime)) {
         $authCookieValidTime = Config::getInstance()->General['login_cookie_expire'];
     }
     $this->authCookieValidTime = $authCookieValidTime;
     if (empty($authCookiePath)) {
         $authCookiePath = Config::getInstance()->General['login_cookie_path'];
     }
     $this->authCookiePath = $authCookiePath;
 }


问题


面经


文章

微信
公众号

扫码关注公众号