示例#1
0
 public function testCreateSuperUserLegacy()
 {
     $ui = \UserInfo::addSuperUser('test', '*****@*****.**');
     $this->assertEquals(USER_SUPER_ID, $ui->getUserID());
     $this->assertEquals(USER_SUPER, $ui->getUserName());
     $this->assertEquals('*****@*****.**', $ui->getUserEmail());
 }
 public function add_users()
 {
     // insert the default groups
     // create the groups our site users
     // have to add these in the right order so their IDs get set
     // starting at 1 w/autoincrement
     $g1 = Group::add(t("Guest"), t("The guest group represents unregistered visitors to your site."));
     $g2 = Group::add(t("Registered Users"), t("The registered users group represents all user accounts."));
     $g3 = Group::add(t("Administrators"), "");
     // insert admin user into the user table
     if (defined('INSTALL_USER_PASSWORD')) {
         $uPassword = INSTALL_USER_PASSWORD;
         $uPasswordEncrypted = User::encryptPassword($uPassword, PASSWORD_SALT);
     } else {
         $uPasswordEncrypted = INSTALL_USER_PASSWORD_HASH;
     }
     $uEmail = INSTALL_USER_EMAIL;
     UserInfo::addSuperUser($uPasswordEncrypted, $uEmail);
     $u = User::getByUserID(USER_SUPER_ID, true, false);
     Loader::library('mail/importer');
     MailImporter::add(array('miHandle' => 'private_message'));
 }
