Using multiple models in an identity

Comparing #2 with #3

Revision #3 was created by Néstor Acevedo Néstor Acevedo on Sep 16, 2021, 1:13:45 AM.

I added the method findByUsername inside Identity model, and I changed inside the method getUser from LoginForm, the static function to use Identity::findByUsername according with the common LoginForm model.

Content

[...]
}

public function validatePassword($password)
{
return password_verify($password, $this->_passwordHash);
}
 
    
 
    public static function findByUsername(username)
 
    {
 
        $model = Customer::find()->where(['username' => $username])->one();
 
        if (!$model) {
 
            $model = Supplier::find()->where(['username' => $username])->one();
 
        }
 
 
        if (!$model) {
 
            return false;
 
        }
 
 
        if ($model instanceof Customer) {
 
            $type = self::TYPE_CUSTOMER;
 
        } else {
 
            $type = self::TYPE_SUPPLIER;
 
        }
 
 
        $identity = new Identity();
 
        $identity->_id = $type . '-' . $model->id;
 
        $identity->_authkey = $model->authkey;
 
        $identity->_passwordHash = $model->password_hash;
 
        return $identity;
 
    }


public static function findIdentityByEmail($email)
[...]
{
if ($this->_user === false) {
$this->_user = Identity::find
IdentityByEmailByUsername($this->username);
}

return $this->_user;
}
}
[...]