A
A
Askar Fuzaylov2017-10-08 06:10:42
Yii
Askar Fuzaylov, 2017-10-08 06:10:42

Why is the user not authenticated after registering in yii2?

Good afternoon
There is an almost standard action for user registration.
After saving the user, I want to authenticate it. But authentication doesn't work.

if (!Yii::$app->user->isGuest) {
            return $this->redirect(['/order/client']);
        }

        $model = new SignupForm();
        if ($model->load(Yii::$app->request->post())) {
            if ($user = $model->signup()) {
                Yii::$app->user->login($user);

                Yii::$app->getSession()->setFlash('success', 'Confirm you email address');
                $redirectUrl = Yii::$app->request->get('redirect');
                if ($redirectUrl) {
                    return $this->redirect(urldecode($redirectUrl));
                }

                return $this->refresh();
            }
        }

        return $this->render('signup', [
            'model' => $model,
        ]);

After the redirect, the user is not authenticated. I can't figure out what's wrong.
The user model implements the yii\web\IdentityInterface interface

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2017-10-08
@proudmore

What does Yii::$app->user->login($user) return?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question