/** * Getting groups of resources * @return array of string => ( id => string ) */ public static function getAsArray() { $config = App_Application::getInstance()->getConfig()->user->resource; $arrGroups = array(); foreach ($config as $strKey => $confGroups) { $arrResources = array(); foreach ($confGroups as $strResourceName => $strResourceId) { $arrResources[$strResourceId] = $strResourceName; } $arrGroups[$strKey] = $arrResources; } return $arrGroups; }
public function isPredefined() { // check configs for prefefined roles, // return Administrator - if not configured $confUser = App_Application::getInstance()->getConfig()->user; if (is_object($confUser) && $confUser->predefined) { return in_array($this->getName(), $confUser->predefined->toArray()); } return $this->getName() == 'Administrator'; }
/** * @return void */ protected function _addDefaultAccounts() { $cfgDefaultAccounts = App_Application::getInstance()->getConfig()->user->list; if (is_object($cfgDefaultAccounts)) { $cfgDefaultAccount = null; $tblRole = User_Role::Table(); $tblUserRole = User_UserRole::Table(); /** @var $cfgDefaultAccount User_Account */ foreach ($cfgDefaultAccounts as $cfgDefaultAccount) { $objAccount = $this->_addDefaultAccount($cfgDefaultAccount->toArray()); if (is_object($cfgDefaultAccount->roles)) { // add roles for a user... $arrRoles = $cfgDefaultAccount->roles; foreach ($arrRoles as $strRoleName) { $objRole = $tblRole->findByName($strRoleName); if (is_object($objRole) && !is_object($tblUserRole->findRole($objAccount->getId(), $objRole->getId()))) { $objUserRole = $tblUserRole->createRow(); $objUserRole->ucur_user_id = $objAccount->getId(); $objUserRole->ucur_role_id = $objRole->getId(); $objUserRole->save(); } } } } } }
/** * Overriden method delete, for deprecate full delete of object from db. * @return void */ public function delete() { $objConfig = App_Application::getInstance()->getConfig()->user; // config-based detection of what to do on deleting user // dometime we need to prevent deletion if ($objConfig->on_delete) { call_user_func_array($objConfig->on_delete, array('object' => $this)); } else { if ($objConfig->never_delete) { $this->ucac_status = User_Account::INACTIVE; $this->save(); } else { parent::delete(); } } }
public function preDispatch() { $config = App_Application::getInstance()->getConfig(); $arrUrlParams = $this->getDispatcher()->getUrlParams(); $arrUserAreas = array('admin' => array('theme' => 'admin', 'section' => 'backend', 'require_login' => 1)); if (is_object(App_Application::getInstance()->getConfig()->user->area)) { $arrUserAreas = App_Application::getInstance()->getConfig()->user->area->toArray(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - $strCurrentArea = ''; $strNextParam = ''; if (isset($arrUrlParams[1]) && isset($arrUserAreas[$arrUrlParams[1]])) { $strCurrentArea = $arrUrlParams[1]; if (isset($arrUrlParams[2])) { $strNextParam = $arrUrlParams[2]; } } else { if (isset($arrUrlParams[1])) { $strNextParam = $arrUrlParams[1]; } } //if ( $strCurrentArea == 'admin' ) die; foreach ($arrUserAreas as $strArea => $arrAreaProperties) { if (!isset($arrAreaProperties['theme'])) { throw new App_Exception('Theme was not specified for user area ' . $strArea); } if (!isset($arrAreaProperties['section'])) { throw new App_Exception('Section was not specified for user area ' . $strArea); } if ($strCurrentArea != $strArea) { continue; } // Sys_Io::out( 'CURRENT AREA: ' . $strCurrentArea . ' ' . $strArea ); $strBaseAreaUrl = str_replace('//', '/', str_replace('//', '/', App_Application::getInstance()->getConfig()->base . '/' . $strArea . '/')); $strSessionName = 'user_' . $strArea; $objSession = new App_Session_Namespace($strSessionName); if (isset($objSession->user_id) && $objSession->user_id != '') { /** @var $objUser User_Account */ $tblUser = User_Account::Table(); $selectUser = $tblUser->select()->where('ucac_id = ?', $objSession->user_id); $objUser = $tblUser->fetchRow($selectUser); if (is_object($objUser)) { Sys_Global::set('USER_LOGIN', $objUser->ucac_login); Sys_Global::set('USER_OBJECT', $objUser); // Sys_Global::set( 'USER_ROLES', $objUser->getRoles() ); // Sys_Debug::dumpDie( $objUser->getRoles() ); } if ($strNextParam == 'sign-out') { $objSession->user_id = 0; header('Location: ' . $strBaseAreaUrl); die; } } else { if (isset($_REQUEST['errcode'])) { Sys_Global::set('errcode', intval($_REQUEST['errcode'])); } if (isset($_REQUEST['login']) && isset($_REQUEST['password'])) { $tblUser = User_Account::Table(); $selectUser = $tblUser->select()->where('ucac_login = ?', $_REQUEST['login'])->where('ucac_password = ?', $_REQUEST['password']); $objUser = $tblUser->fetchRow($selectUser); if (is_object($objUser)) { if ($objUser->ucac_status == User_Account::ACTIVE) { if (isset($arrAreaProperties['role_forbidden'])) { if ($objUser->hasRole($arrAreaProperties['role_forbidden'])) { header('Location: ' . $strBaseAreaUrl . '?errcode=3'); die; } } if (isset($arrAreaProperties['role_required'])) { if (!$objUser->hasRole($arrAreaProperties['role_required'])) { header('Location: ' . $strBaseAreaUrl . '?errcode=3'); die; } } // Sys_Debug::dump( $objUser->getId() ); $objSession->user_id = $objUser->getId(); } else { header('Location: ' . $strBaseAreaUrl . '?errcode=2'); die; } header('Location: ' . $strBaseAreaUrl); die; } else { header('Location: ' . $strBaseAreaUrl . '?errcode=1'); die; } } if (isset($arrAreaProperties['require_login']) && $arrAreaProperties['require_login'] == 1) { $strViewClass = $config->default_renderer; if ($strViewClass) { $view = new $strViewClass(); } else { $view = new App_View(); } $arrThemes = $arrAreaProperties['theme']; if (!is_array($arrThemes)) { $arrThemes = array($arrThemes); } $pathsTpl = array(); foreach ($arrThemes as $strTheme) { $pathsTpl[] = CWA_APPLICATION_DIR . '/theme/' . $strTheme . '/' . $arrAreaProperties['section'] . '/auth.' . $view->getExtension(); } $view->setPath($pathsTpl); $view->errcode = isset($_REQUEST['errcode']) ? intval($_REQUEST['errcode']) : 0; echo $view->render(); die; } } // end of pre-dispatch // - - - - - - - - - - - - - - - - - - - - - - - - - - - - } return true; }