Tracks users leaving a channel

@param  Event  $event Event object
196483
public function onPart(Event $event)
    {
        $msg = $event->getMessage();

        if (!isset($msg['nick'])) {
            return;
        }

        $nick = $msg['nick'];
        $chan = $msg['params']['channels'];

        $this->storage->removeUser($nick, $chan);
    }
555403
public function cleanupRequest(Event $event)
    {
        $params = $event['request']->getParams();
        unset($params[self::REDIRECT_COUNT]);
        unset($params[self::PARENT_REQUEST]);
    }
1149440
public function notify(Event $event)
    {
        $processed = false;
        foreach ($this->listeners as $listener) {
            if ($listener->match($event)) {
                $listener->handle($event);
                $processed = true;
                if ($event->isPropagationStopped()) {
                    break;
                }
            }
        }
        return $processed;
    }
213478
public function shutdown(Event $event)
    {
        $action = $event->subject()->request->action;

        if (!isset($event->subject()->viewVars['_ws'])) {
            return;
        }

        $_ws = $event->subject()->viewVars['_ws'];
        $data = (isset($_ws) && isset($_ws['data'])) ? $_ws['data'] : null;
        $users = (isset($_ws) && isset($_ws['users'])) ? $_ws['users'] : null;

        if (get_class($users) === 'Cake\ORM\ResultSet') {
            $users = $users->extract('id')->toArray();
        } else {
            // not implemented yet
        }

        $trigger = new Trigger($this->_controller);
        $trigger->publish($data, $users);
    }
412138
public function sendEvent(Event $event)
    {
        try {
            $this->eventFactory->addDefaultTagsToEntity($event);
            $this->sendEventThroughSenders($event);
        } catch (\Exception $exception) {
            $this->logException($exception);
        }
    }
1074594
public static function handle(LogoutEvent $event)
    {

        // If there is no user, do nothing.
        if (! $event->user)
            return;

        $event->user->login_history()->save(new UserLoginHistory([
            'source'     => Request::getClientIp(),
            'user_agent' => Request::header('User-Agent'),
            'action'     => 'logout',
        ]));

        $message = 'User logged out from ' . Request::getClientIp();
        event('security.log', [$message, 'authentication']);
    }
438428
public function onNodeResourceEventAlterChannels(Event $event)
    {
        if (!$this->groupManager || !$event instanceof ResourceEvent) {
            return;
        }

        $done = [];

        // Fetch site groups, and yes we don't really have a choice here
        $nodes = $this->entityManager->getStorage('node')->loadMultiple($event->getResourceIdList());
        foreach ($nodes as $node) {
            if ($node->group_id) {
                $groupId = (int)$node->group_id;
                $done[$groupId] = $groupId;
            }
        }

        foreach ($done as $groupId) {
            $event->addArbitraryChanId('admin:content:' . $groupId);
        }
    }
324255
public function logout(Event $event, array $user)
    {
        $this->_init($event->subject()->request);
        Hybrid_Auth::logoutAllProviders();
    }
1256370
public function handleRemoveLive($event)
    {
        $document = $event->getDocument();
        if (!$document instanceof ArticleDocument) {
            return;
        }

        $this->liveIndexer->remove($document);
        $this->liveIndexer->flush();
    }
21622
public function onAfterRouting(Event $event)
    {
        $tmpl = <<<TMPL
{
    "registrar": [
        {
            "language": "php",
            "provider": "routing",
            "signature": [
                "Windwalker\\\\Core\\\\Router\\\\RouteBuilderTrait:to",
                "Windwalker\\\\Core\\\\Router\\\\RouteBuilderTrait:route",
                "Windwalker\\\\Core\\\\Router\\\\RouteBuilderTrait:generate",
                "Windwalker\\\\Core\\\\Router\\\\RouteBuilderTrait:fullRoute",
                "Windwalker\\\\Core\\\\Router\\\\RouteBuilderTrait:rawRoute",
                "Windwalker\\\\Core\\\\Router\\\\CoreRouter:to",
                "Windwalker\\\\Core\\\\Router\\\\CoreRouter:route",
                "Windwalker\\\\Core\\\\Router\\\\CoreRouter:generate",
                "Windwalker\\\\Core\\\\Router\\\\CoreRouter:fullRoute",
                "Windwalker\\\\Core\\\\Router\\\\CoreRouter:rawRoute"
            ]
        }
    ],
    "providers": [
        {
            "name": "routing",
            "lookup_strings": [
                %s
            ]
        }
    ]
}
TMPL;

        /** @var MainRouter $router */
        $router = $event['router'];

        $names = [];
        $routes = $router->getRoutes();

        foreach ($routes as $route) {
            $name = $route->getName();
            
            list($pkg, $name) = array_pad(explode('@', $name), -2, null);
            
            $names[] = StringHelper::quote($name, '"');
            
            if ($pkg) {
                $names[] = StringHelper::quote($pkg . '@' . $name, '"');
            }
        }
        
        $names = implode(",\r\n", $names);
        $content = sprintf($tmpl, $names);

        File::write(WINDWALKER_TEMP . '/ide/router/.ide-toolbox.metadata.json', $content);
    }
