getInstance() 공개 정적인 메소드

Example of how you would overwrite the UsersManager_API with your own class: Call the following in your plugin __construct() for example: StaticContainer::getContainer()->set('UsersManager_API', \Piwik\Plugins\MyCustomUsersManager\API::getInstance());
public static getInstance ( ) : API
리턴 API
예제 #1
0
 /**
  * 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);
 }
예제 #2
0
파일: Menu.php 프로젝트: dorelljames/piwik
 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'));
     }
 }
 public function __construct($name = null)
 {
     parent::__construct($name);
     $this->loginLdapAPI = LoginLdapAPI::getInstance();
     $this->ldapUsers = LdapUsers::makeConfigured();
     $this->usersManagerAPI = UsersManagerAPI::getInstance();
 }
예제 #4
0
 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);
     }
 }
예제 #5
0
파일: 2.0.4-b5.php 프로젝트: piwik/piwik
 private static function migrateConfigSuperUserToDb()
 {
     $config = Config::getInstance();
     if (!$config->existsLocalConfig()) {
         return;
     }
     try {
         $superUser = $config->superuser;
     } catch (\Exception $e) {
         $superUser = null;
     }
     if (!empty($superUser['bridge']) || empty($superUser) || empty($superUser['login'])) {
         // there is a super user which is not from the config but from the bridge, that means we already have
         // a super user in the database
         return;
     }
     $userApi = UsersManagerApi::getInstance();
     try {
         Db::get()->insert(Common::prefixTable('user'), array('login' => $superUser['login'], 'password' => $superUser['password'], 'alias' => $superUser['login'], 'email' => $superUser['email'], 'token_auth' => $userApi->getTokenAuth($superUser['login'], $superUser['password']), 'date_registered' => Date::now()->getDatetime(), 'superuser_access' => 1));
     } catch (\Exception $e) {
         echo "There was an issue, but we proceed: " . $e->getMessage();
     }
     if (array_key_exists('salt', $superUser)) {
         $salt = $superUser['salt'];
     } else {
         $salt = Common::generateUniqId();
     }
     $config->General['salt'] = $salt;
     $config->superuser = array();
     $config->forceSave();
 }
예제 #6
0
 /**
  * @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);
 }
예제 #7
0
 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);
     }
 }
예제 #8
0
 public function setUp()
 {
     parent::setUp();
     $this->api = API::getInstance();
     FakeAccess::$superUser = true;
     Fixture::createWebsite('2014-01-01 00:00:00');
     Fixture::createWebsite('2014-01-01 00:00:00');
     Fixture::createWebsite('2014-01-01 00:00:00');
     $this->api->addUser($this->login, 'password', '*****@*****.**');
 }
예제 #9
0
 /**
  * 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;
 }
 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));
 }
예제 #11
0
 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);
 }
 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', '*****@*****.**');
     \Piwik\Plugins\UsersManager\API::getInstance()->addUser('login2', 'p2kK2msAw1', '*****@*****.**');
     \Piwik\Plugins\UsersManager\API::getInstance()->addUser('login3', 'p2kK2msAw1', '*****@*****.**');
     $this->notifier = new CustomNotifier();
 }
예제 #13
0
 /**
  * Send an email notification to all super users.
  *
  * @param $subject
  * @param $message
  */
 protected function sendEmailNotification($subject, $message)
 {
     $superUsers = UsersManagerApi::getInstance()->getUsersHavingSuperUserAccess();
     foreach ($superUsers as $superUser) {
         $mail = new Mail();
         $mail->setDefaultFromPiwik();
         $mail->addTo($superUser['email']);
         $mail->setSubject($subject);
         $mail->setBodyText($message);
         $mail->send();
     }
 }
예제 #14
0
파일: APITest.php 프로젝트: a4tunado/piwik
 public function setUp()
 {
     parent::setUp();
     $this->api = API::getInstance();
     $pseudoMockAccess = new FakeAccess();
     FakeAccess::$superUser = true;
     Access::setSingletonInstance($pseudoMockAccess);
     Fixture::createWebsite('2014-01-01 00:00:00');
     Fixture::createWebsite('2014-01-01 00:00:00');
     Fixture::createWebsite('2014-01-01 00:00:00');
     $this->api->addUser('userLogin', 'password', '*****@*****.**');
 }
