yii2-usuario icon indicating copy to clipboard operation
yii2-usuario copied to clipboard

Flash message not added after redirect in some case

Open bscheshirwork opened this issue 5 years ago • 0 comments

What steps will reproduce the problem?

Use 'on'-syntax for configure triggers of actions:

                'recovery' => [
                    'class' => \Da\User\Controller\RecoveryController::class,
                    'on ' . \Da\User\Event\ResetPasswordEvent::EVENT_AFTER_RESET => function (\Da\User\Event\ResetPasswordEvent $event) {
                        if ($event->token->user ?? false) {
                            \Yii::$app->user->login($event->token->user);
                        }
                    },
                ],
                'registration' => [
                    'class' => \Da\User\Controller\RegistrationController::class,
                    'on ' . \Da\User\Event\FormEvent::EVENT_AFTER_RESEND => function (\Da\User\Event\FormEvent $event) {
                        \Yii::$app->controller->redirect(['/user/security/login']);
                    },
                ],

What is the expected result?

all flash messages "in box"

What do you get instead?

If I use redirect into callback function I can't see flash messages after reset password or after resend email. Yii::$app->end() does not matter

related #281

p.s.: I must add flash message directly now

                'recovery' => [
                    'class' => \Da\User\Controller\RecoveryController::class,
                    'on ' . \Da\User\Event\FormEvent::EVENT_AFTER_REQUEST => function (\Da\User\Event\FormEvent $event) {
                        \Yii::$app->controller->redirect(['/user/security/login']);
                        \Yii::$app->end();
                    },
                    'on ' . \Da\User\Event\ResetPasswordEvent::EVENT_AFTER_RESET => function (\Da\User\Event\ResetPasswordEvent $event) {
                        if ($event->token->user ?? false) {
                            \Yii::$app->user->login($event->token->user);
                        }
                        \Yii::$app->controller->redirect(\Yii::$app->getUser()->getReturnUrl());
                        \Yii::$app->session->setFlash('success', \Yii::t('user', 'Password has been changed'));
                        \Yii::$app->end();
                    },
                ],
                'registration' => [
                    'class' => \Da\User\Controller\RegistrationController::class,
                    'on ' . \Da\User\Event\FormEvent::EVENT_AFTER_REGISTER => function (\Da\User\Event\FormEvent $event) {
                        \Yii::$app->controller->redirect(['/user/security/login']);
                        \Yii::$app->end();
                    },
                    'on ' . \Da\User\Event\FormEvent::EVENT_AFTER_RESEND => function (\Da\User\Event\FormEvent $event) {
                        \Yii::$app->controller->redirect(['/user/security/login']);
                        \Yii::$app->session->setFlash(
                            'info',
                            \Yii::t(
                                'user',
                                'A message has been sent to your email address. It contains a confirmation link that you must click to complete registration.'
                            )
                        );
                        \Yii::$app->end();
                    },
                ],

https://github.com/bscheshirwork/yii2-app-advanced-redis/blob/56c32c7189b6559cdf0692bc23aaacd81df40401/frontend/config/main.php#L52-L84

bscheshirwork avatar Mar 02 '20 02:03 bscheshirwork