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


PHP User::getIsGuest方法代碼示例

本文整理匯總了PHP中yii\web\User::getIsGuest方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::getIsGuest方法的具體用法?PHP User::getIsGuest怎麽用?PHP User::getIsGuest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\web\User的用法示例。


在下文中一共展示了User::getIsGuest方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: denyAccess

 /**
  * Denies the access of the user.
  * The default implementation will redirect the user to the login page if he is a guest;
  * if the user is already logged, a 403 HTTP exception will be thrown.
  * @param  User $user the current user
  * @throws ForbiddenHttpException if the user is already logged in.
  */
 protected function denyAccess($user)
 {
     if ($user->getIsGuest()) {
         $user->loginRequired();
     } else {
         throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
     }
 }
開發者ID:thinkwill,項目名稱:yii2-admin,代碼行數:15,代碼來源:AccessControl.php

示例3: getIdentifier

 /**
  * @param string $default
  *
  * @return string
  */
 protected function getIdentifier($default)
 {
     $id = $default;
     if ($this->user instanceof User && !$this->user->getIsGuest()) {
         $id = $this->user->getId();
     }
     return $id;
 }
開發者ID:funfei1987,項目名稱:yii2-cart,代碼行數:13,代碼來源:DatabaseStorage.php

示例4: denyAccess

 /**
  * Denies the access of the user.
  * The default implementation will redirect the user to the login page if he is a guest;
  * if the user is already logged, a 403 HTTP exception will be thrown.
  * @param Yii\web\User $user the current user
  * @throws Yii\web\ForbiddenHttpException if the user is already logged in.
  */
 protected function denyAccess($user)
 {
     if ($user->getIsGuest()) {
         $user->loginRequired();
     } else {
         $this->ajaxOnly();
     }
 }
開發者ID:HEXA-UA,項目名稱:supervisor-manager,代碼行數:15,代碼來源:AjaxAccess.php

示例5: matchRole

 /**
  * @param \yii\web\User $user
  * @return bool
  */
 protected function matchRole($user)
 {
     if (empty($this->roles)) {
         return true;
     }
     foreach ($this->roles as $role) {
         if ($role === '?') {
             if ($user->getIsGuest()) {
                 return true;
             }
         } elseif ($role === '@') {
             if (!$user->getIsGuest()) {
                 return true;
             }
         } elseif (!$user->getIsGuest() && $role === $user->identity->role) {
             return true;
         }
     }
     return false;
 }
開發者ID:hauntd,項目名稱:help-center,代碼行數:24,代碼來源:AccessRule.php

示例6: denyAccess

 /**
  * 拒絕訪問
  * @param \yii\web\User $user
  * @throws ForbiddenHttpException
  */
 protected function denyAccess($user)
 {
     if ($user->getIsGuest()) {
         Yii::$app->getSession()->setFlash('danger', Yii::t('common', 'You have not login, please login first.'));
         $user->loginRequired();
     } else {
         //檢查權限是否有配置
         //             $this->checkAuthItem();
         throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
     }
 }
開發者ID:xidiao,項目名稱:gxfenxi,代碼行數:16,代碼來源:AccessControl.php

示例7: denyAccess

 /**
  * Denies the access of the user.
  * The default implementation will redirect the user to the login page if he is a guest;
  * if the user is already logged, a 403 HTTP exception will be thrown.
  * @param User $user the current user
  * @throws ForbiddenHttpException if the user is already logged in.
  */
 protected function denyAccess($user)
 {
     $rr = new RequestResponse();
     if ($user->getIsGuest()) {
         $authUrl = UrlHelper::construct("admin/auth")->setCurrentRef()->enableAdmin()->createUrl();
         if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
             $rr->redirect = $authUrl;
             return (array) $rr;
         } else {
             \Yii::$app->getResponse()->redirect($authUrl);
         }
     } else {
         throw new ForbiddenHttpException(\Yii::t('yii', \Yii::t('app', 'You are not allowed to perform this action.')));
     }
 }
開發者ID:Liv1020,項目名稱:cms,代碼行數:22,代碼來源:AdminAccessControl.php

示例8: matchRole

 /**
  * 覆寫方法
  * @param \yii\web\User $user
  * @return bool|void
  */
 protected function matchRole($user)
 {
     //如果沒有給點roles,那麽是所有的角色都可以用
     if (count($this->roles) === 0) {
         return true;
     }
     //分析所有配資了得roles,在controller的behaviors裏麵配置
     foreach ($this->roles as $role) {
         //?代表遊客
         if ($role === "?") {
             return true;
         } elseif (!$user->getIsGuest() && $role === $user->identity->role) {
             //判斷其他的權限
             return true;
         }
     }
     return false;
 }
開發者ID:csboyty,項目名稱:jinyuanwuye,代碼行數:23,代碼來源:AccessRule.php

示例9: denyAccess

 /**
  * Denies the access of the user.
  * The default implementation will redirect the user to the login page if he is a guest;
  * if the user is already logged, a 403 HTTP exception will be thrown.
  * @param User $user the current user
  * @throws ForbiddenHttpException if the user is already logged in.
  */
 protected function denyAccess($user)
 {
     if ($user->getIsGuest()) {
         $user->loginRequired();
     } else {
         throw new ForbiddenHttpException(Yii::t('yii', 'No esás autorizado para realizar eta acción.'));
     }
 }
開發者ID:sdram58,項目名稱:proyectofinal,代碼行數:15,代碼來源:AccessControl.php

示例10: matchRole

 /**
  * @param User $user the user object
  * @return boolean whether the rule applies to the role
  */
 protected function matchRole($user)
 {
     if (empty($this->roles)) {
         return true;
     }
     foreach ($this->roles as $role) {
         if ($role === '?' && $user->getIsGuest()) {
             return true;
         } elseif ($role === '@' && !$user->getIsGuest()) {
             return true;
         } elseif ($user->checkAccess($role)) {
             return true;
         }
     }
     return false;
 }
開發者ID:davidpersson,項目名稱:FrameworkBenchmarks,代碼行數:20,代碼來源:AccessRule.php


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