Exemple #1
0
 /**
  * Useful for Menu widget
  *
  * <example>
  * 	...
  * 		[ 'label'=>'Some label', 'url'=>['/site/index'], 'visible'=>User::canRoute(['/site/index']) ]
  * 	...
  * </example>
  *
  * @param string|array $route
  * @param bool         $superAdminAllowed
  *
  * @return bool
  */
 public static function canRoute($route, $superAdminAllowed = true)
 {
     if ($superAdminAllowed and Yii::$app->user->isSuperadmin) {
         return true;
     }
     $baseRoute = AuthHelper::unifyRoute($route);
     if (Route::isFreeAccess($baseRoute)) {
         return true;
     }
     AuthHelper::ensurePermissionsUpToDate();
     return Route::isRouteAllowed($baseRoute, Yii::$app->session->get(AuthHelper::SESSION_PREFIX_ROUTES, []));
 }
Exemple #2
0
 /**
  * Check if controller has $freeAccess = true or $action in $freeAccessActions
  * Or it's login, logout, error page
  *
  * @param string $route
  * @param Action|null $action
  *
  * @return bool
  */
 public static function isFreeAccess($route, $action = null)
 {
     if ($action) {
         $controller = $action->controller;
         if ($controller->hasProperty('freeAccess') and $controller->freeAccess === true) {
             return true;
         }
         if ($controller->hasProperty('freeAccessActions') and in_array($action->id, $controller->freeAccessActions)) {
             return true;
         }
     }
     $systemPages = ['/user-management/auth/logout', AuthHelper::unifyRoute(Yii::$app->errorHandler->errorAction), AuthHelper::unifyRoute(Yii::$app->user->loginUrl)];
     if (in_array($route, $systemPages)) {
         return true;
     }
     // Registration can be enabled either by this option or by adding '/user-management/auth/registration' route to guest permissions
     if ($route == '/user-management/auth/registration' && Yii::$app->getModule('user-management')->enableRegistration === true) {
         return true;
     }
     if (static::isInCommonPermission($route)) {
         return true;
     }
     return false;
 }
Exemple #3
0
 /**
  * Check if controller has $freeAccess = true or $action in $freeAccessActions
  * Or it's login, logout, error page
  *
  * @param string $route
  * @param Action|null $action
  *
  * @return bool
  */
 public static function isFreeAccess($route, $action = null)
 {
     if ($action) {
         $controller = $action->controller;
         if ($controller->hasProperty('freeAccess') and $controller->freeAccess === true) {
             return true;
         }
         if ($controller->hasProperty('freeAccessActions') and in_array($action->id, $controller->freeAccessActions)) {
             return true;
         }
     }
     $systemPages = ['/' . \Yii::$app->user->moduleAliasName . '/auth/logout', AuthHelper::unifyRoute(Yii::$app->errorHandler->errorAction), AuthHelper::unifyRoute(Yii::$app->user->loginUrl())];
     if (in_array($route, $systemPages)) {
         return true;
     }
     if (static::isInCommonPermission($route) && \Yii::$app->user->id) {
         return true;
     }
     return false;
 }