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

Compatibility with mongodb #1633

Closed
indicalabs opened this Issue Dec 26, 2013 · 18 comments

Comments

Projects
None yet
3 participants
@indicalabs

I have started working with mongodb extension and able to work smoothly.
But the default functionality like maintaining users , login, logout... needs changes in out of the box code.
Is it possible to smoothly work with mongodb with defaults users functionality without many changes?
Do we really need lot many changes to work with mongodb extension? Can we expect gii works with mongodb in future?

Thanks in advance

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Dec 26, 2013

Member

Which changes do you mean exactly?

Member

samdark commented Dec 26, 2013

Which changes do you mean exactly?

@indicalabs

This comment has been minimized.

Show comment
Hide comment
@indicalabs

indicalabs Dec 26, 2013

Mongodb extension is expecting

  1. To have attributes() method in the model - which is okay.
  2. When we sign up, "status" field is not set with default value - So Not able to login
  3. There was an error sending email. - to reset password (because of empty/no STATUS field)
  4. Logout menu not enabled though I set status and succeed in Login.(Yii::$app->user->isGuest OR
    Yii::$app->user->identity->username was not set)
  5. $identity has not set, I think this is because mongodb will have "_id" but not "id" , If we add id, we also need to
    incorporate autoincrement of this "id" field.

I think if all this works by default, It would be great because out of the box "user" module is attractive and accelerate the development.
I am not very good to fix the issue because I am a Java programmer and fall in love with Yii and learned PHP recently.

Mongodb extension is expecting

  1. To have attributes() method in the model - which is okay.
  2. When we sign up, "status" field is not set with default value - So Not able to login
  3. There was an error sending email. - to reset password (because of empty/no STATUS field)
  4. Logout menu not enabled though I set status and succeed in Login.(Yii::$app->user->isGuest OR
    Yii::$app->user->identity->username was not set)
  5. $identity has not set, I think this is because mongodb will have "_id" but not "id" , If we add id, we also need to
    incorporate autoincrement of this "id" field.

I think if all this works by default, It would be great because out of the box "user" module is attractive and accelerate the development.
I am not very good to fix the issue because I am a Java programmer and fall in love with Yii and learned PHP recently.

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Dec 26, 2013

Member

@klimov-paul can you look into it?

Member

samdark commented Dec 26, 2013

@klimov-paul can you look into it?

@indicalabs

This comment has been minimized.

Show comment
Hide comment
@indicalabs

indicalabs Dec 26, 2013

Paul,
I think , there should be a way to deal with _id of mongodb, because having our own "id" returning as wrong id from ensureMongoId .

Paul,
I think , there should be a way to deal with _id of mongodb, because having our own "id" returning as wrong id from ensureMongoId .

@ghost ghost assigned klimov-paul Dec 26, 2013

@qiangxue qiangxue referenced this issue Dec 26, 2013

Closed

example error #1636

@klimov-paul

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Dec 26, 2013

Member

When we sign up, "status" field is not set with default value

How do you attempt to setup default value for the “status”? Please provide the code example.

Member

klimov-paul commented Dec 26, 2013

When we sign up, "status" field is not set with default value

How do you attempt to setup default value for the “status”? Please provide the code example.

@indicalabs

This comment has been minimized.

Show comment
Hide comment
@indicalabs

indicalabs Dec 26, 2013

For now I am able to resolve status field issue, but user module is not setting identity , because yii expects "id" where mongodb having "_id".

I am just expecting out of the box user module to work with mongodb by changing ActiveRecord

For now I am able to resolve status field issue, but user module is not setting identity , because yii expects "id" where mongodb having "_id".

I am just expecting out of the box user module to work with mongodb by changing ActiveRecord

@klimov-paul

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Dec 26, 2013

Member

What is this “user module” you are mentioned?

Member

klimov-paul commented Dec 26, 2013

What is this “user module” you are mentioned?

@indicalabs

This comment has been minimized.

Show comment
Hide comment
@indicalabs

indicalabs Dec 26, 2013

Sorry I call user module which Yii framework has out of the box functionality for "signup", "login" ,"logout" and "rese-password".

Sorry I call user module which Yii framework has out of the box functionality for "signup", "login" ,"logout" and "rese-password".

@klimov-paul

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Dec 26, 2013

Member

In that case it should be enough to change method “User::getId()” to be following:

public function getId()
{
    return $this->getPrimaryKey();
}
Member

klimov-paul commented Dec 26, 2013

In that case it should be enough to change method “User::getId()” to be following:

public function getId()
{
    return $this->getPrimaryKey();
}
@indicalabs

This comment has been minimized.

Show comment
Hide comment
@indicalabs

indicalabs Dec 26, 2013

Thank Paul. That is working for me now.
Currently "status" and "role" values are setting by the schema in the "user" table, that makes the new user Active by default.
If we make change to the code to set these two fields with default values as part of core Yii framework, yii2-mongo will work for everyone without touching framework code.

