用户使用Yii2和MongoDB登录

时间:2015-02-19 12:09:36

标签: mongodb login yii2

有人可以建议我如何使用Yii2和MongoDB登录用户?我试过下面的例子,它们显示了同样的错误:

https://github.com/hipstercreative/yii2-user-mongo

https://github.com/sheillendra/yii2-user-mongo/tree/master

我逐个调试该函数,并从NULL

中定义的函数$this->getUser()获取LoginForm.php结果
public function login()
{
    if ($this->validate()) {
          return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);

    } else {
        return false;
    }
}

1 个答案:

答案 0 :(得分:0)

/**
 * Logs in a user using the provided username and password.
 *
 * @return bool whether the user is logged in successfully
 */
public function login() {
    if ($this->validate()) {
        return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
    }

    return false;
}

/**
 * Finds user by [[username]]
 *
 * @return User|null
 */
protected function getUser() {
    if ($this->_user === null) {
        $this->_user = User::find()->where(['email' => $this->emailorphone])->orWhere(['phone' => $this->emailorphone])->one();
    }

    return $this->_user;
}