845532
public function onModelAfterSave(Event $event)
    {
        /** @var User|bool $user */
        $user = $event->getData('user');

        if ($user instanceof EntityInterface) {
            if ($user->isNew() && Filter::bool($user->get('notify'))) {
                $this->_getMailer($user)->sendCreateMessage();
            }
        }
    }
704978
public function handleEvent(Event $event)
    {
        if (!$event instanceof UserInfoWithPassword) {
            throw new InvalidArgumentException(t('Invalid event type provided. Event type must be "UserInfoWithPassword".'));
        }

        // Track the password use
        $this->tracker->trackUse($event->getUserPassword(), $event->getUserInfoObject());
    }
1084081
public function logout(Event $event)
    {
        if (phpCAS::isAuthenticated()) {
            //Step 1. When the client clicks logout, this will run.
            //        phpCAS::logout will redirect the client to the CAS server.
            //        The CAS server will, in turn, redirect the client back to
            //        this same logout URL.
            //
            //        phpCAS will stop script execution after it sends the redirect
            //        header, which is a problem because CakePHP still thinks the
            //        user is logged in. See Step 2.
            $auth = $event->subject();
            if ($auth instanceof AuthComponent) {
                $redirectUrl = $auth->config('logoutRedirect');
            }
            if (empty($redirectUrl)) {
                $redirectUrl = '/';
            }
            phpCAS::logout(['url' => Router::url($redirectUrl, true)]);
        }
        //Step 2. We reach this line when the CAS server has redirected the
        //        client back to us. Do nothing in this block; then after this
        //        method returns, CakePHP will do whatever is necessary to log
        //        the user out from its end (destroying the session or whatever).
    }
1343445
public function onBeforeSend(Event $event)
    {
        /** @var $request Request */
        $request = $event['request'];

        $id = $this->signatureCredentials->getMacId();
        $ts = $this->timeProvider->getCurrentTime()->getTimestamp();
        $nonce = $this->randomProvider->generateStringForRanges($this->nonceLength, self::$characterRanges);
        $ext = $this->extensionProvider->getExtensionParameters($request, $this->signatureCredentials, $ts, $nonce);
        $ext = http_build_query($ext, null, '&');
        $mac = $this->algorithmManager->generateMac($request, $this->signatureCredentials, $ts, $nonce, $ext);

        $params = array(
            'id' => $id,
            'ts' => $ts,
            'nonce' => $nonce,
            'ext' => $ext,
            'mac' => $mac,
        );

        $list = array();
        foreach ($params as $key => $value) {
            $list[] = $key . '="' . $value . '"';
        }
        $header = 'MAC ' . implode(', ', $list);

        $request->setHeader('Authorization', $header);
    }
85254
public function logActivity($event)
    {
        // if cronjob / no user
        if (user()->id <= 0) {
            return;
        }

        // log adjustment
        LogAdminActivity::create([
            'subject_id'   => $this->id,
            'subject_type' => get_class($this),
            'name'         => $this->getActivityName($this, $event),
            'before'       => $this->before,
            'after'        => $this->after,
            'user_id'      => user()->id,
        ]);
    }
350769
public function removeUser(UserEventInterface $event, EventQueueInterface $queue)
    {
        $logger = $this->getLogger();
        $logger->debug('Removing user from all channels');
        $connectionMask = $this->getConnectionMask($event->getConnection());
        if (isset($this->modes[$connectionMask])) {
            $this->removeUserData(
                $connectionMask,
                array_keys($this->modes[$connectionMask]),
                $event->getNick()
            );
        }
    }
750795
private function captureStepEvent(Event $event)
    {
        if ($event instanceof AfterStepTested) {
            $this->afterStepTestedEvents[$event->getStep()->getLine()] = $event;
        }
        if ($event instanceof AfterStepSetup) {
            $this->afterStepSetupEvents[$event->getStep()->getLine()] = $event;
        }
    }