/** * Adjusts user's ACL and block user if no subscriptions left. * * @param UserTable $user * @param string $cause cause of the change * @param int $block 1: block user, 0: don't block * @param int[] $gids new ACL gids (in Joomla < 1.6: only 1 entry) * @param int[] $removeGids old ACL gids from plans that just expired * @param array $oldChldGids old ACL gids and children * @param string $reason reason of change: 'N'=new subscription (default), 'R'=renewal, 'U'=update + 'X'=expiries */ protected function _adjustUserAclBlock($user, $cause, $block, $gids, $removeGids, $oldChldGids, $reason) { global $_CB_framework; if ($user && $user->id) { if (self::_anyValueOfArrayInArray((array) $user->gids, $oldChldGids)) { // test above is to not degrade higher-level users ! $wasBlocked = $user->block; $gidsUniqueSorted = array_unique($gids); sort($gidsUniqueSorted, SORT_NUMERIC); $userGids = array_unique((array) $user->gids); sort($userGids, SORT_NUMERIC); if ($block != $wasBlocked || $userGids != $gidsUniqueSorted) { $superadministratorgid = $_CB_framework->acl->mapGroupNamesToValues('Superadministrator'); $k_SA = array_search($superadministratorgid, $removeGids); if ($k_SA !== false) { unset($removeGids[$k_SA]); } $user->gids = array_unique(array_merge(array_diff($userGids, $removeGids), $gidsUniqueSorted)); sort($user->gids, SORT_NUMERIC); if ($block && !in_array($superadministratorgid, (array) $user->gids)) { $user->block = 1; } $oldPwd = $user->password; $user->password = null; // don't update cleartext password in case of registration $user->store(); // takes care of Mambo/Joomla ACL tables and many other stuff $user->password = $oldPwd; if (checkJversion() == 2) { // This is needed for instant adding of groups to logged-in user (fixing bug #3581): Can be removed once CB 1.9 is released: $session = JFactory::getSession(); $jUser = $session->get('user'); if ($jUser && $jUser->id == $user->id) { JAccess::clearStatics(); $session->set('user', new JUser((int) $user->id)); } } if ($block == 0 && $wasBlocked == 1) { $messagesToUser = $reason == 'N' && (!$user->lastvisitDate || $user->lastvisitDate == '0000-00-00 00:00:00'); activateUser($user, 0, 'PaidSubscription', $messagesToUser, $messagesToUser); //TBD: //FIXME Don't ACTIVATE user 2nd time if this function is called from subscription->activate as a result of onUserActivate? } } } } else { user_error(sprintf('AdjustUserAclBlock: user id %d not found in users table.', $user->id), E_USER_NOTICE); } }
/** * Store an array of values to user object * Used only in banUser function in FE: TODO: Change usage in banUser ? * * @param $values * @param bool $triggers * @return bool */ public function storeDatabaseValues($values, $triggers = true) { global $_CB_framework, $_PLUGINS; if ($this->id && is_array($values) && $values) { $ui = $_CB_framework->getUi(); $userVars = array_keys(get_object_vars($this)); $user = new UserTable($this->_db); $oldUserComplete = new UserTable($this->_db); foreach ($userVars as $k) { if (substr($k, 0, 1) != '_') { $user->set($k, $this->get($k)); $oldUserComplete->set($k, $this->get($k)); } } foreach ($values as $name => $value) { if (in_array($name, $userVars)) { $user->set($name, $value); } } if ($triggers) { if ($ui == 1) { $_PLUGINS->trigger('onBeforeUserUpdate', array(&$user, &$user, &$oldUserComplete, &$oldUserComplete)); } elseif ($ui == 2) { $_PLUGINS->trigger('onBeforeUpdateUser', array(&$user, &$user, &$oldUserComplete)); } } if (isset($values['password'])) { $clearTextPassword = $user->get('password'); $user->set('password', $this->hashAndSaltPassword($clearTextPassword)); } else { $clearTextPassword = null; $user->set('password', null); } $return = $user->store(); if ($clearTextPassword) { $user->set('password', $clearTextPassword); } if ($triggers) { if ($return) { if ($ui == 1) { $_PLUGINS->trigger('onAfterUserUpdate', array(&$user, &$user, $oldUserComplete)); } elseif ($ui == 2) { $_PLUGINS->trigger('onAfterUpdateUser', array(&$user, &$user, $oldUserComplete)); } } } $error = $user->getError(); if ($error) { $this->set('_error', $error); } unset($user, $oldUserComplete); return $return; } return false; }
/** * @param cbautoactionsActionTable $trigger * @param UserTable $user */ public function execute( $trigger, $user ) { if ( ! $user->get( 'id' ) ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_NO_USER', ':: Action [action] :: Usergroup skipped due to no user', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } return; } $cache = $user->get( 'password' ); $user->set( 'password', null ); foreach ( $trigger->getParams()->subTree( 'usergroup' ) as $row ) { /** @var ParamsInterface $row */ $groups = $row->get( 'groups', null, GetterInterface::STRING ); if ( $groups ) { $groups = explode( '|*|', $groups ); cbArrayToInts( $groups ); } $session = JFactory::getSession(); $jUser = $session->get( 'user' ); $isMe = ( $jUser ? ( $jUser->id == $user->get( 'id' ) ) : false ); switch ( $row->get( 'mode', 'add', GetterInterface::STRING ) ) { case 'create': $title = $trigger->getSubstituteString( $row->get( 'title', null, GetterInterface::STRING ) ); if ( ! $title ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_NO_TITLE', ':: Action [action] :: Usergroup skipped due to missing title', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $usergroup = JTable::getInstance( 'usergroup' ); $usergroup->load( array( 'title' => $title ) ); if ( ! $usergroup->id ) { $usergroup->parent_id = (int) $row->get( 'parent', 0, GetterInterface::INT ); $usergroup->title = $title; if ( ! $usergroup->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_CREATE_FAILED', ':: Action [action] :: Usergroup failed to create', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } } if ( $row->get( 'add', 1, GetterInterface::BOOLEAN ) ) { if ( ! in_array( $usergroup->id, $user->get( 'gids' ) ) ) { $user->gids[] = $usergroup->id; if ( ! $user->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_FAILED', ':: Action [action] :: Usergroup failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $user->getError() ) ) ); } continue; } if ( $isMe ) { JAccess::clearStatics(); $session->set( 'user', new JUser( $user->get( 'id' ) ) ); } } } break; case 'replace': if ( ! $groups ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_NO_GROUPS', ':: Action [action] :: Usergroup skipped due to missing groups', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $user->set( 'gids', $groups ); if ( ! $user->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_FAILED', ':: Action [action] :: Usergroup failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $user->getError() ) ) ); } continue; } if ( $isMe ) { JAccess::clearStatics(); $session->set( 'user', new JUser( $user->get( 'id' ) ) ); } break; case 'remove': if ( ! $groups ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_NO_GROUPS', ':: Action [action] :: Usergroup skipped due to missing groups', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $removed = false; foreach( $user->get( 'gids' ) as $k => $gid ) { if ( in_array( $gid, $groups ) ) { unset( $user->gids[$k] ); $removed = true; } } if ( $removed ) { if ( ! $user->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_FAILED', ':: Action [action] :: Usergroup failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $user->getError() ) ) ); } continue; } if ( $isMe ) { JAccess::clearStatics(); $session->set( 'user', new JUser( $user->get( 'id' ) ) ); } } break; case 'add': default: if ( ! $groups ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_NO_GROUPS', ':: Action [action] :: Usergroup skipped due to missing groups', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $usergroups = $groups; foreach( $usergroups as $k => $usergroup ) { if ( in_array( $usergroup, $user->get( 'gids' ) ) ) { unset( $usergroups[$k] ); } } if ( $usergroups ) { $user->set( 'gids', array_unique( array_merge( $user->get( 'gids' ), $usergroups ) ) ); if ( ! $user->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_USERGROUP_FAILED', ':: Action [action] :: Usergroup failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $user->getError() ) ) ); } continue; } if ( $isMe ) { JAccess::clearStatics(); $session->set( 'user', new JUser( $user->get( 'id' ) ) ); } } break; } } $user->set( 'password', $cache ); }
/** * @param cbautoactionsActionTable $trigger * @param UserTable $user */ public function execute( $trigger, $user ) { global $_CB_framework, $_PLUGINS, $ueConfig; $params = $trigger->getParams()->subTree( 'registration' ); $approve = (int) $params->get( 'approve', null, GetterInterface::INT ); $confirm = (int) $params->get( 'confirm', null, GetterInterface::INT ); $approval = ( $approve == 2 ? $ueConfig['reg_admin_approval'] : $approve ); $confirmation = ( $confirm == 2 ? $ueConfig['reg_confirmation'] : $confirm ); $usergroup = $params->get( 'usergroup', null, GetterInterface::STRING ); $password = $trigger->getSubstituteString( $params->get( 'password', null, GetterInterface::STRING ) ); $name = array(); if ( ! $usergroup ) { $gids = array( $_CB_framework->getCfg( 'new_usertype' ) ); } else { $gids = explode( '|*|', $usergroup ); } cbArrayToInts( $gids ); $newUser = new UserTable(); $newUser->set( 'gids', $gids ); $newUser->set( 'sendEmail', 0 ); $newUser->set( 'registerDate', $_CB_framework->getUTCDate() ); $newUser->set( 'username', $trigger->getSubstituteString( $params->get( 'username', null, GetterInterface::STRING ) ) ); $newUser->set( 'firstname', $trigger->getSubstituteString( $params->get( 'firstname', null, GetterInterface::STRING ) ) ); $newUser->set( 'middlename', $trigger->getSubstituteString( $params->get( 'middlename', null, GetterInterface::STRING ) ) ); $newUser->set( 'lastname', $trigger->getSubstituteString( $params->get( 'lastname', null, GetterInterface::STRING ) ) ); if ( $newUser->get( 'firstname' ) ) { $name[] = $newUser->get( 'firstname' ); } if ( $newUser->get( 'middlename' ) ) { $name[] = $newUser->get( 'middlename' ); } if ( $newUser->get( 'lastname' ) ) { $name[] = $newUser->get( 'lastname' ); } $newUser->set( 'name', implode( ' ', $name ) ); $newUser->set( 'email', $trigger->getSubstituteString( $params->get( 'email', null, GetterInterface::STRING ) ) ); if ( $password ) { $newUser->set( 'password', $newUser->hashAndSaltPassword( $password ) ); } else { $newUser->setRandomPassword(); $newUser->set( 'password', $newUser->hashAndSaltPassword( $newUser->get( 'password' ) ) ); } $newUser->set( 'registeripaddr', cbGetIPlist() ); if ( $approval == 0 ) { $newUser->set( 'approved', 1 ); } else { $newUser->set( 'approved', 0 ); } if ( $confirmation == 0 ) { $newUser->set( 'confirmed', 1 ); } else { $newUser->set( 'confirmed', 0 ); } if ( ( $newUser->get( 'confirmed' ) == 1 ) && ( $newUser->get( 'approved' ) == 1 ) ) { $newUser->set( 'block', 0 ); } else { $newUser->set( 'block', 1 ); } foreach ( $params->subTree( 'fields' ) as $row ) { /** @var ParamsInterface $row */ $field = $row->get( 'field', null, GetterInterface::STRING ); if ( $field ) { $newUser->set( $field, $trigger->getSubstituteString( $row->get( 'value', null, GetterInterface::RAW ), false, $row->get( 'translate', false, GetterInterface::BOOLEAN ) ) ); } } $_PLUGINS->trigger( 'onBeforeUserRegistration', array( &$newUser, &$newUser ) ); if ( ! $newUser->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_REGISTRATION_FAILED', ':: Action [action] :: Registration failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $newUser->getError() ) ) ); } return; } if ( ( $newUser->get( 'confirmed' ) == 0 ) && ( $confirmation != 0 ) ) { if ( ! $newUser->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_REGISTRATION_FAILED', ':: Action [action] :: Registration failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $newUser->getError() ) ) ); } return; } } if ( $params->get( 'supress', 1, GetterInterface::BOOLEAN ) ) { $emails = false; } else { $emails = true; } activateUser( $newUser, 1, 'UserRegistration', $emails, $emails ); $_PLUGINS->trigger( 'onAfterUserRegistration', array( &$newUser, &$newUser, true ) ); }