Search code examples
authenticationzend-framework2zfcuser

Unable to attach to zfcUser login event on zend framework 2


I want to attach to the login event on zfcUser.

I am able to attach to other zfcUser event like register, change email, change password; the triggers for those events are held in

ZfcUser\Service\User

i.e:

public function register(array $data)
{
   $this->getEventManager()->trigger(__FUNCTION__, $this, array('user' => $user, 'form' => $form));
}

however, I am unable to find the trigger for the login event. Indeed, i cannot even find the processing method for zfcUser login event.

Is there a trigger for the Login Event; if not, how would i go about overriding zfcusers login event so that i can attach a trigger to it.

below is how i attached to the registration event (i would like to do the same with the login event);

class Module
{
public function onBootstrap(MVCEvent $e)
    {
        $eventManager = $e->getApplication()->getEventManager();
        $em           = $eventManager->getSharedManager();
        $em->attach(
                'ZfcUser\Form\RegisterFilter',
                'init',
                function($e)
                {
                    /* @var $form \ZfcUser\Form\Register */
                    $form = $e->getTarget();

                    $form->add(
                            array(
                                    'name' => 'gender',
                                    'type' => 'Zend\Form\Element\Checkbox',
                                    'options' => array(
                                            'label' => 'gender',
                                            'checked_value' => female,
                                            'unchecked_value' => male,
                                    ),
                            )
                    );
                   }

}

Solution

  • Here:

    Pre authentication: https://github.com/ZF-Commons/ZfcUser/blob/master/src/ZfcUser/Authentication/Adapter/AdapterChain.php#L52

    Authentication: https://github.com/ZF-Commons/ZfcUser/blob/master/src/ZfcUser/Authentication/Adapter/AdapterChain.php#L52

    Authenticate success/fail: https://github.com/ZF-Commons/ZfcUser/blob/master/src/ZfcUser/Authentication/Adapter/AdapterChain.php#L71-L77