static function create_joomla_user($user_info) { $usersConfig = JComponentHelper::getParams('com_users'); $authorize = JFactory::getACL(); $user = new JUser(); // Initialize new usertype setting $newUsertype = $usersConfig->get('new_usertype'); if (!$newUsertype) { $newUsertype = 'Registered'; } // Bind the user_info array to the user object if (!$user->bind($user_info)) { JError::raiseError(500, $user->getError()); } // Set some initial user values $user->set('id', 0); $user->set('usertype', $newUsertype); $system = 2; // ID of Registered $user->groups = array(); $user->groups[] = $system; $date = JFactory::getDate(); $user->set('registerDate', $date->toSql()); $parent = JFactory::getUser(); $user->setParam('u' . $parent->id . '_parent_id', $parent->id); if ($user_info['block']) { $user->set('block', '1'); } // If there was an error with registration if (!$user->save()) { return false; } /* Update profile additional data */ return JoomdleHelperMappings::save_user_info($user_info); }
/** * Tests JUser Parameter setting and retrieval. * * @return void * * @since 12.1 * * @covers JUser::defParam * @covers JUser::getParam * @covers JUser::setParam */ public function testParameter() { $this->assertThat($this->object->getParam('holy', 'fred'), $this->equalTo('fred')); $this->object->defParam('holy', 'batman'); $this->assertThat($this->object->getParam('holy', 'fred'), $this->equalTo('batman')); $this->object->setParam('holy', 'batman'); $this->assertThat($this->object->getParam('holy', 'fred'), $this->equalTo('batman')); }
/** * Joomla! user creator. * * @access public * @param string $username the username used for login. * @param string $name the name of the user. * @param string $email the user email. * @return the new user identifier or false if something wrong. * @since 0.6 */ function userCreate($username, $name, $email) { $user = new JUser(); $data = array("username" => $username, "name" => $name, "email" => $email, "usertype" => "Registered", "gid" => 18); $user->bind($data); $user->setParam('admin_language', ''); if ($user->save()) { return $user->id; } return false; }
static function create_joomla_user($user_info) { $usersConfig = JComponentHelper::getParams('com_users'); $authorize = JFactory::getACL(); $user = new JUser(); // Initialize new usertype setting $newUsertype = $usersConfig->get('new_usertype'); if (!$newUsertype) { $newUsertype = 2; } // Password comes hashed // On bind, Joomla hashes it again, so we save it before $password = $user_info['password']; // Bind the user_info array to the user object if (!$user->bind($user_info)) { JError::raiseError(500, $user->getError()); } // Manually set original hashed password $user->password = $password; // Set some initial user values $user->set('id', 0); $user->groups = array(); $user->groups[] = $newUsertype; $date = JFactory::getDate(); $user->set('registerDate', $date->toSql()); $parent = JFactory::getUser(); $user->setParam('u' . $parent->id . '_parent_id', $parent->id); if ($user_info['block']) { $user->set('block', '1'); } // If there was an error with registration if (!$user->save()) { JError::raiseError(500, $user->getError()); return false; } // Set password in crypted form // $u = new JObject (); // $u->id = $user->id; // $u->password = $password; /* Update profile additional data */ return JoomdleHelperMappings::save_user_info($user_info, false); }
public function registerUser($data) { $jxConfig = new JXConfig(); $verifyEmail = $jxConfig->cleanEmailList(array($data['email'])); if (!is_array($verifyEmail)) { $this->setError($verifyEmail); return false; } elseif ($data['password'] == $data['conf_pass']) { $user = new JUser(); $temp = new stdClass(); $temp->name = $data['name']; $temp->username = $data['username']; $temp->password = $data['password']; $temp->block = 0; $temp->sendEmail = 0; $temp->email = $data['email']; // set the default new user group, Registered $temp->groups[] = 2; $bindData = (array) $temp; $user->bind($bindData); if (isset($data['group_limited'])) { $user->setParam('groups_member_limited', $data['group_limited']); } if ($user->save()) { $activity = JTable::getInstance('Activity', 'StreamTable'); $activity->addUser($user->id); return $user->id; } else { $this->setError($user->getError()); return false; } } else { $this->setError(JText::_('COM_REGISTER_ERRMSG_PASSWORD_MISMATCH')); return false; } return false; }
/** * Method to set a parameter * * @param string $key Parameter key * @param mixed $value Parameter value * * @return self For chaining */ public function setParam($key, $value) { $this->cmsOwnUser->setParam($key, $value); return $this; }
/** * Bind the post data to the JUser object and the VM tables, then saves it * It is used to register new users * This function can also change already registered users, this is important when a registered user changes his email within the checkout. * * @author Max Milbers * @author Oscar van Eijk * @return boolean True is the save was successful, false otherwise. */ public static function storeVM25(&$data, $checkToken = TRUE, &$userModel, $opc_no_activation = false, &$opc) { $message = ''; $user = ''; $newId = 0; if ($checkToken) { JRequest::checkToken() or jexit('Invalid Token, while trying to save user'); } $mainframe = JFactory::getApplication(); if (empty($data)) { vmError('Developer notice, no data to store for user'); return false; } //To find out, if we have to register a new user, we take a look on the id of the usermodel object. //The constructor sets automatically the right id. $user = JFactory::getUser(); $user_id = $user->id; $new = $user->id < 1; if (empty($user_id)) { $user = new JUser(); //thealmega http://forum.virtuemart.net/index.php?topic=99755.msg393758#msg393758 } else { $user = JFactory::getUser($user_id); } $gid = $user->get('gid'); // Save original gid // Preformat and control user datas by plugin JPluginHelper::importPlugin('vmuserfield'); $dispatcher = JDispatcher::getInstance(); $valid = true; $dispatcher->trigger('plgVmOnBeforeUserfieldDataSave', array(&$valid, $user_id, &$data, $user)); // $valid must be false if plugin detect an error if ($valid == false) { return false; } // Before I used this "if($cart && !$new)" // This construction is necessary, because this function is used to register a new JUser, so we need all the JUser data in $data. // On the other hand this function is also used just for updating JUser data, like the email for the BT address. In this case the // name, username, password and so on is already stored in the JUser and dont need to be entered again. if (empty($data['email'])) { $email = $user->get('email'); if (!empty($email)) { $data['email'] = $email; } } $data['email'] = str_replace(array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $data['email']); unset($data['isRoot']); unset($data['groups']); unset($data['_authGroups']); //This is important, when a user changes his email address from the cart, //that means using view user layout edit_address (which is called from the cart) $user->set('email', $data['email']); if (empty($data['name'])) { $name = $user->get('name'); if (!empty($name)) { $data['name'] = $name; } } if (empty($data['name'])) { $data['name'] = ''; if (!empty($data['first_name'])) { $data['name'] = $data['first_name']; } if ($data['name'] == '_') { $data['name'] = ''; } if (!empty($data['last_name'])) { $data['name'] = $data['last_name']; } if ($data['name'] == '_') { $data['name'] = ''; } if (empty($data['name'])) { $data['name'] = $data['username']; } if ($data['name'] == '_') { $data['name'] = ''; } if (empty($data['name'])) { $data['name'] = $data['email']; } } if (empty($data['username'])) { $username = $user->get('username'); if (!empty($username)) { $data['username'] = $username; } else { $data['username'] = JRequest::getVar('username', '', 'post', 'username'); if (empty($data['username'])) { $data['username'] = $data['email']; } } } if (empty($data['password'])) { $data['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW); } if (empty($data['password2'])) { $data['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW); } if (!$new && !empty($data['password']) && empty($data['password2'])) { unset($data['password']); unset($data['password2']); } $usersConfig = JComponentHelper::getParams('com_users'); $usernamechange = $usersConfig->get('change_login_name', true); if (!$new) { if (empty($usernamechange)) { $data['username'] = $user->get('username'); } } if (!$user->authorise('core.admin', 'com_virtuemart')) { $whiteDataToBind = array(); $whiteDataToBind['name'] = $data['name']; $whiteDataToBind['username'] = $data['username']; $whiteDataToBind['email'] = $data['email']; if (isset($data['password'])) { $whiteDataToBind['password'] = $data['password']; } if (isset($data['password2'])) { $whiteDataToBind['password2'] = $data['password2']; } } else { $whiteDataToBind = $data; } // Bind Joomla userdata if (!$user->bind($whiteDataToBind)) { foreach ($user->getErrors() as $error) { // vmError('user bind '.$error); vmError('user bind ' . $error, JText::sprintf('COM_VIRTUEMART_USER_STORE_ERROR', $error)); } $message = 'Couldnt bind data to joomla user'; } if ($new) { // If user registration is not allowed, show 403 not authorized. // But it is possible for admins and storeadmins to save /* JPluginHelper::importPlugin('user'); JPluginHelper::importPlugin('system'); $dispatcher = JDispatcher::getInstance(); $valid = true ; $dispatcher->trigger('onAfterStoreUser',array($user,true,true,'' )); */ if (!defined('VM_VERSION') || VM_VERSION < 3) { if (!class_exists('Permissions')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'permissions.php'; } if (!Permissions::getInstance()->check("admin,storeadmin") && $usersConfig->get('allowUserRegistration') == '0') { VmConfig::loadJLang('com_virtuemart'); //JError::raiseError( 403, JText::_('COM_VIRTUEMART_ACCESS_FORBIDDEN')); $data['virtuemart_user_id'] = 0; unset($data['username']); unset($data['password']); unset($data['password2']); $user = new JUser(); $userModel->_id = 0; //$userModel->saveUserData($data); $opc->userStoreAddress($userModel, $data); return false; } $authorize = JFactory::getACL(); } else { $authorize = JFactory::getUser(); if (!($authorize->authorise('core.admin', 'com_virtuemart') or $authorize->authorise('core.manage', 'com_virtuemart')) and $usersConfig->get('allowUserRegistration') == '0') { VmConfig::loadJLang('com_virtuemart'); vmError(vmText::_('COM_VIRTUEMART_ACCESS_FORBIDDEN')); $data['virtuemart_user_id'] = 0; unset($data['username']); unset($data['password']); unset($data['password2']); $user = new JUser(); $userModel->_id = 0; //$userModel->saveUserData($data); $opc->userStoreAddress($userModel, $data); return false; } } // Initialize new usertype setting $newUsertype = $usersConfig->get('new_usertype'); if (!$newUsertype) { if (JVM_VERSION === 1) { $newUsertype = 'Registered'; } else { $newUsertype = 2; } } // Set some initial user values $user->set('usertype', $newUsertype); if (JVM_VERSION === 1) { $user->set('gid', $authorize->get_group_id('', $newUsertype, 'ARO')); } else { $user->groups[] = $newUsertype; } $date = JFactory::getDate(); if (method_exists($date, 'toMySQL')) { $user->set('registerDate', $date->toMySQL()); } else { $user->set('registerDate', $date->toSQL()); } // If user activation is turned on, we need to set the activation information $useractivation = $usersConfig->get('useractivation'); if (!empty($opc_no_activation)) { $useractivation = false; } $doUserActivation = false; if (JVM_VERSION === 1) { if ($useractivation == '1') { $doUserActivation = true; } } else { if ($useractivation == '1' or $useractivation == '2') { $doUserActivation = true; } } vmdebug('user', $useractivation, $doUserActivation); if ($doUserActivation) { jimport('joomla.user.helper'); if (method_exists('JApplication', 'getHash')) { $user->set('activation', JApplication::getHash(JUserHelper::genRandomPassword())); } else { $user->set('activation', JUtility::getHash(JUserHelper::genRandomPassword())); } //$user->set('activation', JUtility::getHash( JUserHelper::genRandomPassword()) ); $user->set('block', '1'); //$user->set('lastvisitDate', '0000-00-00 00:00:00'); } } $option = JRequest::getCmd('option'); // If an exising superadmin gets a new group, make sure enough admins are left... if (!$new && $user->get('gid') != $gid && $gid == __SUPER_ADMIN_GID) { if (method_exists($userModel, 'getSuperAdminCount')) { if ($userModel->getSuperAdminCount() <= 1) { vmError(JText::_('COM_VIRTUEMART_USER_ERR_ONLYSUPERADMIN')); return false; } } } if (isset($data['language'])) { $user->setParam('language', $data['language']); } else { if (isset($data['order_language'])) { $user->setParam('language', $data['order_language']); } } // Save the JUser object $regfail = false; if (!$user->save()) { vmError(JText::_($user->getError()), JText::_($user->getError())); $regfail = true; } //vmdebug('my user, why logged in? ',$user); if (!$regfail) { $newId = $user->get('id'); } else { $newId = 0; } $data['virtuemart_user_id'] = $newId; //We need this in that case, because data is bound to table later $regid = $user->get('id'); if (!empty($regid)) { $GLOBALS['opc_new_user'] = $user->get('id'); } else { $GLOBALS['opc_new_user'] = $newId; } //$this->setUserId($newId); $userModel->_id = $newId; $userModel->_data = null; //Save the VM user stuff if (!empty($data['quite'])) { $msgqx1 = JFactory::getApplication()->get('messageQueue', array()); $msgqx2 = JFactory::getApplication()->get('_messageQueue', array()); } if (!empty($newId)) { include JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php'; if ($new || $allow_sg_update) { $userdata = $userModel->saveUserData($data); $groups = array(); if (method_exists($userModel, 'getCurrentUser')) { $user2 = $userModel->getCurrentUser(); $groups = $user2->shopper_groups; } $shoppergroupmodel = VmModel::getModel('ShopperGroup'); $default = $shoppergroupmodel->getDefault(0); if (!empty($default)) { $default_id = $default->virtuemart_shoppergroup_id; } else { $default_id = 1; } $default1 = $shoppergroupmodel->getDefault(1); if (!empty($default1)) { $default1 = $default1->virtuemart_shoppergroup_id; } else { $default1 = 2; } require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'shoppergroups.php'; OPCShopperGroups::getSetShopperGroup(false); $session = JFactory::getSession(); $ids = $session->get('vm_shoppergroups_add', array(), 'vm'); if (!empty($groups)) { $ids = array_merge($ids, $groups); } $remove = $session->get('vm_shoppergroups_remove', array(), 'vm'); if (!empty($remove)) { foreach ($remove as $sr) { foreach ($ids as $key => $sg) { if ($sg == $sr) { unset($ids[$key]); } } } } if (!empty($ids)) { foreach ($ids as $key => $sg) { if ($sg == $default) { unset($ids[$key]); } if (empty($sg)) { unset($ids[$key]); } if ($sg == $default1) { unset($ids[$key]); } } } if (empty($data['virtuemart_shoppergroup_id']) or $data['virtuemart_shoppergroup_id'] == $default->virtuemart_shoppergroup_id) { $data['virtuemart_shoppergroup_id'] = array(); } if (!empty($ids)) { $ids = array_unique($ids); //stAn, opc 250: $data['virtuemart_shoppergroup_id'] = $sg; $data['virtuemart_shoppergroup_id'] = $ids; // Bind the form fields to the table $db = JFactory::getDBO(); if (!empty($ids)) { foreach ($ids as $ssg) { $q = 'select * from #__virtuemart_vmuser_shoppergroups where virtuemart_user_id = ' . (int) $newId . ' and virtuemart_shoppergroup_id = ' . (int) $ssg . ' limit 0,1'; $db->setQuery($q); $res = $db->loadAssocList(); if (empty($res)) { $q = "insert into `#__virtuemart_vmuser_shoppergroups` (id, virtuemart_user_id, virtuemart_shoppergroup_id) values (NULL, " . (int) $newId . ", " . (int) $ssg . ")"; $db->setQuery($q); $db->query(); } } } } } } //$userAddress = $userModel->storeAddress($data); $userAddress = $opc->userStoreAddress($userModel, $data); if (!empty($data['quite'])) { $x = JFactory::getApplication()->set('messageQueue', $msgqx1); $x = JFactory::getApplication()->set('_messageQueue', $msgqx2); } if (empty($userdata) || empty($userAddress)) { // we will not show the error because if we display only register fields, but an account field is marked as required, it still gives an error if (empty($data['quite'])) { vmError('COM_VIRTUEMART_NOT_ABLE_TO_SAVE_USER_DATA'); } // vmError(Jtext::_('COM_VIRTUEMART_NOT_ABLE_TO_SAVE_USERINFO_DATA')); } if (!$regfail) { if ($new) { // make sure that VM has proper user: if (!empty($newId)) { //JFactory::getUser()->load($newId); if (!class_exists('VirtueMartViewUser')) { require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'overrides' . DS . 'virtuemart.user.registration.view.html.php'; } OPCUser::sendRegistrationEmail($user, $user->password_clear, $doUserActivation, $data); } if ($doUserActivation) { vmInfo('COM_VIRTUEMART_REG_COMPLETE_ACTIVATE'); } else { //vmInfo('COM_VIRTUEMART_REG_COMPLETE'); $user->set('activation', ''); $user->set('block', '0'); $user->set('guest', '0'); } } } //The extra check for isset vendor_name prevents storing of the vendor if there is no form (edit address cart) // stAn, let's not alter vendor /* if((int)$data['user_is_vendor']==1 and isset($data['vendor_name'])){ vmdebug('vendor recognised '.$data['virtuemart_vendor_id']); if($userModel->storeVendorData($data)){ if ($new) { if ($doUserActivation ) { vmInfo('COM_VIRTUEMART_REG_VENDOR_COMPLETE_ACTIVATE'); } else { vmInfo('COM_VIRTUEMART_REG_VENDOR_COMPLETE'); } } else { vmInfo('COM_VIRTUEMART_VENDOR_DATA_STORED'); } } } */ return array('user' => $user, 'password' => $data['password'], 'message' => $message, 'newId' => $newId, 'success' => !$regfail); }
/** * Purge all JBZoo params * @return bool */ public function purgeParams() { $this->_user->setParam(self::PARAM_NAMESPACE, array()); return $this->_user->save(true); }
function published($publish) { $db = JFactory::getDBO(); $ids = JRequest::getVar('cid', array()); $ids = implode(',', $ids); $query = "UPDATE #__jav_items" . " SET published = " . intval($publish) . " WHERE id IN ( {$ids} )"; $db->setQuery($query); if (!$db->query()) { return false; } foreach (JRequest::getVar('cid', array()) as $id) { $item = $this->getItem(array($id)); $logs = $this->getLogs(" and item_id={$id}"); if ($logs) { foreach ($logs as $log) { $user = JFactory::getUser($log->user_id); $user_no_session = new JUser($log->user_id); $total_voted = (int) $user_no_session->getParam('total-voted-' . $item->voice_types_id); if ($publish == 0) { $total_voted = (int) ($total_voted - abs($log->votes)); } else { $total_voted = (int) ($total_voted + abs($log->votes)); } if ($total_voted < 0) { $total_voted = 0; } $user_no_session->setParam('total-voted-' . $item->voice_types_id, $total_voted); $user_no_session->save(); } } } return true; }
function register_save() { $otherlanguage = JFactory::getLanguage(); $otherlanguage->load('com_user', JPATH_SITE); $usersConfig = JComponentHelper::getParams('com_users'); if ($usersConfig->get('allowUserRegistration') == '0') { JError::raiseError(403, JText::_('Access Forbidden')); return; } $authorize = JFactory::getACL(); $user = new JUser(); $system = 2; // ID of Registered $user->groups = array(); $user->groups[] = $system; // Bind the post array to the user object $post = JRequest::get('post'); if (!$user->bind($post, 'usertype')) { JError::raiseError(500, $user->getError()); } // Set some initial user values $user->set('id', 0); $date = JFactory::getDate(); $user->set('registerDate', $date->toSql()); $parent = JFactory::getUser(); $user->setParam('u' . $parent->id . '_parent_id', $parent->id); // If user activation is turned on, we need to set the activation information $useractivation = $usersConfig->get('useractivation'); if ($useractivation == 1 || $useractivation == 2) { jimport('joomla.user.helper'); $user->set('activation', JApplication::getHash(JUserHelper::genRandomPassword())); $user->set('block', '1'); } // If there was an error with registration, set the message and display form if (!$user->save()) { JError::raiseWarning('', JText::_($user->getError())); $this->setRedirect('index.php?option=com_joomdle&view=register'); return false; } // Add to profile type if needed $params = JComponentHelper::getParams('com_joomdle'); $children_pt = $params->get('children_profiletype'); if ($children_pt) { JoomdleHelperProfiletypes::add_user_to_profile($user->id, $children_pt); } // Send registration confirmation mail $password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW); $password = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $password); //Disallow control chars in the email // UserController::_sendMail($user, $password); JoomdleHelperSystem::send_registration_email($user->username, $password); $parent_user = JFactory::getUser(); // Set parent role in Moodle JoomdleHelperContent::call_method("add_parent_role", $user->username, $parent_user->username); $message = JText::_('COM_JOOMDLE_USER_CREATED'); $this->setRedirect('index.php?option=com_joomdle&view=register', $message); //XXX poenr un get current uri }
/** * Swap the authorization code for a persistent token and authorize access * to Joomla!. * * @return bool True if the authorization is successful, false otherwise. */ public function onOauthAuthorize() { $oauth = new JTwitterOAuth(); $oauth->setOption('consumer_key', $this->params->get('clientid')); $oauth->setOption('consumer_secret', $this->params->get('clientsecret')); $oauth->setOption('sendheaders', true); $oauth->authenticate(); $twitter = new JTwitter($oauth); $token = $twitter->oauth->getToken(); $settings = $twitter->profile->getSettings(); // Get the log in credentials. $credentials = array(); $credentials['username'] = $this->_name . '/' . $settings->screen_name; $credentials['name'] = $settings->screen_name; if (isset($settings->email)) { $credentials['email'] = $settings->email; } else { // we need an email for the auto-register to succeed. $credentials['email'] = $settings->screen_name . '@twitter.com'; } $options = array(); $app = JFactory::getApplication(); // Perform the log in. if (true === $app->login($credentials, $options)) { $user = new JUser(JUserHelper::getUserId($credentials['username'])); $user->setParam('twitter.token.key', JArrayHelper::getValue($token, 'key')); $user->setParam('twitter.token.secret', JArrayHelper::getValue($token, 'secret')); $user->save(); return true; } else { return false; } }