Backend\Core\Engine\Authentication::isAllowedModule PHP Метод

isAllowedModule() публичный статический Метод

Is the given module allowed for the current user
public static isAllowedModule ( string $module ) : boolean
$module string The module to check for.
Результат boolean
    public static function isAllowedModule($module)
    {
        $modules = BackendModel::getModules();
        $alwaysAllowed = array('Core', 'Error', 'Authentication');
        $module = \SpoonFilter::toCamelCase((string) $module);
        // is this module a module that doesn't require user level authentication?
        if (in_array($module, $alwaysAllowed)) {
            return true;
        }
        // users that aren't logged in can only access always allowed items
        if (!self::isLoggedIn()) {
            return false;
        }
        // module is active and God user, good enough
        if (in_array($module, $modules) && self::getUser()->isGod()) {
            return true;
        }
        // do we already know something?
        if (empty(self::$allowedModules)) {
            // init var
            $db = BackendModel::get('database');
            // get allowed modules
            $allowedModules = $db->getColumn('SELECT DISTINCT grm.module
                 FROM users_sessions AS us
                 INNER JOIN users AS u ON us.user_id = u.id
                 INNER JOIN users_groups AS ug ON u.id = ug.user_id
                 INNER JOIN groups_rights_modules AS grm ON ug.group_id = grm.group_id
                 WHERE us.session_id = ? AND us.secret_key = ?', array(\SpoonSession::getSessionId(), \SpoonSession::get('backend_secret_key')));
            // add all modules
            foreach ($allowedModules as $row) {
                self::$allowedModules[$row] = true;
            }
        }
        // not available in our cache
        if (!isset(self::$allowedModules[$module])) {
            return false;
        } else {
            // return value that was stored in cache
            return self::$allowedModules[$module];
        }
    }

Usage Example

Пример #1
0
 private function getAllowedModule()
 {
     // create filter with modules which may not be displayed
     $filter = array('Authentication', 'Error', 'Core');
     // get all modules
     $modules = array_diff(BackendModel::getModules(), $filter);
     $allowedModule = false;
     if (BackendAuthentication::isAllowedModule('Dashboard')) {
         $allowedModule = 'Dashboard';
     } else {
         foreach ($modules as $module) {
             if (BackendAuthentication::isAllowedModule($module)) {
                 $allowedModule = $module;
                 break;
             }
         }
     }
     return $allowedModule;
 }
All Usage Examples Of Backend\Core\Engine\Authentication::isAllowedModule