예제 #15
0
파일: Menu.php 프로젝트: piwik/piwik
 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);
     }
 }
예제 #16
0
 public function setUp()
 {
     parent::setUp();
     UsersManagerAPI::getInstance()->addUser(self::TEST_USER, 'anotherparttimer', '*****@*****.**');
     UsersManagerAPI::getInstance()->addUser(self::TEST_SUPERUSER, 'streetballet', '*****@*****.**');
     UsersManagerAPI::getInstance()->setSuperUserAccess(self::TEST_SUPERUSER, true);
     $this->auth = new Auth();
     $this->backupEnv = $_ENV;
     $_ENV = array();
     $this->backupServer = $_SERVER;
     $_SERVER = array();
 }
예제 #17
0
 public function setUp()
 {
     parent::setUp();
     \Piwik\Plugin\Manager::getInstance()->loadPlugin('UsersManager');
     \Piwik\Plugin\Manager::getInstance()->installLoadedPlugins();
     // setup the access layer
     FakeAccess::setIdSitesView(array(1, 2));
     FakeAccess::setIdSitesAdmin(array(3, 4));
     //finally we set the user as a Super User by default
     FakeAccess::$superUser = true;
     FakeAccess::$superUserLogin = '******';
     $this->api = API::getInstance();
     $this->model = Factory::getModel('Piwik\\Plugins\\UsersManager');
 }
예제 #18
0
 /**
  * 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;
 }
예제 #19
0
 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);
 }
예제 #20
0
 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);
 }
예제 #21
0
 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));
 }
예제 #22
0
 public function setUp()
 {
     parent::setUp();
     \Piwik\Plugin\Manager::getInstance()->loadPlugin('UsersManager');
     \Piwik\Plugin\Manager::getInstance()->installLoadedPlugins();
     // setup the access layer
     $pseudoMockAccess = new FakeAccess();
     FakeAccess::setIdSitesView(array(1, 2));
     FakeAccess::setIdSitesAdmin(array(3, 4));
     //finally we set the user as a Super User by default
     FakeAccess::$superUser = true;
     FakeAccess::$superUserLogin = '******';
     Access::setSingletonInstance($pseudoMockAccess);
     $this->api = API::getInstance();
     $this->model = new Model();
 }
 public function test_getServerVisitCustomVariables_shouldReturnSystemReport()
 {
     FakeAccess::clearAccess($superUser = true);
     for ($i = 1; $i < 15; $i++) {
         if (!Fixture::siteCreated($i)) {
             Fixture::createWebsite('2014-01-01 00:00:00');
         }
     }
     for ($i = 1; $i < 9; $i++) {
         UsersApi::getInstance()->addUser($login = '******' . $i, 'password0815', "lorem{$i}@piwik.org");
     }
     for ($i = 1; $i < 5; $i++) {
         SegmentApi::getInstance()->add('Segment' . $i, 'pageUrl%3D@inde');
     }
     $customVars = array(array('id' => 1, 'name' => 'Piwik Version', 'value' => '2.14.3'), array('id' => 2, 'name' => 'PHP Version', 'value' => '5.5.27'), array('id' => 3, 'name' => 'Num Users', 'value' => 8), array('id' => 4, 'name' => 'Num Websites', 'value' => 14), array('id' => 5, 'name' => 'Num Segments', 'value' => 4), array('id' => 6, 'name' => 'MySQL Version', 'value' => Db::get()->getServerVersion()));
     $this->assertSame($customVars, $this->customVars->getServerVisitCustomVariables());
 }
예제 #24
0
 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', '*****@*****.**');
     UsersManagerAPI::getInstance()->setUserAccess('oliverqueen', 'view', array(1));
 }
예제 #25
0
 /**
  * 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;
 }
예제 #26
0
 /**
  * Constructor.
  */
 public function __construct($idSite = false)
 {
     parent::__construct();
     $this->jsClass = "SegmentSelectorControl";
     $this->cssIdentifier = "segmentEditorPanel";
     $this->cssClass = "piwikTopControl borderedControl piwikSelector";
     $this->idSite = $idSite ?: Common::getRequestVar('idSite', false, 'int');
     $this->selectedSegment = Common::getRequestVar('segment', false, 'string');
     $formatter = StaticContainer::get('Piwik\\Plugins\\SegmentEditor\\SegmentFormatter');
     $this->segmentDescription = $formatter->getHumanReadable(Request::getRawSegmentFromRequest(), $this->idSite);
     $this->isAddingSegmentsForAllWebsitesEnabled = SegmentEditor::isAddingSegmentsForAllWebsitesEnabled();
     $segments = APIMetadata::getInstance()->getSegmentsMetadata($this->idSite);
     $visitTitle = Piwik::translate('General_Visit');
     $segmentsByCategory = array();
     foreach ($segments as $segment) {
         if ($segment['category'] == $visitTitle && ($segment['type'] == 'metric' && $segment['segment'] != 'visitIp')) {
             $metricsLabel = Piwik::translate('General_Metrics');
             $metricsLabel[0] = Common::mb_strtolower($metricsLabel[0]);
             $segment['category'] .= ' (' . $metricsLabel . ')';
         }
         $segmentsByCategory[$segment['category']][] = $segment;
     }
     $this->createRealTimeSegmentsIsEnabled = Config::getInstance()->General['enable_create_realtime_segments'];
     $this->segmentsByCategory = $segmentsByCategory;
     $this->nameOfCurrentSegment = '';
     $this->isSegmentNotAppliedBecauseBrowserArchivingIsDisabled = 0;
     $this->availableSegments = API::getInstance()->getAll($this->idSite);
     foreach ($this->availableSegments as &$savedSegment) {
         $savedSegment['name'] = Common::sanitizeInputValue($savedSegment['name']);
         if (!empty($this->selectedSegment) && $this->selectedSegment == $savedSegment['definition']) {
             $this->nameOfCurrentSegment = $savedSegment['name'];
             $this->isSegmentNotAppliedBecauseBrowserArchivingIsDisabled = $this->wouldApplySegment($savedSegment) ? 0 : 1;
         }
     }
     $this->authorizedToCreateSegments = SegmentEditorAPI::getInstance()->isUserCanAddNewSegment($this->idSite);
     $this->isUserAnonymous = Piwik::isUserIsAnonymous();
     $this->segmentTranslations = $this->getTranslations();
     $this->segmentProcessedOnRequest = Rules::isBrowserArchivingAvailableForSegments();
     $this->hideSegmentDefinitionChangeMessage = UsersManagerAPI::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), 'hideSegmentDefinitionChangeMessage');
 }
