Piwik\Plugins\UsersManager\API::updateUser PHP Метод

updateUser() публичный Метод

Only login and password are required (case when we update the password). If the password changes and the user has an old token_auth (legacy MD5 format) associated, the token will be regenerated. This could break a user's API calls.
См. также: addUser() for all the parameters
public updateUser ( $userLogin, $password = false, $email = false, $alias = false, $_isPasswordHashed = false )
    public function updateUser($userLogin, $password = false, $email = false, $alias = false, $_isPasswordHashed = false)
    {
        Piwik::checkUserHasSuperUserAccessOrIsTheUser($userLogin);
        $this->checkUserIsNotAnonymous($userLogin);
        $this->checkUserExists($userLogin);
        $userInfo = $this->model->getUser($userLogin);
        $token_auth = $userInfo['token_auth'];
        $passwordHasBeenUpdated = false;
        if (empty($password)) {
            $password = $userInfo['password'];
        } else {
            $password = Common::unsanitizeInputValue($password);
            if (!$_isPasswordHashed) {
                UsersManager::checkPassword($password);
                $password = UsersManager::getPasswordHash($password);
            }
            $passwordInfo = $this->password->info($password);
            if (!isset($passwordInfo['algo']) || 0 >= $passwordInfo['algo']) {
                // password may have already been fully hashed
                $password = $this->password->hash($password);
            }
            $passwordHasBeenUpdated = true;
        }
        if (empty($alias)) {
            $alias = $userInfo['alias'];
        }
        if (empty($email)) {
            $email = $userInfo['email'];
        }
        if ($email != $userInfo['email']) {
            $this->checkEmail($email);
        }
        $alias = $this->getCleanAlias($alias, $userLogin);
        $this->model->updateUser($userLogin, $password, $email, $alias, $token_auth);
        Cache::deleteTrackerCache();
        /**
         * Triggered after an existing user has been updated.
         * Event notify about password change.
         *
         * @param string $userLogin The user's login handle.
         * @param boolean $passwordHasBeenUpdated Flag containing information about password change.
         */
        Piwik::postEvent('UsersManager.updateUser.end', array($userLogin, $passwordHasBeenUpdated, $email, $password, $alias));
    }

Usage Example

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $login = $input->getArgument('login');
     $user = $this->usersManagerApi->getUser($login);
     if (!UserMapper::isUserLdapUser($user)) {
         throw new Exception("User '{$login}' is not an LDAP user. To regenerate this user's token_auth, change the user's password.");
     }
     if (!$this->userMapper->isRandomTokenAuthGenerationEnabled()) {
         throw new Exception("Random token_auth generation is disabled in [LoginLdap] config. This means any changes made by this " . "command will be overwritten when the user logs in. Aborting.");
     }
     $newPassword = $this->userMapper->generateRandomPassword();
     $this->usersManagerApi->updateUser($login, $newPassword, $email = false, $alias = false, $isPasswordHash = true);
     $user = $this->usersManagerApi->getUser($login);
     $this->writeSuccessMessage($output, array("token_auth for '{$login}' regenerated successfully, new token_auth = '{$user['token_auth']}'"));
 }
All Usage Examples Of Piwik\Plugins\UsersManager\API::updateUser