/** * Updates a user in the database. * Only login and password are required (case when we update the password). * When the password changes, the key token for this user will change, which could break * its API calls. * * @see addUser() for all the parameters */ public function updateUser($userLogin, $password = false, $email = false, $alias = false, $_isPasswordHashed = false) { Piwik::checkUserIsSuperUserOrTheUser($userLogin); $this->checkUserIsNotAnonymous($userLogin); $this->checkUserIsNotSuperUser($userLogin); $userInfo = $this->getUser($userLogin); if (empty($password)) { $password = $userInfo['password']; } else { $password = Common::unsanitizeInputValue($password); if (!$_isPasswordHashed) { UsersManager::checkPassword($password); $password = UsersManager::getPasswordHash($password); } } if (empty($alias)) { $alias = $userInfo['alias']; } if (empty($email)) { $email = $userInfo['email']; } if ($email != $userInfo['email']) { $this->checkEmail($email); } $alias = $this->getCleanAlias($alias, $userLogin); $token_auth = $this->getTokenAuth($userLogin, $password); $db = Db::get(); $db->update(Common::prefixTable("user"), array('password' => $password, 'alias' => $alias, 'email' => $email, 'token_auth' => $token_auth), "login = '******'"); Cache::deleteTrackerCache(); /** * Triggered after an existing user has been updated. * * @param string $userLogin The user's login handle. */ Piwik::postEvent('UsersManager.updateUser.end', array($userLogin)); }
/** * Sets the language for the user * * @param string $login * @param string $languageCode * @return bool */ public function setLanguageForUser($login, $languageCode) { Piwik::checkUserIsSuperUserOrTheUser($login); Piwik::checkUserIsNotAnonymous(); if (!$this->isLanguageAvailable($languageCode)) { return false; } $paramsBind = array($login, $languageCode, $languageCode); Db::query('INSERT INTO ' . Common::prefixTable('user_language') . ' (login, language) VALUES (?,?) ON DUPLICATE KEY UPDATE language=?', $paramsBind); return true; }
/** * Returns a stored segment by ID * * @param $idSegment * @throws Exception * @return bool */ public function get($idSegment) { Piwik::checkUserHasSomeViewAccess(); if (!is_numeric($idSegment)) { throw new Exception("idSegment should be numeric."); } $segment = Db::get()->fetchRow("SELECT * " . " FROM " . Common::prefixTable("segment") . " WHERE idsegment = ?", $idSegment); if (empty($segment)) { return false; } try { if (!$segment['enable_all_users']) { Piwik::checkUserIsSuperUserOrTheUser($segment['login']); } } catch (Exception $e) { throw new Exception("You can only edit the custom segments you have created yourself. This segment was created and 'shared with you' by the Super User. " . "To modify this segment, you can first create a new one by clicking on 'Add new segment'. Then you can customize the segment's definition."); } if ($segment['deleted']) { throw new Exception("This segment is marked as deleted. "); } return $segment; }