/** * Constructor for PPI_Acl * * @param boolean $p_bParse Default is true. If false it will not parse the default framework ini file. */ public function __construct($p_bParse = true) { if ($p_bParse === false) { return; } $oConfig = PPI_Model_Helper::getConfig(); $oDispatch = PPI_Model_Helper::getDispatcher(); if (!file_exists(CONFIGPATH . $oConfig->system->acl->filename)) { throw new PPI_Exception('Unable to locate access control file'); } $xml = simplexml_load_file(CONFIGPATH . $oConfig->system->acl->filename); if ($xml === false) { throw new PPI_Exception('Error parsing access controls'); } $aRules = array(); foreach ($xml as $rule) { $sController = (string) strtolower($rule->attributes()->controller); $aRule = array('controller' => $sController, 'method' => (string) strtolower($rule->attributes()->method), 'roles' => array()); foreach ($rule->children() as $role) { $sRole = (string) strtolower($role->attributes()->name); $aRule['roles'][$sRole] = (string) strtolower($role->attributes()->access); } $aRules[$sController] = $aRule; } $this->setRules($aRules); }
function putRecord(array $aData) { $oConfig = PPI_Helper::getConfig(); // If its an insert if (!array_key_exists($this->_iTableIndex, $aData)) { $plainPass = $aData['password']; if (!array_key_exists($oConfig->system->usernameField, $aData)) { throw new PPI_Exception('Unable to locate username field when creating user'); } $aData['active'] = isset($oConfig->system->defaultUserActive) && $oConfig->system->defaultUserActive != false ? 1 : 0; $aData['created'] = time(); $aData['activation_code'] = base64_encode(time()); // ----- Password Stuff ---- if (isset($aData['salt'])) { $sSalt = $aData['salt']; unset($aData['salt']); // If no salt has been set then we get it from the config. } else { $sSalt = $oConfig->system->userAuthSalt; } if (empty($sSalt)) { throw new PPI_Exception('No salt found when trying to register user'); } $aData['password'] = $this->encryptPassword($sSalt, $aData['password']); // If no role_id has been set, lets set it from the config. if (!isset($aData['role_id'])) { if (!isset($oConfig->system->defaultUserRole)) { throw new PPI_Exception('Missing config value system.defaultUserRole'); } $aData['role_id'] = PPI_Model_Helper::getRoleIDFromName($oConfig->system->defaultUserRole); } } else { //if password is being passed in for re-set, we need to encrypt it if (isset($aData['password'], $aData['salt'])) { $aData['password'] = $this->encryptPassword($aData['salt'], $aData['password']); unset($aData[$oConfig->system->usernameField]); unset($aData['salt']); } } return parent::putRecord($aData); // set the system log here // send acitvation email here //$oEmail = new PPI_Model_Email(); /*$oEmail->setTemplate('User Registration', array( 'site_name' => $oConfig->site_name, 'username' => $aData[$oConfig->usernameField], 'password' => $plainPass ))->sendMail();*/ }
/** * This function returns the role number of the user * * @todo Do a lookup for the guest user ID instead of defaulting to 1 * @return integer */ static function getRoleID() { $aUserInfo = PPI_Model_Helper::getInstance()->getAuthData(); return $aUserInfo !== false && count($aUserInfo) > 0 ? $aUserInfo['role_id'] : 1; }