robregonm / yii2-auth

Yii 2 User Authentication & Role Based Access Control (RBAC) Module
BSD 3-Clause "New" or "Revised" License
77 stars 37 forks source link

The password is not updated #27

Closed cansozeri closed 10 years ago

cansozeri commented 10 years ago

Hello,

When I update the user, everything can be updated but password not, I investigate the logs with yii debug and there is no db request for password update.

cansozeri commented 10 years ago

I have found that it is related about beforesave function.

In update process in beforeSave function, this part is not functioning. I do not know why but this part is only work with create call.

if (($this->isNewRecord || in_array($this->getScenario(), ['resetPassword', 'profile'])) && !empty($this->password)) {
                $this->password_hash = Security::generatePasswordHash($this->password);

            }

So I add

if (!empty($this->password)) {
                $this->password_hash = Security::generatePasswordHash($this->password);
            }

Now the function is like this and it works, maybe we have to change the first part of the function, if so how ???

public function beforeSave($insert)
    {

        if (parent::beforeSave($insert)) {
            if (($this->isNewRecord || in_array($this->getScenario(), ['resetPassword', 'profile'])) && !empty($this->password)) {
                $this->password_hash = Security::generatePasswordHash($this->password);

            }
            if ($this->isNewRecord) {
                $this->auth_key = Security::generateRandomKey();
            }
            if ($this->getScenario() !== \yii\web\User::EVENT_AFTER_LOGIN) {
                $this->setAttribute('update_time', new Expression('CURRENT_TIMESTAMP'));

            }

            if (!empty($this->password)) {
                $this->password_hash = Security::generatePasswordHash($this->password);
            }

            return true;

        }
        return false;
    }
DenisOgr commented 10 years ago

I have same problem. Have you fied it?

robregonm commented 10 years ago

This issue have been already fixed. However, could you post the steps for replicating this issue?

DenisOgr commented 10 years ago

I resolved this problem, it was my mistake, sorry. And also. Why do you not use protected functions in you classes? I want to extend your DefaultController, but it use private, and it compels me, copy some private functions. Thanks.