示例#3
0
 public function configure()
 {
     try {
         $val = Loader::helper('validation/form');
         $val->setData($this->post());
         $val->addRequired("SITE", t("Please specify your site's name"));
         $val->addRequiredEmail("uEmail", t('Please specify a valid email address'));
         $val->addRequired("DB_DATABASE", t('You must specify a valid database name'));
         $val->addRequired("DB_SERVER", t('You must specify a valid database server'));
         $e = Loader::helper('/validation/error');
         if (is_object($this->fileWriteErrors)) {
             $e = $this->fileWriteErrors;
         }
         if (!function_exists('mysql_connect')) {
             $e->add($this->getDBErrorMsg());
         } else {
             // attempt to connect to the database
             $db = Loader::db($_POST['DB_SERVER'], $_POST['DB_USERNAME'], $_POST['DB_PASSWORD'], $_POST['DB_DATABASE'], true);
             if ($_POST['DB_SERVER'] && $_POST['DB_DATABASE']) {
                 if (!$db) {
                     $e->add(t('Unable to connect to database.'));
                 } else {
                     $num = $db->GetCol("show tables");
                     if (count($num) > 0) {
                         $e->add(t('There are already %s tables in this database. Concrete must be installed in an empty database.', count($num)));
                     }
                 }
             }
         }
         if ($val->test() && !$e->has()) {
             if (!is_dir($this->installData['DIR_FILES_UPLOADED_THUMBNAILS'])) {
                 mkdir($this->installData['DIR_FILES_UPLOADED_THUMBNAILS']);
             }
             if (!is_dir($this->installData['DIR_FILES_INCOMING'])) {
                 mkdir($this->installData['DIR_FILES_INCOMING']);
             }
             if (!is_dir($this->installData['DIR_FILES_TRASH'])) {
                 mkdir($this->installData['DIR_FILES_TRASH']);
             }
             if (!is_dir($this->installData['DIR_FILES_CACHE'])) {
                 mkdir($this->installData['DIR_FILES_CACHE']);
             }
             if (!is_dir($this->installData['DIR_FILES_CACHE_DB'])) {
                 mkdir($this->installData['DIR_FILES_CACHE_DB']);
             }
             if (!is_dir($this->installData['DIR_FILES_AVATARS'])) {
                 mkdir($this->installData['DIR_FILES_AVATARS']);
             }
             if (isset($_POST['uPasswordForce'])) {
                 $this->installData['uPassword'] = $_POST['uPasswordForce'];
             }
             if (isset($_POST['packages'])) {
                 $this->installData['packages'] = $_POST['packages'];
             }
             $this->installDB();
             $vh = Loader::helper('validation/identifier');
             // copy the files
             $fh = Loader::helper('file');
             if ($_POST['INSTALL_SAMPLE_CONTENT']) {
                 $fh->copyAll($this->installData['DIR_BASE_CORE'] . '/config/install/files', DIR_FILES_UPLOADED);
             }
             // insert admin user into the user table
             $salt = defined('MANUAL_PASSWORD_SALT') ? MANUAL_PASSWORD_SALT : $vh->getString(64);
             if (!isset($this->installData['uPassword'])) {
                 $uPassword = rand(100000, 999999);
             } else {
                 $uPassword = $this->installData['uPassword'];
             }
             $uEmail = $_POST['uEmail'];
             $uPasswordEncrypted = User::encryptPassword($uPassword, $salt);
             UserInfo::addSuperUser($uPasswordEncrypted, $uEmail);
             if (defined('PERMISSIONS_MODEL') && PERMISSIONS_MODEL != 'simple') {
                 $setPermissionsModel = PERMISSIONS_MODEL;
             }
             if (file_exists($this->installData['DIR_CONFIG_SITE'])) {
                 $this->fp = @fopen($this->installData['DIR_CONFIG_SITE'] . '/site.php', 'w+');
                 if ($this->fp) {
                     Cache::flush();
                     if (is_array($this->installData['packages'])) {
                         foreach ($this->installData['packages'] as $pkgHandle) {
                             $p = Loader::package($pkgHandle);
                             $p->install();
                         }
                     }
                     // write the config file
                     $configuration = "<?php\n";
                     $configuration .= "define('DB_SERVER', '" . addslashes($_POST['DB_SERVER']) . "');\n";
                     $configuration .= "define('DB_USERNAME', '" . addslashes($_POST['DB_USERNAME']) . "');\n";
                     $configuration .= "define('DB_PASSWORD', '" . addslashes($_POST['DB_PASSWORD']) . "');\n";
                     $configuration .= "define('DB_DATABASE', '" . addslashes($_POST['DB_DATABASE']) . "');\n";
                     $configuration .= "define('BASE_URL', '" . $this->installData['BASE_URL'] . "');\n";
                     $configuration .= "define('DIR_REL', '" . $this->installData['DIR_REL'] . "');\n";
                     if (isset($setPermissionsModel)) {
                         $configuration .= "define('PERMISSIONS_MODEL', '" . addslashes($setPermissionsModel) . "');\n";
                     }
                     $configuration .= "define('PASSWORD_SALT', '{$salt}');\n";
                     if (is_array($_POST['SITE_CONFIG'])) {
                         foreach ($_POST['SITE_CONFIG'] as $key => $value) {
                             $configuration .= "define('" . $key . "', '" . $value . "');\n";
                         }
                     }
                     $res = fwrite($this->fp, $configuration);
                     fclose($this->fp);
                     chmod($this->installData['DIR_CONFIG_SITE'] . '/site.php', 0777);
                     // save some options into the database
                     Config::save('SITE', $_POST['SITE']);
                     // add the current app version as our site's app version
                     Config::save('SITE_APP_VERSION', $this->installData['APP_VERSION']);
                     Config::save('SITE_DEBUG_LEVEL', $this->installData['DEBUG_DISPLAY_ERRORS']);
                     Config::save('ENABLE_LOG_EMAILS', 1);
                     Config::save('ENABLE_LOG_ERRORS', 1);
                     Config::save('FULL_PAGE_CACHE_GLOBAL', 0);
                     // login
                     define('PASSWORD_SALT', $salt);
                     $u = new User($this->installData['USER_SUPER'], $uPassword);
                     $this->set('message', t('Congratulations. concrete5 has been installed. You have been logged in as <b>%s</b> with the password <b>%s</b>.<br/><br/>If you wish to change this password, you may do so from the users area of the dashboard.', $this->installData['USER_SUPER'], $uPassword));
                 } else {
                     throw new Exception(t('Unable to open config/site.php for writing.'));
                 }
             } else {
                 throw new Exception(t('Unable to locate config directory.'));
             }
         } else {
             if ($e->has()) {
                 $this->set('error', $e);
             } else {
                 $this->set('error', $val->getError());
             }
         }
     } catch (Exception $e) {
         // remove site.php so that we can try again ?
         if (is_resource($this->fp)) {
             fclose($this->fp);
         }
         if (file_exists($this->installData['DIR_CONFIG_SITE'] . '/site.php')) {
             unlink($this->installData['DIR_CONFIG_SITE'] . '/site.php');
         }
         $this->set('error', $e);
     }
 }
 public function add_users()
 {
     // insert the default groups
     // create the groups our site users
     // specify the ID's since auto increment may not always be +1
     $g1 = Group::add(tc("GroupName", "Guest"), tc("GroupDescription", "The guest group represents unregistered visitors to your site."), GUEST_GROUP_ID);
     $g2 = Group::add(tc("GroupName", "Registered Users"), tc("GroupDescription", "The registered users group represents all user accounts."), REGISTERED_GROUP_ID);
     $g3 = Group::add(tc("GroupName", "Administrators"), "", ADMIN_GROUP_ID);
     // insert admin user into the user table
     if (defined('INSTALL_USER_PASSWORD')) {
         Loader::library('3rdparty/phpass/PasswordHash');
         $hasher = new PasswordHash(PASSWORD_HASH_COST_LOG2, PASSWORD_HASH_PORTABLE);
         $uPassword = INSTALL_USER_PASSWORD;
         $uPasswordEncrypted = $hasher->HashPassword($uPassword);
     } else {
         $uPasswordEncrypted = INSTALL_USER_PASSWORD_HASH;
     }
     $uEmail = INSTALL_USER_EMAIL;
     UserInfo::addSuperUser($uPasswordEncrypted, $uEmail);
     $u = User::getByUserID(USER_SUPER_ID, true, false);
     Loader::library('mail/importer');
     MailImporter::add(array('miHandle' => 'private_message'));
 }