Exemplo n.º 1
0
 /**
  * Method to create the root user for the site.
  *
  * @param   object  $options  The session options.
  *
  * @return  boolean  True on success.
  *
  * @since   3.1
  */
 private function _createRootUser($options)
 {
     // Get the application
     /* @var InstallationApplicationWeb $app */
     $app = JFactory::getApplication();
     // Get a database object.
     try {
         $db = InstallationHelperDatabase::getDbo($options->db_type, $options->db_host, $options->db_user, $options->db_pass, $options->db_name, $options->db_prefix);
     } catch (RuntimeException $e) {
         $app->enqueueMessage(JText::sprintf('INSTL_ERROR_CONNECT_DB', $e->getMessage()), 'notice');
         return false;
     }
     $cryptpass = JUserHelper::hashPassword($options->admin_password);
     // Take the admin user id.
     $userId = InstallationModelDatabase::getUserId();
     // We don't need the randUserId in the session any longer, let's remove it.
     InstallationModelDatabase::resetRandUserId();
     // Create the admin user.
     date_default_timezone_set('UTC');
     $installdate = date('Y-m-d H:i:s');
     $nullDate = $db->getNullDate();
     // Sqlsrv change.
     $query = $db->getQuery(true)->select($db->quoteName('id'))->from($db->quoteName('#__users'))->where($db->quoteName('id') . ' = ' . $db->quote($userId));
     $db->setQuery($query);
     if ($db->loadResult()) {
         $query->clear()->update($db->quoteName('#__users'))->set($db->quoteName('name') . ' = ' . $db->quote('Super User'))->set($db->quoteName('username') . ' = ' . $db->quote(trim($options->admin_user)))->set($db->quoteName('email') . ' = ' . $db->quote($options->admin_email))->set($db->quoteName('password') . ' = ' . $db->quote($cryptpass))->set($db->quoteName('block') . ' = 0')->set($db->quoteName('sendEmail') . ' = 1')->set($db->quoteName('registerDate') . ' = ' . $db->quote($installdate))->set($db->quoteName('lastvisitDate') . ' = ' . $db->quote($nullDate))->set($db->quoteName('activation') . ' = ' . $db->quote('0'))->set($db->quoteName('params') . ' = ' . $db->quote(''))->where($db->quoteName('id') . ' = ' . $db->quote($userId));
     } else {
         $columns = array($db->quoteName('id'), $db->quoteName('name'), $db->quoteName('username'), $db->quoteName('email'), $db->quoteName('password'), $db->quoteName('block'), $db->quoteName('sendEmail'), $db->quoteName('registerDate'), $db->quoteName('lastvisitDate'), $db->quoteName('activation'), $db->quoteName('params'));
         $query->clear()->insert('#__users', true)->columns($columns)->values($db->quote($userId) . ', ' . $db->quote('Super User') . ', ' . $db->quote(trim($options->admin_user)) . ', ' . $db->quote($options->admin_email) . ', ' . $db->quote($cryptpass) . ', ' . $db->quote('0') . ', ' . $db->quote('1') . ', ' . $db->quote($installdate) . ', ' . $db->quote($nullDate) . ', ' . $db->quote('0') . ', ' . $db->quote(''));
     }
     $db->setQuery($query);
     try {
         $db->execute();
     } catch (RuntimeException $e) {
         $app->enqueueMessage($e->getMessage(), 'notice');
         return false;
     }
     // Map the super admin to the Super Admin Group
     $query->clear()->select($db->quoteName('user_id'))->from($db->quoteName('#__user_usergroup_map'))->where($db->quoteName('user_id') . ' = ' . $db->quote($userId));
     $db->setQuery($query);
     if ($db->loadResult()) {
         $query->clear()->update($db->quoteName('#__user_usergroup_map'))->set($db->quoteName('user_id') . ' = ' . $db->quote($userId))->set($db->quoteName('group_id') . ' = 8');
     } else {
         $query->clear()->insert($db->quoteName('#__user_usergroup_map'), false)->columns(array($db->quoteName('user_id'), $db->quoteName('group_id')))->values($db->quote($userId) . ', 8');
     }
     $db->setQuery($query);
     try {
         $db->execute();
     } catch (RuntimeException $e) {
         $app->enqueueMessage($e->getMessage(), 'notice');
         return false;
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * @return  boolean
  *
  * @since   3.0
  */
 function _createRootUser($options)
 {
     // Get a database object.
     try {
         $db = InstallationHelperDatabase::getDBO($options->db_type, $options->db_host, $options->db_user, $options->db_pass, $options->db_name, $options->db_prefix);
     } catch (RuntimeException $e) {
         $this->setError(JText::sprintf('INSTL_ERROR_CONNECT_DB', $e->getMessage()));
     }
     // Create random salt/password for the admin user
     $salt = JUserHelper::genRandomPassword(32);
     $crypt = JUserHelper::getCryptedPassword($options->admin_password, $salt);
     $cryptpass = $crypt . ':' . $salt;
     // Take the admin user id
     JLoader::register('InstallationModelDatabase', JPATH_INSTALLATION . '/models/database.php');
     $userId = InstallationModelDatabase::getUserId();
     // We don't need anymore the randUserId in the session, let's remove it
     InstallationModelDatabase::resetRandUserId();
     // Create the admin user
     date_default_timezone_set('UTC');
     $installdate = date('Y-m-d H:i:s');
     $nullDate = $db->getNullDate();
     // Sqlsrv change
     $query = $db->getQuery(true);
     $query->select('id');
     $query->from('#__users');
     $query->where('id = ' . $db->quote($userId));
     $db->setQuery($query);
     if ($db->loadResult()) {
         $query = $db->getQuery(true);
         $query->update('#__users');
         $query->set('name = ' . $db->quote('Super User'));
         $query->set('username = '******'email = ' . $db->quote($options->admin_email));
         $query->set('password = '******'usertype = ' . $db->quote('deprecated'));
         $query->set('block = 0');
         $query->set('sendEmail = 1');
         $query->set('registerDate = ' . $db->quote($installdate));
         $query->set('lastvisitDate = ' . $db->quote($nullDate));
         $query->set('activation = ' . $db->quote('0'));
         $query->set('params = ' . $db->quote(''));
         $query->where('id = ' . $db->quote($userId));
     } else {
         $query = $db->getQuery(true);
         $columns = array($db->quoteName('id'), $db->quoteName('name'), $db->quoteName('username'), $db->quoteName('email'), $db->quoteName('password'), $db->quoteName('usertype'), $db->quoteName('block'), $db->quoteName('sendEmail'), $db->quoteName('registerDate'), $db->quoteName('lastvisitDate'), $db->quoteName('activation'), $db->quoteName('params'));
         $query->insert('#__users', true);
         $query->columns($columns);
         $query->values($db->quote($userId) . ', ' . $db->quote('Super User') . ', ' . $db->quote($options->admin_user) . ', ' . $db->quote($options->admin_email) . ', ' . $db->quote($cryptpass) . ', ' . $db->quote('deprecated') . ', ' . $db->quote('0') . ', ' . $db->quote('1') . ', ' . $db->quote($installdate) . ', ' . $db->quote($nullDate) . ', ' . $db->quote('0') . ', ' . $db->quote(''));
     }
     $db->setQuery($query);
     try {
         $db->execute();
     } catch (RuntimeException $e) {
         $this->setError($e->getMessage());
         return false;
     }
     // Map the super admin to the Super Admin Group
     $query = $db->getQuery(true);
     $query->select('user_id');
     $query->from('#__user_usergroup_map');
     $query->where('user_id = ' . $db->quote($userId));
     $db->setQuery($query);
     if ($db->loadResult()) {
         $query = $db->getQuery(true);
         $query->update('#__user_usergroup_map');
         $query->set('user_id = ' . $db->quote($userId));
         $query->set('group_id = 8');
     } else {
         $query = $db->getQuery(true);
         $query->insert('#__user_usergroup_map', false);
         $query->columns(array($db->quoteName('user_id'), $db->quoteName('group_id')));
         $query->values($userId . ', ' . '8');
     }
     $db->setQuery($query);
     try {
         $db->execute();
     } catch (RuntimeException $e) {
         $this->setError($e->getMessage());
         return false;
     }
     return true;
 }