Thank Paul. That is working for me now.
Currently "status" and "role" values are setting by the schema in the "user" table, that makes the new user Active by default.
If we make change to the code to set these two fields with default values as part of core Yii framework, yii2-mongo will work for everyone without touching framework code.

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Dec 26, 2013

Member

Is it about advanced app template?

Member

samdark commented Dec 26, 2013

Is it about advanced app template?

@indicalabs

This comment has been minimized.

Show comment
Hide comment

Yes

@klimov-paul

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Dec 27, 2013

Member

@samdark, perhaps it is better you'll handle this.

Member

klimov-paul commented Dec 27, 2013

@samdark, perhaps it is better you'll handle this.

@ghost ghost assigned samdark Dec 27, 2013

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Dec 27, 2013

Member

OK. Will do when I'll be back home (mid-January).

Member

samdark commented Dec 27, 2013

OK. Will do when I'll be back home (mid-January).

@indicalabs

This comment has been minimized.

Show comment
Hide comment
@indicalabs

indicalabs Dec 28, 2013

samdark,
Just to be clear here,

  1. status and role to be set through code with default values
  2. and these two should return in identity which will be used in PhpManager.php as in the below $this->assign(Yii::$app->user->identity->id, Yii::$app->user->identity->role);
    So that this Active user can be validated in custom rbac.php as soon as he Signed up

samdark,
Just to be clear here,

  1. status and role to be set through code with default values
  2. and these two should return in identity which will be used in PhpManager.php as in the below $this->assign(Yii::$app->user->identity->id, Yii::$app->user->identity->role);
    So that this Active user can be validated in custom rbac.php as soon as he Signed up

@samdark samdark closed this in 515095b Dec 29, 2013

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Dec 29, 2013

Member

@Venu85 please check if it's better now. And thanks for your report.

Member

samdark commented Dec 29, 2013

@Venu85 please check if it's better now. And thanks for your report.

@indicalabs

This comment has been minimized.

Show comment
Hide comment
@indicalabs

indicalabs Dec 30, 2013

@samdark Login is successful now, the mongodb database has the below record after signup

{
    "_id" : ObjectId("52c158e721182fb801d63af6"),
    "username" : "22",
    "email" : "xxxx@yahoo.com",
    "create_time" : 1388402919,
    "update_time" : 1388402919,
    "password_hash" : "$2y$13$0KFR9.oDPVU.t.t21IoZkOA1l/97HAkkCKpciLSEJVpYE1Tr22PdO",
    "auth_key" : "3IJfPVjzM404Heyv8-JTJ0Zy26FGOckm"
}

But the problem is, Since there is no status and role set,

  1. User is not able to login after first logout, (because application is checking "status" - In case of mysql, status is setting with default value by database)
  2. I have configured roles to authorize few actions, which is failed with below error (because it is expecting Yii::$app->user->identity->role to be set
Invalid Parameter – yii\base\InvalidParamException
Unknown authorization item ''.
at /Sites/advanced/vendor/yiisoft/yii2/yii/rbac/PhpManager.php
*/
    public function assign($userId, $itemName, $bizRule = null, $data = null)
    {
        if (!isset($this->_items[$itemName])) {
            throw new InvalidParamException("Unknown authorization item '$itemName'.");

@samdark Login is successful now, the mongodb database has the below record after signup

{
    "_id" : ObjectId("52c158e721182fb801d63af6"),
    "username" : "22",
    "email" : "xxxx@yahoo.com",
    "create_time" : 1388402919,
    "update_time" : 1388402919,
    "password_hash" : "$2y$13$0KFR9.oDPVU.t.t21IoZkOA1l/97HAkkCKpciLSEJVpYE1Tr22PdO",
    "auth_key" : "3IJfPVjzM404Heyv8-JTJ0Zy26FGOckm"
}

But the problem is, Since there is no status and role set,

  1. User is not able to login after first logout, (because application is checking "status" - In case of mysql, status is setting with default value by database)
  2. I have configured roles to authorize few actions, which is failed with below error (because it is expecting Yii::$app->user->identity->role to be set
Invalid Parameter – yii\base\InvalidParamException
Unknown authorization item ''.
at /Sites/advanced/vendor/yiisoft/yii2/yii/rbac/PhpManager.php
*/
    public function assign($userId, $itemName, $bizRule = null, $data = null)
    {
        if (!isset($this->_items[$itemName])) {
            throw new InvalidParamException("Unknown authorization item '$itemName'.");

@samdark samdark reopened this Dec 30, 2013

@samdark samdark closed this in 8e013aa Jan 8, 2014

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Jan 8, 2014

Member

Forgot to update scenarios. Should be OK now.

Member

samdark commented Jan 8, 2014

Forgot to update scenarios. Should be OK now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment