Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yii 2.0.17 + Yiii2-mongodb ~2.1.0 Flash message does no work #17559

Closed
webspec2012 opened this issue Apr 19, 2019 · 16 comments
Closed

Yii 2.0.17 + Yiii2-mongodb ~2.1.0 Flash message does no work #17559

webspec2012 opened this issue Apr 19, 2019 · 16 comments
Labels
Milestone

Comments

@webspec2012
Copy link

If using MongoDB as session storage, Flash messages do not work.

'session' => [
            'name' => 'backend',
            'class' => 'yii\mongodb\Session',
            'sessionCollection' => 'BackendSessions',
],
/**
     * Changing user password
     *
     * @param string $id User id
     * @return mixed
     * @throws NotFoundHttpException
     */
    public function actionChangePassword($id)
    {
        $model = User::findOne($id);
        if (empty($model)) {
            throw new NotFoundHttpException("User specified not found!");
        }

        $password = User::generateRandomPassword();
        $model->setPassword($password);
        $model->generateAuthKey();

        if ($model->save(false)) {
            \Yii::$app->session->setFlash('success', 'New password was set: "'.$password.'"');
        } else {
            \Yii::$app->session->setFlash('error', 'There was an error changing password!');
        }

        return $this->redirect(['view', 'id' => $id]);
    }

Message is list after redirect. It works if I stop storing sessions in MongoDB.

@webspec2012
Copy link
Author

webspec2012 commented Sep 10, 2019

The problem is here in latest framework version. It works well with 2.0.15.1.

@samdark samdark changed the title Yii 2.0.17 + Yiii2-mongodb ~2.1.0 не работают Flash сообщения Yii 2.0.17 + Yiii2-mongodb ~2.1.0 Flash message does no work Sep 10, 2019
@samdark
Copy link
Member

samdark commented Sep 10, 2019

I've translated issue into English so community can participate as a whole.

If the version of MongoDB was not changed, then it seems the problem is somewhere in the framework. Since you have a clear way to reproduce it please do bisect to find out exact commit that broke it. Here's how: https://git-scm.com/docs/git-bisect or in Russian: https://git-scm.com/book/ru/v1/Инструменты-Git-Отладка-с-помощью-Git

@webspec2012
Copy link
Author

This problem after commit:

Class yii\mongodb\Session extends MultiFieldSession

Function MultiFieldSession::composeFields was changed.
If you return the old feature code, it works fine.

@samdark samdark transferred this issue from yiisoft/yii2-mongodb Sep 11, 2019
@samdark samdark added the type:bug Bug label Sep 11, 2019
@samdark samdark added this to the 2.0.27 milestone Sep 11, 2019
@samdark
Copy link
Member

samdark commented Sep 11, 2019

@webspec2012 can you check if it's 8bb334b#r33018458?

@samdark samdark added the status:to be verified Needs to be reproduced and validated. label Sep 11, 2019
@webspec2012
Copy link
Author

The session ID changes from one page to another.

..

db.BackendSessions.remove({});
WriteResult({ "nRemoved" : 4 })

refresh site page by F5

db.BackendSessions.find().pretty();
{
"_id" : ObjectId("5d79f9882893100f3029bfa4"),
"id" : "3racnq6iq3gtm8ma3has4nueva",
"data" : "__flash|a:0:{}__id|s:24:"5a65db240a64100202b7ca65";"
}

refresh site page by F5

db.BackendSessions.find().pretty();
{
"_id" : ObjectId("5d79f9882893100f3029bfa4"),
"id" : "04gl55gs0ecj22q61tu3s9l475",
"data" : "__flash|a:0:{}__id|s:24:"5a65db240a64100202b7ca65";"
}

refresh site page by F5

db.BackendSessions.find().pretty();
{
"_id" : ObjectId("5d79f9882893100f3029bfa4"),
"id" : "ilcs8pkjetisbie47p0h524adb",
"data" : "__flash|a:0:{}__id|s:24:"5a65db240a64100202b7ca65";"
}

...

@samdark
Copy link
Member

samdark commented Sep 12, 2019

Does PHP write it into MongoDB at all?

@webspec2012
Copy link
Author

webspec2012 commented Sep 12, 2019

Снимок экрана от 2019-09-12 12-17-06

This log for each page..

@samdark
Copy link
Member

samdark commented Sep 12, 2019

@lubosdz any idea on why would it break?

@ailmanki
Copy link

my 2 cents, this looks sketchy - I would start investigating that:

// ensure data consistency

@samdark
Copy link
Member

samdark commented Sep 12, 2019

@ailmanki thanks, that would be awesome.

@webspec2012
Copy link
Author

Mongodb Session class not extends DbSession.

@lubosdz
Copy link
Contributor

lubosdz commented Sep 12, 2019

Mongodb Session class not extends DbSession.

So is the issue solved ?

I reckon yii2-mongo sessionWrite has not been updated accordingly after bugfix - compare:
https://github.com/yiisoft/yii2-mongodb/blob/master/src/Session.php#L137
https://github.com/yiisoft/yii2/blob/master/framework/web/DbSession.php#L186

Unfortunatelly I dont have mongo setup ..

Edit:
Related mongo issue #279 - see e.g. failing build.

@samdark
Copy link
Member

samdark commented Sep 12, 2019

So is the issue solved ?

No.

@samdark samdark added status:ready for adoption Feel free to implement this issue. and removed status:to be verified Needs to be reproduced and validated. labels Sep 12, 2019
@samdark samdark modified the milestones: 2.0.27, 2.0.28 Sep 17, 2019
@lubosdz
Copy link
Contributor

lubosdz commented Oct 2, 2019

Fixed in PR #285.

CI fail not related to this PR - see build log - PHP 5.5. not pre-installed (is PHP 5.5 officially supported or can this be removed?).

samdark pushed a commit to yiisoft/yii2-mongodb that referenced this issue Oct 2, 2019
@samdark samdark closed this as completed Oct 2, 2019
@samdark
Copy link
Member

samdark commented Oct 2, 2019

@webspec2012 can you test with dev-master of the yiisoft/yii2-mongo?

@samdark samdark removed help wanted status:ready for adoption Feel free to implement this issue. labels Oct 2, 2019
@webspec2012
Copy link
Author

The `dev-master ' branch works correctly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants