本文整理汇总了PHP中yii\web\User::getIdentity方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getIdentity方法的具体用法?PHP User::getIdentity怎么用?PHP User::getIdentity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\web\User
的用法示例。
在下文中一共展示了User::getIdentity方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getIdentity
public function getIdentity($autoRenew = true)
{
if ($this->_overrideIdentity !== null) {
return $this->_overrideIdentity;
}
return parent::getIdentity($autoRenew);
}
示例2: getIdentity
/**
*
* overwrite 存到session
*/
public function getIdentity($autoRenew = true)
{
if (!Yii::$app->session["_userInfo"]) {
Yii::$app->session["_userInfo"] = parent::getIdentity($autoRenew);
}
return Yii::$app->session["_userInfo"];
}
示例3: matchActionAccess
/**
* check the permission, if we rewrite and controller, the controller id and module id is not changed
* @param \yii\base\Action $action
* @param \yii\web\User $user
* @param \yii\web\Request $request
* @return bool
*/
public function matchActionAccess($action, $user, $request)
{
if ($user->getIsGuest()) {
return false;
}
/** @var \core\auth\Module $authModule */
$authModule = \Yii::$app->getModule('core_auth');
foreach ($authModule->getAdmins() as $key => $admin) {
if ($user->getIdentity()->username == $admin['username']) {
return true;
}
}
if ($action->controller->module instanceof Application) {
$key = 'default' . '_' . $action->controller->id . '_' . $action->id;
} else {
$key = $action->getUniqueId();
$key = explode('/', $key);
array_shift($key);
$key = implode('_', $key);
}
$key = lcfirst(implode('', array_map(function ($k) {
return ucfirst($k);
}, explode('-', $key))));
return $user->can($key, $this->params);
}
示例4: checkSecureAccess
/**
* Returns true if $user can edit secure options for concrete entity ($owner).
* @param User $user
* @return bool
*/
public function checkSecureAccess(User $user)
{
Yii::trace("Checking secure access to '{$this->owner->className()}'" . PHP_EOL . 'Identifier: ' . VarDumper::dumpAsString($this->owner->getPrimaryKey(true)) . PHP_EOL . "User: {$user->getId()}", __METHOD__);
if (($identity = $user->getIdentity()) && $identity->isAdmin) {
return true;
}
if (empty($this->secureRoles)) {
return false;
}
foreach ($this->secureRoles as $item) {
if (!$user->can($item)) {
return false;
}
}
return true;
}
示例5: getIdentity
/**
* @param bool $autoRenew
* @return null|\app\models\User
*/
public function getIdentity($autoRenew = true)
{
return parent::getIdentity($autoRenew);
}
示例6: checkAccess
/**
* @param array $row
* @param SecureActiveQueryInterface $query
* @param User $user
* @return User
* @throws \LogicException
* @SuppressWarnings(PHPMD.ElseExpression)
*/
protected function checkAccess(array $row, SecureActiveQueryInterface $query, User $user)
{
$identifier = ($identity = $user->getIdentity()) ? $identity->username : 0;
Yii::trace("Checking access to row data for user '{$identifier}'" . PHP_EOL . VarDumper::dumpAsString($row), __METHOD__);
$secureItemField = $query->getSecureItemAttribute();
if (!isset($row[$secureItemField])) {
throw new \LogicException("Row from database should contain secure item field '{$secureItemField}'");
}
$permission = $row[$secureItemField];
if (!is_null($identity) && $identity->isAdmin) {
$result = true;
} else {
$result = $user->can($permission);
}
Yii::getLogger()->log(($result ? 'Access granted' : 'Access denied') . " for user '{$identifier}' (" . $permission . ')', $result ? Logger::LEVEL_INFO : Logger::LEVEL_WARNING, __METHOD__);
return $result;
}