Example #1
0
 /**
  * Creates a new user
  */
 public function createNewUser($username, $password, $email = "", $internalRegistration = false)
 {
     Tools::logm('Trying to create a new user...');
     if (!empty($username) && !empty($password)) {
         $newUsername = filter_var($username, FILTER_SANITIZE_STRING);
         $email = filter_var($email, FILTER_SANITIZE_STRING);
         if (!$this->store->userExists($newUsername)) {
             if ($this->store->install($newUsername, Tools::encodeString($password . $newUsername), $email)) {
                 if ($email != "") {
                     // if email is filled
                     if (SEND_CONFIRMATION_EMAIL && function_exists('mail')) {
                         // if internal registration from config screen
                         $body_internal = _('Hi,') . "\r\n\r\n" . sprintf(_('Someone just created a wallabag account for you on %1$s.'), Tools::getPocheUrl()) . "\r\n\r\n" . sprintf(_('Your login is %1$s.'), $newUsername) . "\r\n\r\n" . _('Note : The password has been chosen by the person who created your account. Get in touch with that person to know your password and change it as soon as possible') . "\r\n\r\n" . _('Have fun with it !') . "\r\n\r\n" . _('This is an automatically generated message, no one will answer if you respond to it.');
                         // if external (public) registration
                         $body = sprintf(_('Hi, %1$s'), $newUsername) . "\r\n\r\n" . sprintf(_('You\'ve just created a wallabag account on %1$s.'), Tools::getPocheUrl()) . "\r\n\r\n" . _("Have fun with it !");
                         $body = $internalRegistration ? $body_internal : $body;
                         $body = wordwrap($body, 70, "\r\n");
                         // cut lines with more than 70 caracters (MIME standard)
                         if (mail($email, sprintf(_('Your new wallabag account on %1$s'), Tools::getPocheUrl()), $body, 'X-Mailer: PHP/' . phpversion() . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n" . "From: " . $newUsername . "@" . gethostname() . "\r\n")) {
                             Tools::logm('The user ' . $newUsername . ' has been emailed');
                             $this->messages->add('i', sprintf(_('The new user %1$s has been sent an email at %2$s. You may have to check spam folder.'), $newUsername, $email));
                             Tools::redirect('?');
                         } else {
                             Tools::logm('A problem has been encountered while sending an email');
                             $this->messages->add('e', _('A problem has been encountered while sending an email'));
                         }
                     } else {
                         Tools::logm('The user has been created, but the server did not authorize sending emails');
                         $this->messages->add('i', _('The server did not authorize sending a confirmation email, but the user was created.'));
                     }
                 } else {
                     Tools::logm('The user has been created, but no email was saved, so no confimation email was sent');
                     $this->messages->add('i', _('The user was created, but no email was sent because email was not filled in'));
                 }
                 Tools::logm('The new user ' . $newUsername . ' has been installed');
                 if (\Session::isLogged()) {
                     $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to <a href="?logout">logout ?</a>'), $newUsername));
                 }
                 Tools::redirect();
             } else {
                 Tools::logm('error during adding new user');
                 Tools::redirect();
             }
         } else {
             $this->messages->add('e', sprintf(_('Error : An user with the name %s already exists !'), $newUsername));
             Tools::logm('An user with the name ' . $newUsername . ' already exists !');
             Tools::redirect();
         }
     } else {
         Tools::logm('Password or username were empty');
     }
 }
 /**
  * Renders the initial page that comes up when you first install UserFrosting.
  *
  * This page performs the following steps:
  * 1. Check that the current version of PHP is adequate.
  * 2. Check that PDO is installed and enabled.
  * 3. Check that we can connect to the database, as configured in `config-userfrosting.php`.
  * 4. Check that the database tables have not already been created.
  * 5. If all of these checks are passed, set up the initial tables by calling `Database::install()`.
  * This page is "public access".
  * Request type: GET
  * @see MySqlDatabase::install()
  */
 public function pageSetupDB()
 {
     $messages = [];
     // 1. Check PHP version
     error_log("Checking php version");
     // PHP_VERSION_ID is available as of PHP 5.2.7, if our version is lower than that, then emulate it
     if (!defined('PHP_VERSION_ID')) {
         $version = explode('.', PHP_VERSION);
         define('PHP_VERSION_ID', $version[0] * 10000 + $version[1] * 100 + $version[2]);
     }
     if (PHP_VERSION_ID < 50400) {
         $messages[] = ["title" => "You need to upgrade your PHP installation.", "message" => "I'm sorry, UserFrosting relies on numerous features of PHP that are only available in PHP 5.4 or later.  Please upgrade your version of PHP, or contact your web hosting service and ask them to upgrade it for you."];
     }
     // 2. Check that PDO is installed and enabled
     if (!class_exists('PDO')) {
         $messages[] = ["title" => "PDO is not installed.", "message" => "I'm sorry, you must have PDO installed and enabled in order for UserFrosting to access the database.  If you don't know what PDO is, please see <a href='http://php.net/manual/en/book.pdo.php'>http://php.net/manual/en/book.pdo.php</a>.  You must also have MySQL version 4.1 or higher installed, since UserFrosting relies on native prepared statements."];
     }
     error_log("Checking db connection");
     // 3. Check database connection
     if (!Database::testConnection()) {
         $messages[] = ["title" => "We couldn't connect to your database.", "message" => "Make sure that your database is properly configured in <code>config-userfrosting.php</code>, and that you have selected the correct configuration mode ('dev' or 'production').  Also, make sure that your database user has the proper privileges to connect to the database."];
     }
     error_log("Checking any current tables");
     $tables = Database::getCreatedTables();
     if (count($tables) > 0) {
         $messages[] = ["title" => "One or more tables already exist.", "message" => "The following tables already exist in the database: <strong>" . implode(", ", $tables) . "</strong>.  Do you already have another installation of UserFrosting in this database?  Please either create a new database (recommended), or change the table prefix in <code>config-userfrosting.php</code> if you cannot create a new database."];
     }
     error_log("Done with checks");
     if (count($messages) > 0) {
         $this->_app->render('install/install-errors.twig', ["messages" => $messages]);
     } else {
         error_log("Installing");
         // Create tables
         Database::install();
         $messages[] = ["title" => "<i class='fa fa-lock'></i> PDO is installed.", "message" => "No need to worry about any pesky SQL injection attacks!", "class" => "success"];
         $messages[] = ["title" => "<i class='fa fa-database'></i> Database connection", "message" => "Hooray!  We were able to connect to your database and create the core tables for UserFrosting.", "class" => "success"];
         if (PHP_VERSION_ID >= 50400 && PHP_VERSION_ID < 50500) {
             $messages[] = ["title" => "<i class='fa fa-warning'></i> PHP version", "message" => "You currently have version " . PHP_VERSION . " of PHP installed.  We recommend version 5.5 or later.  UserFrosting can still be installed, but we highly recommend you upgrade soon.", "class" => "warning"];
         } else {
             $messages[] = ["title" => "<i class='fa fa-check'></i> PHP version", "message" => "You currently have version " . PHP_VERSION . " of PHP installed.  Good job!", "class" => "success"];
         }
         // Check for GD library (required for Captcha)
         if (!(extension_loaded('gd') && function_exists('gd_info'))) {
             $messages[] = ["title" => "<i class='fa fa-warning'></i> GD library not installed", "message" => "We could not confirm that the <code>GD</code> library is installed and enabled.  GD is an image processing library that UserFrosting uses to generate captcha codes for user account registration.  If you don't need captcha, you can disable it in Site Settings and ignore this message.  Otherwise, please see the <a href='http://www.userfrosting.com/troubleshooting/' target='_blank'>troubleshooting guide</a> for information on installing and configuring GD.", "class" => "warning"];
         } else {
             if (!function_exists('imagepng')) {
                 $messages[] = ["title" => "<i class='fa fa-warning'></i> PNG operations not available", "message" => "The <code>GD</code> library is installed and enabled, but PNG functions do not seem to be available.  UserFrosting uses the PNG functions of GD, an image processing library, to generate captcha codes for user account registration.  If you don't need captcha, you can disable it in Site Settings and ignore this message.  Otherwise, please see the <a href='http://www.userfrosting.com/troubleshooting/' target='_blank'>troubleshooting guide</a> for information on updating GD to support PNG operations.", "class" => "warning"];
             }
         }
         $this->_app->render('install/install-ready.twig', ["messages" => $messages]);
     }
 }
Example #3
0
 public function pageSetupDB()
 {
     $messages = [];
     // 1. Check PHP version
     // PHP_VERSION_ID is available as of PHP 5.2.7, if our version is lower than that, then emulate it
     if (!defined('PHP_VERSION_ID')) {
         $version = explode('.', PHP_VERSION);
         define('PHP_VERSION_ID', $version[0] * 10000 + $version[1] * 100 + $version[2]);
     }
     if (PHP_VERSION_ID < 50400) {
         $messages[] = ["title" => "You need to upgrade your PHP installation.", "message" => "I'm sorry, UserFrosting relies on numerous features of PHP that are only available in PHP 5.4 or later.  Please upgrade your version of PHP, or contact your web hosting service and ask them to upgrade it for you."];
     }
     // 2. Check that PDO is installed and enabled
     if (!class_exists('PDO')) {
         $messages[] = ["title" => "PDO is not installed.", "message" => "I'm sorry, you must have PDO installed and enabled in order for UserFrosting to access the database.  If you don't know what PDO is, please see <a href='http://php.net/manual/en/book.pdo.php'>http://php.net/manual/en/book.pdo.php</a>.  You must also have MySQL version 4.1 or higher installed, since UserFrosting relies on native prepared statements."];
     }
     // 3. Check database connection
     if (!Database::testConnection()) {
         $messages[] = ["title" => "We couldn't connect to your database.", "message" => "Make sure that your database is properly configured in <code>config-userfrosting.php</code>, and that you have selected the correct configuration mode ('dev' or 'production').  Also, make sure that your database user has the proper privileges to connect to the database."];
     }
     $tables = Database::getTables();
     if (count($tables) > 0) {
         $messages[] = ["title" => "One or more tables already exist.", "message" => "The following tables already exist in the database: <strong>" . implode(", ", $tables) . "</strong>.  Do you already have another installation of UserFrosting in this database?  Please either create a new database (recommended), or change the table prefix in <code>config-userfrosting.php</code> if you cannot create a new database."];
     }
     if (count($messages) > 0) {
         $this->_app->render('common/install/install-errors.html', ['page' => ['author' => $this->_app->site->author, 'title' => "Installation Error", 'description' => "Installation page for UserFrosting", 'alerts' => $this->_app->alerts->getAndClearMessages()], "messages" => $messages]);
     } else {
         // Create tables
         Database::install();
         $messages[] = ["title" => "<i class='fa fa-lock'></i> PDO is installed.", "message" => "No need to worry about any pesky SQL injection attacks!", "class" => "success"];
         $messages[] = ["title" => "<i class='fa fa-database'></i> Database connection", "message" => "Hooray!  We were able to connect to your database and create the core tables for UserFrosting.", "class" => "success"];
         if (PHP_VERSION_ID >= 50400 && PHP_VERSION_ID < 50500) {
             $messages[] = ["title" => "<i class='fa fa-warning'></i> PHP version", "message" => "You currently have version " . PHP_VERSION . " of PHP installed.  We recommend version 5.5 or later.  UserFrosting can still be installed, but we highly recommend you upgrade soon.", "class" => "warning"];
         } else {
             $messages[] = ["title" => "<i class='fa fa-check'></i> PHP version", "message" => "You currently have version " . PHP_VERSION . " of PHP installed.  Good job!", "class" => "success"];
         }
         $this->_app->render('common/install/install-ready.html', ['page' => ['author' => $this->_app->site->author, 'title' => "Installation", 'description' => "Installation page for UserFrosting", 'alerts' => $this->_app->alerts->getAndClearMessages()], "messages" => $messages]);
     }
 }
Example #4
0
     if ($config['databaseType'] == '') {
         $config['databaseType'] = 'mysql';
     }
     include_once dirname(__FILE__) . '/../../includes/database.php';
     $testDB = new Database();
     unset($_POST['submit']);
     if (!$testDB->connect($_POST['databaseHost'], $_POST['databaseUser'], $_POST['databasePassword'], $_POST['databaseName'])) {
         $errors[] = 'Could not connect to database.';
     } else {
         $db = $testDB;
     }
 }
 if (count($errors) == 0 and !$config['installed']) {
     $db = new Database();
     !$db->connect($_POST['databaseHost'], $_POST['databaseUser'], $_POST['databasePassword'], $_POST['databaseName']);
     if (!$db->install()) {
         $errors[] = 'Database error: ' . $db->getErrorMessage();
     }
 }
 if (count($errors) == 0) {
     $newConfig = array_merge($config, $_POST);
     unset($newConfig['navigation']);
     unset($newConfig['modules']);
     unset($newConfig['adminFirstName']);
     unset($newConfig['adminLastName']);
     unset($newConfig['adminEmail']);
     unset($newConfig['adminPassword']);
     unset($newConfig['adminPassword2']);
     if ($newConfig['databaseType'] == '') {
         $newConfig['databaseType'] = 'mysql';
     }