예제 #27
0
파일: API.php 프로젝트: bnkems/piwik
 /**
  * Create a user upon call from frontend
  * This API method will be called from Controller of this module
  * 
  * @param String    $userLogin
  * @param String    $userPassword
  * @param String    $userEmail                         
  * @return Boolean
  */
 public function createUser($userLogin, $userPassword, $userEmail)
 {
     if ($userLogin and $userPassword) {
         $userManager = UserManagerAPI::getInstance();
         if (!$this->userManagerModel->userEmailExists($userEmail) and !$this->userManagerModel->userExists($userLogin)) {
             $password = Common::unsanitizeInputValue($userPassword);
             UserManager::checkPassword($password);
             $passwordTransformed = UserManager::getPasswordHash($password);
             $token_auth = $userManager->getTokenAuth($userEmail, $passwordTransformed);
             try {
                 $this->userManagerModel->addUser($userEmail, $passwordTransformed, $userEmail, $userLogin, $token_auth, Date::now()->getDatetime());
                 return true;
             } catch (Exception $e) {
                 //throw new Exception($e->getMessage());
                 $this->__errors[] = 'Error in creating the user in database.';
             }
         } else {
             $this->__errors[] = 'User email already exists or the login name already exists';
         }
     }
     return false;
 }
예제 #28
0
 /**
  * Authenticates the user and initializes the session.
  */
 public function initSession($login, $md5Password, $rememberMe)
 {
     $tokenAuth = API::getInstance()->getTokenAuth($login, $md5Password);
     $this->setLogin($login);
     $this->setTokenAuth($tokenAuth);
     $authResult = $this->authenticate();
     $authCookieName = Config::getInstance()->General['login_cookie_name'];
     $authCookieExpiry = $rememberMe ? time() + Config::getInstance()->General['login_cookie_expire'] : 0;
     $authCookiePath = Config::getInstance()->General['login_cookie_path'];
     $cookie = new Cookie($authCookieName, $authCookieExpiry, $authCookiePath);
     if (!$authResult->wasAuthenticationSuccessful()) {
         $cookie->delete();
         throw new Exception(Piwik::translate('Login_LoginPasswordNotCorrect'));
     }
     $cookie->set('login', $login);
     $cookie->set('token_auth', $this->getHashTokenAuth($login, $authResult->getTokenAuth()));
     $cookie->setSecure(ProxyHttp::isHttps());
     $cookie->setHttpOnly(true);
     $cookie->save();
     @Session::regenerateId();
     // remove password reset entry if it exists
     Login::removePasswordResetInfo($login);
 }
