3
反正有強迫yii
通過給定用戶名認證用戶而不諮詢數據庫嗎?Yii:強制認證
我的應用將使用api
登錄,直到api
未寫入,我們不能使用app
。
這個api
的東陽試圖用User::model()
public function authenticate()
{
if (strpos($this->username,"@")) {
$user=User::model()->findByAttributes(array('email'=>$this->username));
} else {
$user=User::model()->findByAttributes(array('username'=>$this->username));
}
if($user===null)
if (strpos($this->username,"@")) {
$this->errorCode=self::ERROR_EMAIL_INVALID;
} else {
$this->errorCode=self::ERROR_USERNAME_INVALID;
}
else if(Yii::app()->getModule('user')->encrypting($this->password)!==$user->password)
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else if($user->active==0&&Yii::app()->getModule('user')->loginNotActiv==false)
$this->errorCode=self::ERROR_STATUS_NOTACTIV;
else if($user->active==-1)
$this->errorCode=self::ERROR_STATUS_BAN;
else {
$this->_id=$user->id;
$this->errorCode=self::ERROR_NONE;
$user->saveState($this);
}
return !$this->errorCode;
}