當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::getIdentity方法代碼示例

本文整理匯總了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);
 }
開發者ID:ExtPoint,項目名稱:project-boilerplate,代碼行數:7,代碼來源:ContextUser.php

示例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"];
 }
開發者ID:rockielin,項目名稱:yii2-app-advanced-template,代碼行數:11,代碼來源:User.php

示例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);
 }
開發者ID:yinheark,項目名稱:yincart2,代碼行數:32,代碼來源:ActionAccessRule.php

示例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;
 }
開發者ID:yii2-tools,項目名稱:yii2-secure-ar,代碼行數:21,代碼來源:SecureBehavior.php

示例5: getIdentity

 /**
  * @param bool $autoRenew
  * @return null|\app\models\User
  */
 public function getIdentity($autoRenew = true)
 {
     return parent::getIdentity($autoRenew);
 }
開發者ID:remk-wadriga,項目名稱:calories-calculating-yii2-project,代碼行數:8,代碼來源:User.php

示例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;
 }
開發者ID:yii2-tools,項目名稱:yii2-secure-ar,代碼行數:25,代碼來源:SecureFilterBehavior.php


注:本文中的yii\web\User::getIdentity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。