diff options
author | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-10-09 14:01:08 +0000 |
---|---|---|
committer | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-10-09 14:01:08 +0000 |
commit | 94b9d7cac30e0da63ad7042a8bec41cb09320058 (patch) | |
tree | 08f98c2ceaf196bcf09813bade8d715dae31791e | |
parent | 2a9504c3b2f2c99cd52bfabb9d68cc9cf1da28c1 (diff) | |
download | elgg-94b9d7cac30e0da63ad7042a8bec41cb09320058.tar.gz elgg-94b9d7cac30e0da63ad7042a8bec41cb09320058.tar.bz2 |
pulled out special exception in registration action for first admin login
git-svn-id: http://code.elgg.org/elgg/trunk@7040 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | actions/register.php | 37 | ||||
-rw-r--r-- | install/ElggInstaller.php | 61 | ||||
-rw-r--r-- | install/languages/en.php | 3 |
3 files changed, 56 insertions, 45 deletions
diff --git a/actions/register.php b/actions/register.php index 9c4efa9f6..b9db150c1 100644 --- a/actions/register.php +++ b/actions/register.php @@ -43,39 +43,20 @@ if ($CONFIG->allow_registration) { 'invitecode' => $invitecode ); - // if this user is admin, that means it was the first - // registered user. Don't trigger this hook. - // @todo This can be removed in the new installer - if (!$new_user->isAdmin()) { - // @todo should registration be allowed no matter what the plugins return? - if (!trigger_plugin_hook('register', 'user', $params, TRUE)) { - $new_user->delete(); - // @todo this is a generic messages. We could have plugins - // throw a RegistrationException, but that is very odd - // for the plugin hooks system. - throw new RegistrationException(elgg_echo('registerbad')); - } + // @todo should registration be allowed no matter what the plugins return? + if (!trigger_plugin_hook('register', 'user', $params, TRUE)) { + $new_user->delete(); + // @todo this is a generic messages. We could have plugins + // throw a RegistrationException, but that is very odd + // for the plugin hooks system. + throw new RegistrationException(elgg_echo('registerbad')); } system_message(sprintf(elgg_echo("registerok"), $CONFIG->sitename)); // Forward on success, assume everything else is an error... - // If just registered admin user, login the user in and forward to the - // plugins simple settings page. - if (!datalist_get('first_admin_login') && $new_user->isAdmin()) { - login($new_user); - // remove the "you've registered!" system_message(); - $_SESSION['msg']['messages'] = array(); - - // remind users to enable / disable desired tools - elgg_add_admin_notice('first_installation_plugin_reminder', elgg_echo('firstadminlogininstructions')); - - datalist_set('first_admin_login', time()); - forward('pg/admin/plugins/simple'); - } else { - login($new_user); - forward(); - } + login($new_user); + forward(); } else { register_error(elgg_echo("registerbad")); } diff --git a/install/ElggInstaller.php b/install/ElggInstaller.php index dc639d44a..79c6bb212 100644 --- a/install/ElggInstaller.php +++ b/install/ElggInstaller.php @@ -9,6 +9,16 @@ * @link http://elgg.org/ */ +/* + * @todo - integrate this could in case we want to send new admin to plugins page + // remind users to enable / disable desired tools + elgg_add_admin_notice('first_installation_plugin_reminder', elgg_echo('firstadminlogininstructions')); + + datalist_set('first_admin_login', time()); + forward('pg/admin/plugins/simple'); + + */ + class ElggInstaller { protected $steps = array( @@ -26,7 +36,9 @@ class ElggInstaller { 'admin' => FALSE, ); - protected $isAction; + protected $isAction = FALSE; + + protected $autoLogin = FALSE; /** * Constructor bootstraps the Elgg engine @@ -359,10 +371,10 @@ class ElggInstaller { break; } - if (!$this->createAdminAccount($submissionVars)) { + if (!$this->createAdminAccount($submissionVars, $this->autoLogin)) { break; } - + system_message(elgg_echo('install:success:admin')); $this->continueToNextStep('admin'); @@ -574,16 +586,19 @@ class ElggInstaller { */ protected function finishBootstraping($step) { - // install has its own session handling - session_name('Elgg'); - session_start(); - unregister_elgg_event_handler('boot', 'system', 'session_init'); - - // once the database has been created, load rest of engine $dbIndex = array_search('database', $this->getSteps()); + $settingsIndex = array_search('settings', $this->getSteps()); $stepIndex = array_search($step, $this->getSteps()); + if ($stepIndex <= $settingsIndex) { + // install has its own session handling before the db created and set up + session_name('Elgg'); + session_start(); + unregister_elgg_event_handler('boot', 'system', 'session_init'); + } + if ($stepIndex > $dbIndex) { + // once the database has been created, load rest of engine global $CONFIG; $lib_dir = $CONFIG->path . 'engine/lib/'; @@ -1124,7 +1139,7 @@ class ElggInstaller { foreach ($formVars as $field => $info) { if ($info['required'] == TRUE && !$submissionVars[$field]) { $name = elgg_echo("install:settings:label:$field"); - register_error(sprintf(elgg_echo('install:error:requiredfield')), $name); + register_error(sprintf(elgg_echo('install:error:requiredfield'), $name)); return FALSE; } } @@ -1151,7 +1166,7 @@ class ElggInstaller { } // @todo check that url is a url - + // @note filter_var cannot be used because it doesn't work on international urls return TRUE; } @@ -1268,9 +1283,10 @@ class ElggInstaller { * Create a user account for the admin * * @param array $submissionVars + * @param bool $login Login in the admin user? * @return bool */ - protected function createAdminAccount($submissionVars) { + protected function createAdminAccount($submissionVars, $login = FALSE) { global $CONFIG; $guid = register_user( @@ -1285,17 +1301,28 @@ class ElggInstaller { return FALSE; } - // @todo - register plugin hook instead for can edit - // need a logged in user to set admin flag so we go directly to database - $result = update_data("UPDATE {$CONFIG->dbprefix}users_entity set admin='yes' where guid=$guid"); - if (!$result) { - register_error("Unable to give new user account admin privileges."); + $user = get_entity($guid); + if (!$user) { + register_error(elgg_echo('install:error:loadadmin')); return FALSE; } + elgg_set_ignore_access(TRUE); + if ($user->makeAdmin() == FALSE) { + register_error(elgg_echo('install:error:adminaccess')); + } + elgg_set_ignore_access(FALSE); + + // add validation data to satisfy the user validation plugins create_metadata($guid, 'validated', TRUE, '', 0, ACCESS_PUBLIC); create_metadata($guid, 'validated_method', 'admin_user', '', 0, ACCESS_PUBLIC); + if ($login) { + if (login($user) == FALSE) { + register_error(elgg_echo('install:error:adminlogin')); + } + } + return TRUE; } } diff --git a/install/languages/en.php b/install/languages/en.php index 4163ea5d2..577d5ddbc 100644 --- a/install/languages/en.php +++ b/install/languages/en.php @@ -128,6 +128,9 @@ If you are ready to proceed, click the Next button.", 'install:error:locationdatadirectory' => 'Your data directory %s must be outside of your install path for security.', 'install:error:emailaddress' => '%s is not a valid email address', 'install:error:createsite' => 'Unable to create the site.', + 'install:error:loadadmin' => 'Unable to load admin user.', + 'install:error:adminaccess' => 'Unable to give new user account admin privileges.', + 'install:error:adminlogin' => 'Unable to login the new admin user automatically.', ); add_translation("en", $english); |