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


PHP web\User類代碼示例

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


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

示例1: afterLogout

 /**
  * @inheritdoc
  */
 public function afterLogout($identity)
 {
     parent::afterLogout($identity);
     // обновляем время авторизации и статус online
     if ($identity && $identity instanceof \nepster\users\models\User) {
         $identity->time_activity = time();
         $identity->save(false);
     }
 }
開發者ID:nepster-web,項目名稱:yii2-module-users,代碼行數:12,代碼來源:User.php

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

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

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

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

示例6: matchUserRoles

 /**
  * Matches the web User object against the specified platform roles.
  * 
  * @param \yii\web\User $user
  * @return bool
  */
 public function matchUserRoles($user)
 {
     if (empty($this->userRoles)) {
         return true;
     }
     foreach ($this->userRoles as $role) {
         if (Role::check($role, $user->getRole())) {
             return true;
         }
     }
     return false;
 }
開發者ID:jlorente,項目名稱:yii2-app-advanced,代碼行數:18,代碼來源:AccessRule.php

示例7: authenticate

 /**
  * Authenticates the current user.
  *
  * @param \yii\web\User     $user
  * @param \yii\web\Request  $request
  * @param \yii\web\Response $response
  *
  * @return \yii\web\IdentityInterface the authenticated user identity. If authentication information is not
  *                                    provided, null will be returned.
  * @throws \yii\web\UnauthorizedHttpException if authentication information is provided but is invalid.
  */
 public function authenticate($user, $request, $response)
 {
     /** @var array $request */
     /** @noinspection PhpUndefinedFieldInspection */
     $request = Json::decode($request->rawBody);
     $token = ArrayHelper::getValue($request, $this->accessTokenPath);
     if (!$token || !($identity = $user->loginByAccessToken($token))) {
         \Yii::$app->session->remove(TokenAuth::DEFAULT_TOKEN_PATH);
         throw new UnauthorizedHttpException('Incorrect or expired token provided');
     }
     \Yii::$app->session->set(TokenAuth::DEFAULT_TOKEN_PATH, $token);
     return $identity;
 }
開發者ID:voodoo-mobile,項目名稱:yii2-api,代碼行數:24,代碼來源:TokenAuth.php

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

示例9: loginRequired

 /**
  * @inheritdoc
  */
 public function loginRequired($checkAjax = true, $checkAcceptHeader = true)
 {
     if ($this->enableSession && (!$checkAjax || !Yii::$app->getRequest()->getIsAjax())) {
         Yii::$app->session->setFlash('flash-warning', HUsers::t('messages', 'This page is restricted to authenticated users'));
     }
     return parent::loginRequired($checkAjax, $checkAcceptHeader);
 }
開發者ID:ChristopheBrun,項目名稱:hLib,代碼行數:10,代碼來源:WebUser.php

示例10: init

 /**
  * Initializes the User component
  */
 public function init()
 {
     if ($this->identityClass == null) {
         $this->identityClass = 'comyii\\user\\models\\User';
     }
     parent::init();
 }
開發者ID:vladim1,項目名稱:yii2-user,代碼行數:10,代碼來源:User.php

示例11: interception

 public function interception($event)
 {
     if (!isset(Yii::$app->i18n->translations['db_rbac'])) {
         Yii::$app->i18n->translations['db_rbac'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'sourceLanguage' => 'ru-Ru', 'basePath' => '@developeruz/db_rbac/messages'];
     }
     $route = Yii::$app->getRequest()->resolve();
     //Проверяем права по конфигу
     $this->createRule();
     $user = Instance::ensure(Yii::$app->user, User::className());
     $request = Yii::$app->getRequest();
     $action = $event->action;
     if (!$this->cheсkByRule($action, $user, $request)) {
         //И по AuthManager
         if (!$this->checkPermission($route)) {
             //Если задан $login_url и пользователь не авторизован
             if (Yii::$app->user->isGuest && $this->login_url) {
                 Yii::$app->response->redirect($this->login_url)->send();
                 exit;
             }
             //Если задан $redirect_url
             if ($this->redirect_url) {
                 Yii::$app->response->redirect($this->redirect_url)->send();
                 exit;
             } else {
                 throw new ForbiddenHttpException(Yii::t('db_rbac', 'Недостаточно прав'));
             }
         }
     }
 }
開發者ID:developeruz,項目名稱:yii2-db-rbac,代碼行數:29,代碼來源:AccessBehavior.php

示例12: init

 public function init()
 {
     parent::init();
     if ($this->userConfig !== null) {
         $this->userConfig = Instance::ensure($this->userConfig, UserConfig::className());
     }
 }
開發者ID:cdcchen,項目名稱:yii-plus,代碼行數:7,代碼來源:User.php

示例13: init

 /**
  * 初始化方法
  */
 public function init()
 {
     parent::init();
     //獲取user實例
     $this->user = Instance::ensure($this->user, User::className());
     $this->user_info = $this->user->identity;
 }
開發者ID:wangpengzhen,項目名稱:web,代碼行數:10,代碼來源:RbacControl.php

示例14: can

 /**
  * Checks if the user can perform the operation as specified by the given permission.
  *
  * Note that you must configure "authManager" application component in order to use this method.
  * Otherwise an exception will be thrown.
  *
  * @param string $permissionName the name of the permission (e.g. "edit post") that needs access check.
  * @param array $params name-value pairs that would be passed to the rules associated
  * with the roles and permissions assigned to the user. A param with name 'user' is added to
  * this array, which holds the value of [[id]].
  * @param boolean $allowCaching whether to allow caching the result of access check.
  * When this parameter is true (default), if the access check of an operation was performed
  * before, its result will be directly returned when calling this method to check the same
  * operation. If this parameter is false, this method will always call
  * [[\yii\rbac\ManagerInterface::checkAccess()]] to obtain the up-to-date access result. Note that this
  * caching is effective only within the same request and only works when `$params = []`.
  * @return boolean whether the user can perform the operation as specified by the given permission.
  * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
  */
 public function can($permissionName, $params = [], $allowCaching = true)
 {
     if (!$this->getIsGuest() && $this->getIdentity()->isSuperUser()) {
         return true;
     }
     return parent::can($permissionName, $params, $allowCaching);
 }
開發者ID:rkit,項目名稱:bootstrap-yii2,代碼行數:26,代碼來源:User.php

示例15: getUser

 /**
  * Get user
  * @return User
  */
 public function getUser()
 {
     if (!$this->_user instanceof User) {
         $this->_user = Instance::ensure($this->_user, User::className());
     }
     return $this->_user;
 }
開發者ID:WiconWang,項目名稱:CS-Iris,代碼行數:11,代碼來源:AccessControl.php


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