/** * Returns an instance of Vi_Auth * * Singleton pattern implementation * * @return Vi_Auth Provides a fluent interface */ public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; }
/** * Check not permission function * * @example {{p name='see_user' module='user'}}These words will be checked permission to apper...{{/p}} */ public static function checkNotPermisison($params, $content, &$smarty, &$repeat) { if (null == self::$_alc) { /** * Init alc */ $auth = Vi_Auth::getInstance(); self::$_alc = new Vi_Acl($auth->getIdentity()); } // echo "<pre>";print_r($params);die; /** * Skip the first, will translate in second running */ if (null == $content) { return ''; } if (null == @$params['expandId']) { $params['expandId'] = '*'; } if (true == self::$_alc->checkPermission(@$params['name'], @$params['module'], $params['expandId'])) { /** * Print data */ return ''; } else { return $content; } }
/** * constructor init all data */ public function __construct($username) { $this->_auth = Vi_Auth::getInstance(); $dbPrefix = Vi_Registry::getDBPrefix(); $db = Vi_Registry::getDB(); $sqlSelectPermission = "\r\n\t\t\t\tSELECT p.name as pkey, r.enabled as penabled, r.expand_table_id, p.module as module_name FROM\r\n\t\t\t\t\t(SELECT * FROM {$dbPrefix}user WHERE username = {$db->quote($username)}) u,\r\n\t\t\t\t\t{$dbPrefix}group_permission r,\r\n\t\t\t\t\t{$dbPrefix}permission p\r\n\t\t\t\tWHERE r.permission_id = p.permission_id AND u.group_id = r.group_id;"; $db = Vi_Registry::getDB(); $permissions = $db->fetchAll($sqlSelectPermission); $results = array(); foreach ($permissions as $per) { if (null == $per['expand_table_id']) { $results[$per['module_name']][$per['pkey']] = $per['penabled'] == '1' ? true : false; } else { $results[$per['module_name']][$per['pkey']][$per['expand_table_id']] = $per['penabled'] == '1' ? true : false; } } $this->_permissions = $results; }
/** * Init configuration */ public function init() { /** * Notify module type to translator */ $this->_currentType = Vi_Language::$currentType; $this->_currentName = Vi_Language::$currentName; Vi_Language::$currentType = Vi_Language::TYPE_MODULE; Vi_Language::$currentName = $this->_request->getModuleName(); /** * Add include path for controller */ set_include_path(get_include_path() . PATH_SEPARATOR . 'modules/' . Vi_Registry::getModuleName()); /** * start session for system */ $this->session = new Zend_Session_Namespace(Vi_Constant::SESSION_NAMESPACE . "_" . Vi_Registry::getAppName()); Vi_Registry::set('session', $this->session); /** * Load module config */ $this->_config = Vi_Registry::get('config'); $configFile = 'modules/' . $this->_request->getModuleName() . '/config.php'; if (is_file($configFile)) { $moduleConfig = (include $configFile); /** * Unset config item have values as default system */ $this->_unsetConfig($moduleConfig); /** * Merge with system config */ $this->_config = array_merge($this->_config, $moduleConfig); Vi_Registry::set('config', $this->_config); } /** * Load module constant */ $constantFile = 'modules/' . $this->_request->getModuleName() . '/Constant.php'; if (is_file($constantFile)) { include_once $constantFile; } /** * start up the auth */ $this->auth = Vi_Auth::getInstance(); $authStorage = new Vi_Auth_Storage(); $this->auth->setStorage($authStorage); Vi_Registry::set('auth', $this->auth); /** * Only ADMIN application need following function * * Don't remove comment if you need change. * In Vi_Controller_Action_Admin, this function is always loaded */ // $this->_initAcl();//Don't load permission as default }