getEvent(); $result = new AuthenticationResult( $e->getCode(), $e->getIdentity(), $e->getMessages() ); $this->resetAdapters(); return $result; } /** * prepareForAuthentication * * @param Request $request * @return Response|bool * @throws Exception\AuthenticationEventException */ public function prepareForAuthentication(Request $request) { $e = $this->getEvent(); $e->setRequest($request); $this->getEventManager()->trigger('authenticate.pre', $e); $result = $this->getEventManager()->trigger('authenticate', $e, function ($test) { return ($test instanceof Response); }); if ($result->stopped()) { if ($result->last() instanceof Response) { return $result->last(); } throw new Exception\AuthenticationEventException( sprintf( 'Auth event was stopped without a response. Got "%s" instead', is_object($result->last()) ? get_class($result->last()) : gettype($result->last()) ) ); } if ($e->getIdentity()) { $this->getEventManager()->trigger('authenticate.success', $e); return true; } $this->getEventManager()->trigger('authenticate.fail', $e); return false; } /** * resetAdapters * * @return AdapterChain */ public function resetAdapters() { $listeners = $this->getEventManager()->getListeners('authenticate'); foreach ($listeners as $listener) { $listener = $listener->getCallback(); if (is_array($listener) && $listener[0] instanceof ChainableAdapter) { $listener[0]->getStorage()->clear(); } } return $this; } /** * logoutAdapters * * @return AdapterChain */ public function logoutAdapters() { //Adapters might need to perform additional cleanup after logout $this->getEventManager()->trigger('logout', $this->getEvent()); } /** * Get the auth event * * @return AdapterChainEvent */ public function getEvent() { if (null === $this->event) { $this->setEvent(new AdapterChainEvent); $this->event->setTarget($this); } return $this->event; } /** * Set an event to use during dispatch * * By default, will re-cast to AdapterChainEvent if another event type is provided. * * @param Event $e * @return AdapterChain */ public function setEvent(Event $e) { if (!$e instanceof AdapterChainEvent) { $eventParams = $e->getParams(); $e = new AdapterChainEvent(); $e->setParams($eventParams); } $this->event = $e; return $this; } }