Exemple #1
0
 public static function createUser($email, $data)
 {
     if (empty($email)) {
         return false;
     }
     $email = strtolower(trim($email));
     $lang = JFactory::getLanguage();
     $lang->load('com_user', JPATH_SITE, null, true);
     $lang->load('com_user', JPATH_ADMINISTRATOR, null, true);
     $lang->load('com_users', JPATH_ADMINISTRATOR, null, true);
     $lang->load('com_rsmembership', JPATH_SITE);
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     if ($user_id = RSMembership::checkUser($email)) {
         $user = JFactory::getUser($user_id);
         $password = JText::_('COM_RSMEMBERSHIP_HIDDEN_PASSWORD_TEXT');
         RSMembership::sendUserEmail($user, $password, $data->fields, false);
         return $user_id;
     }
     jimport('joomla.user.helper');
     // Get required system objects
     $user = clone JFactory::getUser(0);
     if (!RSMembershipHelper::getConfig('full_email_username')) {
         @(list($username, $domain) = explode('@', $email));
     } else {
         $username = $email;
     }
     if (RSMembershipHelper::getConfig('choose_username') && !empty($data->username)) {
         $username = $data->username;
     }
     $query->clear();
     $query->select($db->qn('id'))->from($db->qn('#__users'))->where($db->qn('username') . ' LIKE ' . $db->q($username));
     $db->setQuery($query, 0, 1);
     if (preg_match("#[<>\"'%;()&]#i", $username) || strlen(utf8_decode($username)) < 2) {
         $username = JFilterOutput::stringURLSafe($data->name);
         if (strlen($username) < 2) {
             $username = str_pad($username, 2, mt_rand(0, 9));
         }
     }
     while ($db->loadResult()) {
         $username .= mt_rand(0, 9);
         $query->clear();
         $query->select($db->qn('id'))->from($db->qn('#__users'))->where($db->qn('username') . ' LIKE ' . $db->q($username));
         $db->setQuery($query, 0, 1);
     }
     // Bind the post array to the user object
     $post = array();
     $post['name'] = $data->name;
     if (trim($post['name']) == '') {
         $post['name'] = $email;
     }
     $post['email'] = $email;
     $post['username'] = $username;
     $post['password'] = JUserHelper::genRandomPassword(8);
     $original = $post['password'];
     $post['password2'] = $post['password'];
     if (!$user->bind($post, 'usertype')) {
         JError::raiseError(500, $user->getError());
     }
     // Set some initial user values
     $user->set('id', 0);
     $usersConfig = JComponentHelper::getParams('com_users');
     $user->set('groups', array($usersConfig->get('new_usertype', 2)));
     $date = JFactory::getDate();
     $user->set('registerDate', $date->toSql());
     // If user activation is turned on, we need to set the activation information
     $useractivation = $usersConfig->get('useractivation');
     if ($useractivation == 1 || $useractivation == 2) {
         $user->set('activation', JApplication::getHash($post['password']));
         $user->set('block', '1');
     }
     $user->set('lastvisitDate', '0000-00-00 00:00:00');
     // If there was an error with registration, set the message
     if (!$user->save()) {
         return false;
         JError::raiseWarning('', JText::_($user->getError()));
     }
     // Send registration confirmation mail
     $password = $original;
     // Disallow control chars in the email
     $password = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $password);
     if (RSMembershipHelper::getConfig('choose_password') && !empty($data->password)) {
         $query->clear();
         $query->update($db->qn('#__users'))->set($db->qn('password') . ' = ' . $db->q($data->password))->where($db->qn('id') . ' = ' . $db->q($user->get('id')));
         $db->setQuery($query);
         $db->execute();
         $password = JText::_('COM_RSMEMBERSHIP_HIDDEN_PASSWORD_TEXT');
     }
     RSMembership::sendUserEmail($user, $password, $data->fields);
     RSMembership::createUserData($user->get('id'), $data->fields);
     return $user->get('id');
 }
 function createUser($email, $data)
 {
     if (empty($email)) {
         return false;
     }
     $email = strtolower($email);
     $lang =& JFactory::getLanguage();
     $lang->load('com_user', JPATH_SITE, null, true);
     $lang->load('com_user', JPATH_ADMINISTRATOR, null, true);
     $lang->load('com_users', JPATH_ADMINISTRATOR, null, true);
     $lang->load('com_rsmembership', JPATH_SITE);
     $db = JFactory::getDBO();
     $db->setQuery("SELECT `id` FROM #__users WHERE `email` LIKE '" . $db->getEscaped($email) . "' LIMIT 1");
     if ($user_id = $db->loadResult()) {
         $user =& JFactory::getUser($user_id);
         $password = JText::_('RSM_HIDDEN_PASSWORD_TEXT');
         RSMembership::sendUserEmail($user, $password, $data->fields, false);
         return $user_id;
     }
     jimport('joomla.user.helper');
     // Get required system objects
     $user = clone JFactory::getUser(0);
     @(list($username, $domain) = explode('@', $email));
     if (RSMembershipHelper::getConfig('choose_username') && !empty($data->username)) {
         $username = $data->username;
     }
     $db->setQuery("SELECT `id` FROM #__users WHERE `username` LIKE '" . $db->getEscaped($username) . "' LIMIT 1");
     if (preg_match("#[<>\"'%;()&]#i", $username) || strlen(utf8_decode($username)) < 2) {
         $username = JFilterOutput::stringURLSafe($data->name);
         if (strlen($username) < 2) {
             $username = str_pad($username, 2, mt_rand(0, 9));
         }
     }
     while ($db->loadResult()) {
         $username .= mt_rand(0, 9);
         $db->setQuery("SELECT `id` FROM #__users WHERE `username` LIKE '" . $db->getEscaped($username) . "' LIMIT 1");
     }
     // Bind the post array to the user object
     $post = array();
     $post['name'] = $data->name;
     if (trim($post['name']) == '') {
         $post['name'] = $email;
     }
     $post['email'] = $email;
     $post['username'] = $username;
     $post['password'] = JUserHelper::genRandomPassword(8);
     $original = $post['password'];
     $post['password2'] = $post['password'];
     if (!$user->bind($post, 'usertype')) {
         JError::raiseError(500, $user->getError());
     }
     // Set some initial user values
     $user->set('id', 0);
     if (RSMembershipHelper::isJ16()) {
         $usersConfig = JComponentHelper::getParams('com_users');
         $user->set('groups', array($usersConfig->get('new_usertype', 2)));
     } else {
         $authorize =& JFactory::getACL();
         // Initialize new usertype setting
         $usersConfig =& JComponentHelper::getParams('com_users');
         $newUsertype = $usersConfig->get('new_usertype');
         if (!$newUsertype) {
             $newUsertype = 'Registered';
         }
         $user->set('usertype', '');
         $user->set('gid', $authorize->get_group_id('', $newUsertype, 'ARO'));
     }
     $date =& JFactory::getDate();
     $user->set('registerDate', $date->toMySQL());
     // If user activation is turned on, we need to set the activation information
     $useractivation = $usersConfig->get('useractivation');
     if ($useractivation == '1') {
         $user->set('activation', JUtility::getHash($post['password']));
         $user->set('block', '1');
     }
     $user->set('lastvisitDate', '0000-00-00 00:00:00');
     // If there was an error with registration, set the message
     if (!$user->save()) {
         return false;
         JError::raiseWarning('', JText::_($user->getError()));
     }
     // Hack for community builder - approve the user so that he can login
     if (file_exists(JPATH_SITE . DS . 'components' . DS . 'com_comprofiler' . DS . 'comprofiler.php')) {
         $db->setQuery("INSERT INTO #__comprofiler SET approved = 1 , user_id = " . $user->get('id') . " , id = " . $user->get('id') . " , confirmed = 1");
         $db->query();
     }
     // Send registration confirmation mail
     $password = $original;
     // Disallow control chars in the email
     $password = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $password);
     if (RSMembershipHelper::getConfig('choose_password') && !empty($data->password)) {
         $db->setQuery("UPDATE #__users SET `password`='" . $db->getEscaped($data->password) . "' WHERE `id`='" . $user->get('id') . "'");
         $db->query();
         $password = JText::_('RSM_HIDDEN_PASSWORD_TEXT');
     }
     RSMembership::sendUserEmail($user, $password, $data->fields);
     RSMembership::createUserData($user->get('id'), $data->fields);
     return $user->get('id');
 }