Event does not run after User Login

Hi all,

I created a Behavior which contains function. This function should be afterLogon of User (yii/web/User::EVENT_AFTER_LOGIN). But this function never will be triggered unfortunatelly.

I have a Behaviour class for the user model:


class UserBehavior extends Behavior

{

    /**

     * @inheritdoc

     * @param \yii\base\Component $owner

     */

    public function attach($owner)

    {

        parent::attach($owner);

        $owner->on(\yii\web\User::EVENT_AFTER_LOGIN, [$this, 'updateLoginInformation']);

    }


    /**

     * @inheritdoc

     */

    public function events()

    {

        return [

            \yii\web\User::EVENT_AFTER_LOGIN => [$this, 'updateLoginInformation'],

        ];

    }


    /**

     * Update login information data:

     * - login ip address

     * - login time

     */

    public function updateLoginInformation()

    {

        /** @var \common\models\User $owner */

        $owner = $this->owner;

        $owner->logged_in_ip = Yii::$app->request->getUserIP();

        $owner->logged_in_at = time();

        $owner->save();

    }

}

I declared the events and the attach too. But this events never be run after login…

I attached this behavior to the user model:


    /**

     * @inheritdoc

     */

    public function behaviors()

    {

        return [

            TimestampBehavior::className(),

            UserBehavior::className()

        ];

    }

If I know well the the EVENT_AFTER_LOGIN will be triggered automatically by the Yii framework, this is the reason why I do not trigger it again.

And I do not where is the problem, because the updageLoginInformatin never called.

Well, It seems you cannot subscribe to the yii/web/User::EVENT_AFTER_LOGIN event.

I created a new Event cosntant in my class, and triggered it after a successfull login, and it is ok.

For me it seems the yii/web/User::EVENT_AFTER_LOGIN is not allowed.

I’ve hooked on to it fine, though I configured it within my application config:




return [

    'components' => [

        'user' => [

            'on ' . \yii\web\User::EVENT_AFTER_LOGIN => ['app\components\LoginEventHandler', 'processLogin'],

        ],

    ],

];