예제 #29
0
 private static function migrateExistingMobileMessagingOptions()
 {
     if (Option::get(MobileMessaging::DELEGATED_MANAGEMENT_OPTION) == 'true') {
         return;
     }
     // copy $superUserLogin_MobileMessagingSettings -> _MobileMessagingSettings as settings are managed globally
     $optionName = MobileMessaging::USER_SETTINGS_POSTFIX_OPTION;
     $superUsers = UsersManagerApi::getInstance()->getUsersHavingSuperUserAccess();
     if (empty($superUsers)) {
         return;
     }
     $firstSuperUser = array_shift($superUsers);
     if (empty($firstSuperUser)) {
         return;
     }
     $superUserLogin = $firstSuperUser['login'];
     $optionPrefixed = $superUserLogin . $optionName;
     // $superUserLogin_MobileMessagingSettings
     $value = Option::get($optionPrefixed);
     if (false !== $value) {
         // _MobileMessagingSettings
         Option::set($optionName, $value);
     }
 }
예제 #30
0
 public function test_getSitesIdFromSiteUrl_asUser()
 {
     API::getInstance()->addSite("site1", array("http://www.piwik.net", "https://piwik.com"));
     API::getInstance()->addSite("site2", array("http://piwik.com", "http://piwik.net"));
     API::getInstance()->addSite("site3", array("http://piwik.com", "http://piwik.org"));
     APIUsersManager::getInstance()->addUser("user1", "geqgegagae", "*****@*****.**", "alias");
     APIUsersManager::getInstance()->setUserAccess("user1", "view", array(1));
     APIUsersManager::getInstance()->addUser("user2", "geqgegagae", "*****@*****.**", "alias");
     APIUsersManager::getInstance()->setUserAccess("user2", "view", array(1));
     APIUsersManager::getInstance()->setUserAccess("user2", "admin", array(3));
     APIUsersManager::getInstance()->addUser("user3", "geqgegagae", "*****@*****.**", "alias");
     APIUsersManager::getInstance()->setUserAccess("user3", "view", array(1, 2));
     APIUsersManager::getInstance()->setUserAccess("user3", "admin", array(3));
     FakeAccess::$superUser = false;
     FakeAccess::$identity = 'user1';
     FakeAccess::setIdSitesView(array(1));
     FakeAccess::setIdSitesAdmin(array());
     $this->assertFalse(Piwik::hasUserSuperUserAccess());
     $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com');
     $this->assertEquals(1, count($idsites));
     // testing URL normalization
     $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://www.piwik.com');
     $this->assertEquals(1, count($idsites));
     $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.net');
     $this->assertEquals(1, count($idsites));
     FakeAccess::$superUser = false;
     FakeAccess::$identity = 'user2';
     FakeAccess::setIdSitesView(array(1));
     FakeAccess::setIdSitesAdmin(array(3));
     $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com');
     $this->assertEquals(2, count($idsites));
     FakeAccess::$superUser = false;
     FakeAccess::$identity = 'user3';
     FakeAccess::setIdSitesView(array(1, 2));
     FakeAccess::setIdSitesAdmin(array(3));
     $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com');
     $this->assertEquals(3, count($idsites));
     $idsites = API::getInstance()->getSitesIdFromSiteUrl('https://www.piwik.com');
     $this->assertEquals(3, count($idsites));
 }