本文整理匯總了PHP中UserIdentity::apiAuthenticate方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserIdentity::apiAuthenticate方法的具體用法?PHP UserIdentity::apiAuthenticate怎麽用?PHP UserIdentity::apiAuthenticate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UserIdentity
的用法示例。
在下文中一共展示了UserIdentity::apiAuthenticate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: authenticate
/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute, $params)
{
if (!$this->hasErrors()) {
$identity = new UserIdentity($this->username, $this->password);
if (0 == $this->isapi) {
$identity->authenticate();
} else {
$identity->apiAuthenticate();
}
switch ($identity->errorCode) {
case UserIdentity::ERROR_NONE:
$accessableProducts = TestUserService::getAccessableProduct($identity->getId());
if (empty($accessableProducts)) {
$this->addError('username', Yii::t('LoginForm', 'no accessable product'));
} else {
$duration = 0;
if ($this->rememberMe) {
// keep login state duration
$duration = LoginForm::DURATION;
}
Yii::app()->user->login($identity, $duration);
UserLogService::createUserLog(array('created_by' => Yii::app()->user->id, 'created_at' => date(CommonService::DATE_FORMAT), 'ip' => $_SERVER['REMOTE_ADDR']));
LoginService::setLanguageCookie($this->language);
}
break;
case UserIdentity::ERROR_USERNAME_INVALID:
$this->addError('username', Yii::t('LoginForm', 'username is incorrect'));
break;
case UserIdentity::ERROR_CONNECT:
$this->addError('username', Yii::t('LoginForm', 'ldap connect failed'));
break;
case UserIdentity::ERROR_USER_DISABLED:
$this->addError('username', Yii::t('LoginForm', 'user disabled'));
break;
case UserIdentity::ERROR_LDAP_MISS:
$this->addError('username', Yii::t('LoginForm', 'ldap module disabled'));
break;
case UserIdentity::ERROR_USER_NOT_FOUND:
$this->addError('username', Yii::t('LoginForm', 'user not found') . ' <a href="' . Yii::app()->createUrl('site/permission') . '">' . Yii::t('LoginForm', 'permission tips') . '</a>');
break;
default:
// UserIdentity::ERROR_PASSWORD_INVALID {
$this->addError('password', Yii::t('LoginForm', 'password is incorrect'));
break;
}
}
}