From 7f9441c33da07b215efcb51668434b3957559fd3 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 20 Oct 2009 16:32:22 -0700 Subject: Changes to Identity interface to allow for multiple Identity providers. What I've tested to this point, is you can install a new provider, switch to it, login as administrator, uninstall the default user module, reinstall the user module, switch back to the user module and login. --- modules/user/helpers/user_installer.php | 74 +-------------------------------- 1 file changed, 2 insertions(+), 72 deletions(-) (limited to 'modules/user/helpers/user_installer.php') diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php index 8ef4f13d..d7ad1e89 100644 --- a/modules/user/helpers/user_installer.php +++ b/modules/user/helpers/user_installer.php @@ -19,87 +19,17 @@ */ class user_installer { static function install() { - $db = Database::instance(); - $db->query("CREATE TABLE IF NOT EXISTS {users} ( - `id` int(9) NOT NULL auto_increment, - `name` varchar(32) NOT NULL, - `full_name` varchar(255) NOT NULL, - `password` varchar(64) NOT NULL, - `login_count` int(10) unsigned NOT NULL DEFAULT 0, - `last_login` int(10) unsigned NOT NULL DEFAULT 0, - `email` varchar(64) default NULL, - `admin` BOOLEAN default 0, - `guest` BOOLEAN default 0, - `hash` char(32) default NULL, - `url` varchar(255) default NULL, - `locale` char(10) default NULL, - PRIMARY KEY (`id`), - UNIQUE KEY(`hash`), - UNIQUE KEY(`name`)) - DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE IF NOT EXISTS {groups} ( - `id` int(9) NOT NULL auto_increment, - `name` char(64) default NULL, - `special` BOOLEAN default 0, - PRIMARY KEY (`id`), - UNIQUE KEY(`name`)) - DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE IF NOT EXISTS {groups_users} ( - `group_id` int(9) NOT NULL, - `user_id` int(9) NOT NULL, - PRIMARY KEY (`group_id`, `user_id`), - UNIQUE KEY(`user_id`, `group_id`)) - DEFAULT CHARSET=utf8;"); - - $everybody = group::create("Everybody"); - $everybody->special = true; - $everybody->save(); - - $registered = group::create("Registered Users"); - $registered->special = true; - $registered->save(); - - $guest = user::create("guest", "Guest User", ""); - $guest->guest = true; - $guest->remove($registered); - $guest->save(); - - $admin = user::create("admin", "Gallery Administrator", "admin"); - $admin->admin = true; - $admin->save(); - - // Let the admin own everything - $db->update("items", array("owner_id" => $admin->id), array("owner_id" => "IS NULL")); + user::activate(); module::set_version("user", 1); - - $root = ORM::factory("item", 1); - access::allow($everybody, "view", $root); - access::allow($everybody, "view_full", $root); - - access::allow($registered, "view", $root); - access::allow($registered, "view_full", $root); } static function uninstall() { - // Delete all users and groups so that we give other modules an opportunity to clean up - foreach (ORM::factory("user")->find_all() as $user) { - $user->delete(); - } - - foreach (ORM::factory("group")->find_all() as $group) { - $group->delete(); - } + user::deactivate(); try { Session::instance()->destroy(); } catch (Exception $e) { // We don't care if there was a problem destroying the session. } - $db = Database::instance(); - $db->query("DROP TABLE IF EXISTS {users};"); - $db->query("DROP TABLE IF EXISTS {groups};"); - $db->query("DROP TABLE IF EXISTS {groups_users};"); } } \ No newline at end of file -- cgit v1.2.3 From 21383dddc372c26e1de30c0d17d1e308428ce033 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 21 Oct 2009 11:52:55 -0700 Subject: Make sure we set the active identity provider when the user module is installed. This is mostly for the unit_tests as when the gallery3 installer is used, the user module is activated by default. --- modules/user/helpers/user_installer.php | 1 + 1 file changed, 1 insertion(+) (limited to 'modules/user/helpers/user_installer.php') diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php index d7ad1e89..1410f1ef 100644 --- a/modules/user/helpers/user_installer.php +++ b/modules/user/helpers/user_installer.php @@ -20,6 +20,7 @@ class user_installer { static function install() { user::activate(); + module::set_var("gallery", "identity_provider", "user"); module::set_version("user", 1); } -- cgit v1.2.3 From b74b131e25ca0ddb42d2545a5d0ea2d796452f1d Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 22 Oct 2009 22:29:56 -0700 Subject: Change Identity adminstration to use the uninstall/install methods when changing providers. --- modules/gallery/controllers/admin_identity.php | 19 +++-- modules/gallery/helpers/identity.php | 34 ++++----- modules/gallery/helpers/module.php | 4 +- modules/gallery/libraries/IdentityProvider.php | 26 ++----- .../gallery/libraries/drivers/IdentityProvider.php | 10 --- modules/gallery/views/admin_identity.html.php | 4 +- .../gallery/views/admin_identity_confirm.html.php | 2 +- modules/user/helpers/user.php | 85 ---------------------- modules/user/helpers/user_installer.php | 76 +++++++++++++++++-- .../libraries/drivers/IdentityProvider/Gallery.php | 16 +--- 10 files changed, 110 insertions(+), 166 deletions(-) (limited to 'modules/user/helpers/user_installer.php') diff --git a/modules/gallery/controllers/admin_identity.php b/modules/gallery/controllers/admin_identity.php index d06132ff..0521a0f8 100644 --- a/modules/gallery/controllers/admin_identity.php +++ b/modules/gallery/controllers/admin_identity.php @@ -47,23 +47,26 @@ class Admin_Identity_Controller extends Admin_Controller { module::event("pre_identity_change", $active_provider, $new_provider); - identity::deactivate(); + module::deactivate($active_provider); + module::uninstall($active_provider); + + try { + Session::instance()->destroy(); + } catch (Exception $e) { + // We don't care if there was a problem destroying the session. + } // Switch authentication - module::set_var("gallery", "identity_provider", $new_provider); identity::reset(); + module::set_var("gallery", "identity_provider", $new_provider); - identity::activate(); + module::install($new_provider); + module::activate($new_provider); // @todo this type of collation is questionable from an i18n perspective message::success(t("Changed to %description", array("description" => $providers->$new_provider))); - try { - Session::instance()->destroy(); - } catch (Exception $e) { - // We don't care if there was a problem destroying the session. - } url::redirect(item::root()->abs_url()); } diff --git a/modules/gallery/helpers/identity.php b/modules/gallery/helpers/identity.php index cf84c8a9..d0cba8e7 100644 --- a/modules/gallery/helpers/identity.php +++ b/modules/gallery/helpers/identity.php @@ -39,6 +39,16 @@ class identity_Core { return self::$available; } + /** + * Frees the current instance of the identity provider so the next call to instance will reload + * + * @param string configuration + * @return Identity_Core + */ + static function reset() { + IdentityProvider::reset(); + } + /** * Make sure that we have a session and group_ids cached in the session. */ @@ -71,12 +81,12 @@ class identity_Core { $session->set("group_ids", $ids); } //} catch (Exception $e) { - //try { - //Session::instance()->destroy(); - //} catch (Exception $e) { + // try { + // Session::instance()->destroy(); + // } catch (Exception $e) { // We don't care if there was a problem destroying the session. - //} - //url::redirect(item::root()->abs_url()); + // } + // url::redirect(item::root()->abs_url()); //} } @@ -125,20 +135,6 @@ class identity_Core { return IdentityProvider::instance()->is_writable(); } - /** - * @see IdentityProvider_Driver::activate. - */ - static function activate() { - IdentityProvider::instance()->activate(); - } - - /** - * @see IdentityProvider_Driver::deactivate. - */ - static function deactivate() { - IdentityProvider::instance()->deactivate(); - } - /** * @see IdentityProvider_Driver::guest. */ diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 1d77e63d..9d41cd51 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -130,6 +130,8 @@ class module_Core { array_unshift($kohana_modules, MODPATH . $module_name); Kohana::config_set("core.modules", $kohana_modules); + // Rebuild the include path so the module installer can benefit from auto loading + Kohana::include_paths(true); $installer_class = "{$module_name}_installer"; if (method_exists($installer_class, "install")) { call_user_func_array(array($installer_class, "install"), array()); @@ -154,7 +156,7 @@ class module_Core { */ static function upgrade($module_name) { $kohana_modules = Kohana::config("core.modules"); - array_unshift($kohana_modules, MODPATH . $module_name); + $kohana_modules = array_unshift($kohana_modules, MODPATH . $module_name); Kohana::config_set("core.modules", $kohana_modules); $version_before = module::get_version($module_name); diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php index 512f28eb..38718d4b 100644 --- a/modules/gallery/libraries/IdentityProvider.php +++ b/modules/gallery/libraries/IdentityProvider.php @@ -38,7 +38,7 @@ class IdentityProvider_Core { * @return Identity_Core */ static function & instance() { - if (!isset(self::$instance)) { + if (empty(self::$instance)) { // Create a new instance self::$instance = new IdentityProvider(); } @@ -47,14 +47,14 @@ class IdentityProvider_Core { } /** - * Returns a singleton instance of Identity. - * There can only be one Identity driver configured at a given point + * Frees the current instance of the identity provider so the next call to instance will reload * * @param string configuration * @return Identity_Core */ static function reset() { - self::$instance = new IdentityProvider(); + self::$instance = null; + Kohana::config_clear("identity"); } /** @@ -66,12 +66,12 @@ class IdentityProvider_Core { $config = module::get_var("gallery", "identity_provider", "user"); // Test the config group name - if (($this->config = Kohana::config("identity.".$config)) === NULL) { + if (($this->config = Kohana::config("identity." . $config)) === NULL) { throw new Exception("@todo NO USER LIBRARY CONFIGURATION FOR: $config"); } // Set driver name - $driver = "IdentityProvider_".ucfirst($this->config["driver"])."_Driver"; + $driver = "IdentityProvider_" . ucfirst($this->config["driver"]) ."_Driver"; // Load the driver if ( ! Kohana::auto_load($driver)) { @@ -100,20 +100,6 @@ class IdentityProvider_Core { return !empty($this->config["allow_updates"]); } - /** - * @see IdentityProvider_Driver::activate. - */ - public function activate() { - $this->driver->activate(); - } - - /** - * @see IdentityProvider_Driver::deactivate. - */ - public function deactivate() { - $this->driver->deactivate(); - } - /** * @see IdentityProvider_Driver::guest. */ diff --git a/modules/gallery/libraries/drivers/IdentityProvider.php b/modules/gallery/libraries/drivers/IdentityProvider.php index 8a578d1b..5bb41dcc 100644 --- a/modules/gallery/libraries/drivers/IdentityProvider.php +++ b/modules/gallery/libraries/drivers/IdentityProvider.php @@ -18,16 +18,6 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ interface IdentityProvider_Driver { - /** - * Initialize the provider so it is ready to use - */ - public function activate(); - - /** - * Cleanup up this provider so it is unavailable for use and won't conflict with the current driver - */ - public function deactivate(); - /** * Return the guest user. * diff --git a/modules/gallery/views/admin_identity.html.php b/modules/gallery/views/admin_identity.html.php index 1405cacb..358860cf 100644 --- a/modules/gallery/views/admin_identity.html.php +++ b/modules/gallery/views/admin_identity.html.php @@ -10,7 +10,7 @@ $("#g-dialog").html(data); $("#g-dialog").dialog({ bgiframe: true, - title: "", + title: for_js() ?>, resizable: false, height:165, modal: true, @@ -34,7 +34,7 @@
-

+

diff --git a/modules/gallery/views/admin_identity_confirm.html.php b/modules/gallery/views/admin_identity_confirm.html.php index e14525b5..54aae9c8 100644 --- a/modules/gallery/views/admin_identity_confirm.html.php +++ b/modules/gallery/views/admin_identity_confirm.html.php @@ -4,7 +4,7 @@

- +

diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php index 5f154313..5ef2b726 100644 --- a/modules/user/helpers/user.php +++ b/modules/user/helpers/user.php @@ -24,91 +24,6 @@ * Note: by design, this class does not do any permission checking. */ class user_Core { - /** - * Initialize the provider so it is ready to use - */ - static function activate() { - $db = Database::instance(); - $db->query("CREATE TABLE IF NOT EXISTS {users} ( - `id` int(9) NOT NULL auto_increment, - `name` varchar(32) NOT NULL, - `full_name` varchar(255) NOT NULL, - `password` varchar(64) NOT NULL, - `login_count` int(10) unsigned NOT NULL DEFAULT 0, - `last_login` int(10) unsigned NOT NULL DEFAULT 0, - `email` varchar(64) default NULL, - `admin` BOOLEAN default 0, - `guest` BOOLEAN default 0, - `hash` char(32) default NULL, - `url` varchar(255) default NULL, - `locale` char(10) default NULL, - PRIMARY KEY (`id`), - UNIQUE KEY(`hash`), - UNIQUE KEY(`name`)) - DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE IF NOT EXISTS {groups} ( - `id` int(9) NOT NULL auto_increment, - `name` char(64) default NULL, - `special` BOOLEAN default 0, - PRIMARY KEY (`id`), - UNIQUE KEY(`name`)) - DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE IF NOT EXISTS {groups_users} ( - `group_id` int(9) NOT NULL, - `user_id` int(9) NOT NULL, - PRIMARY KEY (`group_id`, `user_id`), - UNIQUE KEY(`user_id`, `group_id`)) - DEFAULT CHARSET=utf8;"); - - $everybody = group::create("Everybody"); - $everybody->special = true; - $everybody->save(); - - $registered = group::create("Registered Users"); - $registered->special = true; - $registered->save(); - - $guest = user::create("guest", "Guest User", ""); - $guest->guest = true; - $guest->remove($registered); - $guest->save(); - - $admin = user::create("admin", "Gallery Administrator", "admin"); - $admin->admin = true; - $admin->save(); - - // Let the admin own everything - $db->query("update {items} set owner_id = {$admin->id}"); - - $root = ORM::factory("item", 1); - access::allow($everybody, "view", $root); - access::allow($everybody, "view_full", $root); - - access::allow($registered, "view", $root); - access::allow($registered, "view_full", $root); - } - - /** - * Cleanup up this provider so it is unavailable for use and won't conflict with the current driver - */ - static function deactivate() { - // Delete all users and groups so that we give other modules an opportunity to clean up - foreach (ORM::factory("user")->find_all() as $user) { - $user->delete(); - } - - foreach (ORM::factory("group")->find_all() as $group) { - $group->delete(); - } - - $db = Database::instance(); - $db->query("DROP TABLE IF EXISTS {users};"); - $db->query("DROP TABLE IF EXISTS {groups};"); - $db->query("DROP TABLE IF EXISTS {groups_users};"); - } - /** * Return the guest user. * diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php index 1410f1ef..36c617a8 100644 --- a/modules/user/helpers/user_installer.php +++ b/modules/user/helpers/user_installer.php @@ -19,18 +19,84 @@ */ class user_installer { static function install() { + $db = Database::instance(); + $db->query("CREATE TABLE IF NOT EXISTS {users} ( + `id` int(9) NOT NULL auto_increment, + `name` varchar(32) NOT NULL, + `full_name` varchar(255) NOT NULL, + `password` varchar(64) NOT NULL, + `login_count` int(10) unsigned NOT NULL DEFAULT 0, + `last_login` int(10) unsigned NOT NULL DEFAULT 0, + `email` varchar(64) default NULL, + `admin` BOOLEAN default 0, + `guest` BOOLEAN default 0, + `hash` char(32) default NULL, + `url` varchar(255) default NULL, + `locale` char(10) default NULL, + PRIMARY KEY (`id`), + UNIQUE KEY(`hash`), + UNIQUE KEY(`name`)) + DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE IF NOT EXISTS {groups} ( + `id` int(9) NOT NULL auto_increment, + `name` char(64) default NULL, + `special` BOOLEAN default 0, + PRIMARY KEY (`id`), + UNIQUE KEY(`name`)) + DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE IF NOT EXISTS {groups_users} ( + `group_id` int(9) NOT NULL, + `user_id` int(9) NOT NULL, + PRIMARY KEY (`group_id`, `user_id`), + UNIQUE KEY(`user_id`, `group_id`)) + DEFAULT CHARSET=utf8;"); + + $everybody = group::create("Everybody"); + $everybody->special = true; + $everybody->save(); + + $registered = group::create("Registered Users"); + $registered->special = true; + $registered->save(); + + $guest = user::create("guest", "Guest User", ""); + $guest->guest = true; + $guest->remove($registered); + $guest->save(); + + $admin = user::create("admin", "Gallery Administrator", "admin"); + $admin->admin = true; + $admin->save(); + + // Let the admin own everything + $db->query("update {items} set owner_id = {$admin->id}"); + + $root = ORM::factory("item", 1); + access::allow($everybody, "view", $root); + access::allow($everybody, "view_full", $root); + + access::allow($registered, "view", $root); + access::allow($registered, "view_full", $root); user::activate(); module::set_var("gallery", "identity_provider", "user"); module::set_version("user", 1); } static function uninstall() { - user::deactivate(); + // Delete all users and groups so that we give other modules an opportunity to clean up + foreach (ORM::factory("user")->find_all() as $user) { + $user->delete(); + } - try { - Session::instance()->destroy(); - } catch (Exception $e) { - // We don't care if there was a problem destroying the session. + foreach (ORM::factory("group")->find_all() as $group) { + $group->delete(); } + + $db = Database::instance(); + $db->query("DROP TABLE IF EXISTS {users};"); + $db->query("DROP TABLE IF EXISTS {groups};"); + $db->query("DROP TABLE IF EXISTS {groups_users};"); } } \ No newline at end of file diff --git a/modules/user/libraries/drivers/IdentityProvider/Gallery.php b/modules/user/libraries/drivers/IdentityProvider/Gallery.php index 5941abb7..026f04e9 100644 --- a/modules/user/libraries/drivers/IdentityProvider/Gallery.php +++ b/modules/user/libraries/drivers/IdentityProvider/Gallery.php @@ -20,21 +20,7 @@ /* * Based on the Cache_Sqlite_Driver developed by the Kohana Team */ -class Identity_Gallery_Driver implements IdentityProvider_Driver { - /** - * @see IdentityProvider_Driver::activate. - */ - public function activate() { - user::activate(); - } - - /** - * @see IdentityProvider_Driver::deactivate. - */ - public function deactivate() { - user::deactivate(); - } - +class IdentityProvider_Gallery_Driver implements IdentityProvider_Driver { /** * @see IdentityProvider_Driver::guest. */ -- cgit v1.2.3 From 923a322ef57fec97fdf5cbb2a0fd5efd67668911 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 23 Oct 2009 06:09:24 -0700 Subject: Change the Admin_Identity_Controller to not destroy the session until after the new provider is installed. --- modules/gallery/controllers/admin_identity.php | 11 +++++------ modules/user/helpers/user_installer.php | 1 - 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'modules/user/helpers/user_installer.php') diff --git a/modules/gallery/controllers/admin_identity.php b/modules/gallery/controllers/admin_identity.php index 0521a0f8..dcc3edcb 100644 --- a/modules/gallery/controllers/admin_identity.php +++ b/modules/gallery/controllers/admin_identity.php @@ -50,12 +50,6 @@ class Admin_Identity_Controller extends Admin_Controller { module::deactivate($active_provider); module::uninstall($active_provider); - try { - Session::instance()->destroy(); - } catch (Exception $e) { - // We don't care if there was a problem destroying the session. - } - // Switch authentication identity::reset(); module::set_var("gallery", "identity_provider", $new_provider); @@ -67,6 +61,11 @@ class Admin_Identity_Controller extends Admin_Controller { message::success(t("Changed to %description", array("description" => $providers->$new_provider))); + try { + Session::instance()->destroy(); + } catch (Exception $e) { + // We don't care if there was a problem destroying the session. + } url::redirect(item::root()->abs_url()); } diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php index 36c617a8..520f580c 100644 --- a/modules/user/helpers/user_installer.php +++ b/modules/user/helpers/user_installer.php @@ -79,7 +79,6 @@ class user_installer { access::allow($registered, "view", $root); access::allow($registered, "view_full", $root); - user::activate(); module::set_var("gallery", "identity_provider", "user"); module::set_version("user", 1); } -- cgit v1.2.3 From 274d4680fad4aa8254b35b4906847d262b53cd33 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 26 Oct 2009 09:36:51 -0700 Subject: Upgrade the gallery module to version 16 to reflect the refactoring of the user module into an identity provider. Change how we determine if there are available groups that we need to export --- modules/gallery/helpers/access.php | 3 +-- modules/gallery/helpers/gallery_installer.php | 9 ++++++++- modules/gallery/module.info | 2 +- modules/user/helpers/user_installer.php | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) (limited to 'modules/user/helpers/user_installer.php') diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index a3abbe2e..c1c1f9d1 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -421,8 +421,7 @@ class access_Core { private static function _get_all_groups() { // When we build the gallery package, it's possible that there is no identity provider installed yet. // This is ok at packaging time, so work around it. - $config = module::get_var("gallery", "identity_provider"); - if (!empty($config)) { + if (module::is_active(module::get_var("gallery", "identity_provider", "user"))) { return identity::groups(); } else { return array(); diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 9c19eaed..01a213c8 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -253,6 +253,8 @@ class gallery_installer { $theme->save(); } + module::set_var("gallery", "identity_provider", "user"); + block_manager::add("dashboard_sidebar", "gallery", "block_adder"); block_manager::add("dashboard_sidebar", "gallery", "stats"); block_manager::add("dashboard_sidebar", "gallery", "platform_info"); @@ -268,7 +270,7 @@ class gallery_installer { module::set_var("gallery", "show_credits", 1); // @todo this string needs to be picked up by l10n_scanner module::set_var("gallery", "credits", "Powered by Gallery %version"); - module::set_version("gallery", 15); + module::set_version("gallery", 16); } static function upgrade($version) { @@ -393,6 +395,11 @@ class gallery_installer { } module::set_version("gallery", $version = 15); } + + if ($version == 15) { + module::set_var("gallery", "identity_provider", "user"); + module::set_version("gallery", $version = 16); + } } static function uninstall() { diff --git a/modules/gallery/module.info b/modules/gallery/module.info index f509ff08..e21431a7 100644 --- a/modules/gallery/module.info +++ b/modules/gallery/module.info @@ -1,3 +1,3 @@ name = "Gallery 3" description = "Gallery core application" -version = 15 +version = 16 diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php index 520f580c..cc8e71ea 100644 --- a/modules/user/helpers/user_installer.php +++ b/modules/user/helpers/user_installer.php @@ -79,7 +79,7 @@ class user_installer { access::allow($registered, "view", $root); access::allow($registered, "view_full", $root); - module::set_var("gallery", "identity_provider", "user"); + module::set_version("user", 1); } -- cgit v1.2.3 From 156a99beef968a22167502bb6389b4df7526feb0 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 27 Oct 2009 10:13:40 -0700 Subject: Set the minimum password length to 5. The gallery owner can change this in the advance settings. --- modules/user/controllers/admin_users.php | 5 ++++- modules/user/controllers/password.php | 5 +++-- modules/user/controllers/users.php | 5 +++++ modules/user/helpers/user_installer.php | 12 +++++++++++- modules/user/module.info | 2 +- 5 files changed, 24 insertions(+), 5 deletions(-) (limited to 'modules/user/helpers/user_installer.php') diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index 4d80521e..55a525ba 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -308,7 +308,6 @@ class Admin_Users_Controller extends Admin_Controller { $group->input("url")->label(t("URL"))->id("g-url")->value($user->url); $group->checkbox("admin")->label(t("Admin"))->id("g-admin")->checked($user->admin); $form->add_rules_from($user); - $form->edit_user->password->rules("-required"); module::event("user_edit_form_admin", $user, $form); $group->submit("")->value(t("Modify User")); @@ -330,6 +329,10 @@ class Admin_Users_Controller extends Admin_Controller { $group->checkbox("admin")->label(t("Admin"))->id("g-admin"); $form->add_rules_from(ORM::factory("user")); + $minimum_length = module::get_var("user", "mininum_password_length", 5); + $form->edit_user->password + ->rules($minimum_length ? "length[$minimum_length, 40]" : "length[40]"); + module::event("user_add_form_admin", $user, $form); $group->submit("")->value(t("Add User")); return $form; diff --git a/modules/user/controllers/password.php b/modules/user/controllers/password.php index b76a5e92..888fb37d 100644 --- a/modules/user/controllers/password.php +++ b/modules/user/controllers/password.php @@ -101,8 +101,9 @@ class Password_Controller extends Controller { if (!empty($hash)) { $hidden->value($hash); } - $group->password("password")->label(t("Password"))->id("g-password") - ->rules("required|length[1,40]"); + $minimum_length = module::get_var("user", "mininum_password_length", 5); + $input_password = $group->password("password")->label(t("Password"))->id("g-password") + ->rules($minimum_length ? "required|length[$minimum_length, 40]" : "length[40]"); $group->password("password2")->label(t("Confirm Password"))->id("g-password2") ->matches($group->password); $group->inputs["password2"]->error_messages( diff --git a/modules/user/controllers/users.php b/modules/user/controllers/users.php index 28164e9c..3507ec6d 100644 --- a/modules/user/controllers/users.php +++ b/modules/user/controllers/users.php @@ -78,6 +78,11 @@ class Users_Controller extends Controller { $group->input("url")->label(t("URL"))->id("g-url")->value($user->url); $form->add_rules_from($user); + $minimum_length = module::get_var("user", "mininum_password_length", 5); + $form->edit_user->password + ->rules($minimum_length ? "length[$minimum_length, 40]" : "length[40]"); + + module::event("user_edit_form", $user, $form); $group->submit("")->value(t("Save")); return $form; diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php index cc8e71ea..9aad4130 100644 --- a/modules/user/helpers/user_installer.php +++ b/modules/user/helpers/user_installer.php @@ -80,7 +80,17 @@ class user_installer { access::allow($registered, "view", $root); access::allow($registered, "view_full", $root); - module::set_version("user", 1); + module::set_var("user", "mininum_password_length", 5); + + module::set_version("user", 2); + } + + static function upgrade($version) { + if ($version == 1) { + module::set_var("user", "mininum_password_length", 5); + + module::set_version("user", $version = 2); + } } static function uninstall() { diff --git a/modules/user/module.info b/modules/user/module.info index 36a2179a..7178f108 100644 --- a/modules/user/module.info +++ b/modules/user/module.info @@ -1,6 +1,6 @@ name = "Users and Groups" description = "Gallery 3 user and group management" -version = 1 +version = 2 ; Don't show this module on the module administration screen no_module_admin = 1 -- cgit v1.2.3 From abe42002b2250d4ecf5627293e0338e11c4bfdb0 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 31 Oct 2009 14:13:35 -0700 Subject: Don't specify the default identity provider in the gallery installer. Let the user module use that as a trigger to set ownership of the root album to the administrator. --- modules/gallery/helpers/gallery_installer.php | 2 -- modules/user/helpers/user_installer.php | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'modules/user/helpers/user_installer.php') diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 5daf1016..2eb02546 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -253,8 +253,6 @@ class gallery_installer { $theme->save(); } - module::set_var("gallery", "identity_provider", "user"); - block_manager::add("dashboard_sidebar", "gallery", "block_adder"); block_manager::add("dashboard_sidebar", "gallery", "stats"); block_manager::add("dashboard_sidebar", "gallery", "platform_info"); diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php index 9aad4130..0cba502f 100644 --- a/modules/user/helpers/user_installer.php +++ b/modules/user/helpers/user_installer.php @@ -70,8 +70,18 @@ class user_installer { $admin->admin = true; $admin->save(); - // Let the admin own everything - $db->query("update {items} set owner_id = {$admin->id}"); + $current_provider = module::get_var("gallery", "identity_provider"); + if (empty($current_provider)) { + // If there is no provider defined then we are doing an initial install + // so we need to set the provider and make the administrator own everything + // If the installer is called and there is an identity provider, then we + // are switching identity providers and and the event handlers will do the + // right things + module::set_var("gallery", "identity_provider", "user"); + + // Let the admin own everything + $db->query("update {items} set owner_id = {$admin->id}"); + } $root = ORM::factory("item", 1); access::allow($everybody, "view", $root); -- cgit v1.2.3