diff options
-rw-r--r-- | modules/gallery/config/identity.php (renamed from modules/user/helpers/user_event.php) | 27 | ||||
-rw-r--r-- | modules/gallery/controllers/admin_users.php (renamed from modules/user/controllers/admin_users.php) | 1 | ||||
-rw-r--r-- | modules/gallery/controllers/albums.php | 1 | ||||
-rw-r--r-- | modules/gallery/controllers/login.php (renamed from modules/user/controllers/login.php) | 1 | ||||
-rw-r--r-- | modules/gallery/controllers/logout.php (renamed from modules/user/controllers/logout.php) | 0 | ||||
-rw-r--r-- | modules/gallery/controllers/password.php (renamed from modules/user/controllers/password.php) | 0 | ||||
-rw-r--r-- | modules/gallery/controllers/users.php (renamed from modules/user/controllers/users.php) | 0 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_block.php | 10 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_event.php | 4 | ||||
-rw-r--r-- | modules/gallery/helpers/group.php (renamed from modules/user/helpers/group.php) | 125 | ||||
-rw-r--r-- | modules/gallery/helpers/locales.php | 17 | ||||
-rw-r--r-- | modules/gallery/helpers/user.php (renamed from modules/user/helpers/user.php) | 281 | ||||
-rw-r--r-- | modules/gallery/libraries/Identity.php | 223 | ||||
-rw-r--r-- | modules/gallery/libraries/drivers/Identity.php | 286 | ||||
-rw-r--r-- | modules/gallery/views/admin_users.html.php (renamed from modules/user/views/admin_users.html.php) | 36 | ||||
-rw-r--r-- | modules/gallery/views/admin_users_group.html.php (renamed from modules/user/views/admin_users_group.html.php) | 4 | ||||
-rw-r--r-- | modules/gallery/views/login.html.php (renamed from modules/user/views/login.html.php) | 2 | ||||
-rw-r--r-- | modules/gallery/views/login_ajax.html.php (renamed from modules/user/views/login_ajax.html.php) | 2 | ||||
-rw-r--r-- | modules/gallery/views/reset_password.html.php (renamed from modules/user/views/reset_password.html.php) | 0 | ||||
-rw-r--r-- | modules/gallery/views/user_languages_block.html.php (renamed from modules/user/views/user_languages_block.html.php) | 0 | ||||
-rw-r--r-- | modules/user/libraries/drivers/Identity/Gallery.php | 293 | ||||
-rw-r--r-- | modules/user/models/user.php | 21 | ||||
-rw-r--r-- | themes/admin_wind/css/screen.css | 3 |
23 files changed, 1073 insertions, 264 deletions
diff --git a/modules/user/helpers/user_event.php b/modules/gallery/config/identity.php index 93a92589..72d1b589 100644 --- a/modules/user/helpers/user_event.php +++ b/modules/gallery/config/identity.php @@ -17,12 +17,21 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class user_event_Core { - static function admin_menu($menu, $theme) { - $menu->add_after("appearance_menu", - Menu::factory("link") - ->id("users_groups") - ->label(t("Users/Groups")) - ->url(url::site("admin/users"))); - } -} +/* + * @package Identity + * + * User settings, defined as arrays, or "groups". If no group name is + * used when loading the cache library, the group named "default" will be used. + * + * Each group can be used independently, and multiple groups can be used at once. + * + * Group Options: + * driver - User backend driver. Gallery comes with Gallery user driver. + * + * params - Driver parameters, specific to each driver. + */ +$config["default"] = array ( + "driver" => "gallery", + "allow_updates" => false, + "params" => array(), +); diff --git a/modules/user/controllers/admin_users.php b/modules/gallery/controllers/admin_users.php index a8a8cd95..34b3a426 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/gallery/controllers/admin_users.php @@ -21,6 +21,7 @@ class Admin_Users_Controller extends Admin_Controller { public function index() { $view = new Admin_View("admin.html"); $view->content = new View("admin_users.html"); + $view->content->writable = user::is_writable(); $view->content->users = user::get_user_list(array("orderby" => array("name" => "ASC"))); $view->content->groups = group::get_group_list(array("orderby" => array("name" => "ASC"))); print $view; diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 9733d1cd..95d63308 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -29,6 +29,7 @@ class Albums_Controller extends Items_Controller { $view = new Theme_View("page.html", "login"); $view->page_title = t("Log in to Gallery"); $view->content = new View("login_ajax.html"); + $view->content->writable = user::is_writable(); $view->content->form = user::get_login_form("login/auth_html"); print $view; return; diff --git a/modules/user/controllers/login.php b/modules/gallery/controllers/login.php index 2c4bd557..85f6db5d 100644 --- a/modules/user/controllers/login.php +++ b/modules/gallery/controllers/login.php @@ -21,6 +21,7 @@ class Login_Controller extends Controller { public function ajax() { $view = new View("login_ajax.html"); + $view->writable = user::is_writable(); $view->form = user::get_login_form("login/auth_ajax"); print $view; } diff --git a/modules/user/controllers/logout.php b/modules/gallery/controllers/logout.php index 45d397ad..45d397ad 100644 --- a/modules/user/controllers/logout.php +++ b/modules/gallery/controllers/logout.php diff --git a/modules/user/controllers/password.php b/modules/gallery/controllers/password.php index e8b08960..e8b08960 100644 --- a/modules/user/controllers/password.php +++ b/modules/gallery/controllers/password.php diff --git a/modules/user/controllers/users.php b/modules/gallery/controllers/users.php index 07c5a457..07c5a457 100644 --- a/modules/user/controllers/users.php +++ b/modules/gallery/controllers/users.php diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php index d8812c80..a4f4dae0 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -93,17 +93,17 @@ class gallery_block_Core { case "language": $locales = locales::installed(); - foreach ($locales as $locale => $display_name) { - $locales[$locale] = SafeString::of_safe_html($display_name); - } - if (count($locales) > 1) { + if (count($locales)) { + foreach ($locales as $locale => $display_name) { + $locales[$locale] = SafeString::of_safe_html($display_name); + } $block = new Block(); $block->css_id = "g-user-language-block"; $block->title = t("Language Preference"); $block->content = new View("user_languages_block.html"); $block->content->installed_locales = array_merge(array("" => t("« none »")), $locales); - $block->content->selected = (string) locales::cookie_locale(); + $block->content->selected = (string) user::cookie_locale(); } else { $block = ""; } diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 106aa202..e0de2152 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -187,6 +187,10 @@ class gallery_event_Core { ->id("sidebar") ->label(t("Manage Sidebar")) ->url(url::site("admin/sidebar")))) + ->append(Menu::factory("link") + ->id("users_groups") + ->label(t("Users/Groups")) + ->url(url::site("admin/users"))) ->append(Menu::factory("submenu") ->id("statistics_menu") ->label(t("Statistics"))) diff --git a/modules/user/helpers/group.php b/modules/gallery/helpers/group.php index fbc5157d..17dd7f70 100644 --- a/modules/user/helpers/group.php +++ b/modules/gallery/helpers/group.php @@ -24,105 +24,100 @@ * Note: by design, this class does not do any permission checking. */ class group_Core { + static function get_edit_form_admin($group) { + $form = new Forge("admin/users/edit_group/$group->id", "", "post", array("id" => "g-edit-group-form")); + $form_group = $form->group("edit_group")->label(t("Edit Group")); + $form_group->input("name")->label(t("Name"))->id("g-name")->value($group->name); + $form_group->inputs["name"]->error_messages( + "in_use", t("There is already a group with that name")); + $form_group->submit("")->value(t("Save")); + $form->add_rules_from(self::get_edit_rules()); + return $form; + } + + static function get_add_form_admin() { + $form = new Forge("admin/users/add_group", "", "post", array("id" => "g-add-group-form")); + $form->set_attr('class', "g-narrow"); + $form_group = $form->group("add_group")->label(t("Add Group")); + $form_group->input("name")->label(t("Name"))->id("g-name"); + $form_group->inputs["name"]->error_messages( + "in_use", t("There is already a group with that name")); + $form_group->submit("")->value(t("Add Group")); + $group = ORM::factory("group"); + $form->add_rules_from(self::get_edit_rules()); + return $form; + } + + static function get_delete_form_admin($group) { + $form = new Forge("admin/users/delete_group/$group->id", "", "post", + array("id" => "g-delete-group-form")); + $form_group = $form->group("delete_group")->label( + t("Are you sure you want to delete group %group_name?", array("group_name" => $group->name))); + $form_group->submit("")->value(t("Delete")); + return $form; + } + /** * Create a new group. * * @param string $name - * @return Group_Model + * @return Group_Core */ static function create($name) { - $group = ORM::factory("group")->where("name", $name)->find(); - if ($group->loaded) { - throw new Exception("@todo GROUP_ALREADY_EXISTS $name"); - } - - $group->name = $name; - $group->save(); - - return $group; + return Identity::instance()->create_group($name); } /** * The group of all possible visitors. This includes the guest user. * - * @return Group_Model + * @return Group_Core */ static function everybody() { - return model_cache::get("group", 1); + return Identity::instance()->everybody(); } /** * The group of all logged-in visitors. This does not include guest users. * - * @return Group_Model + * @return Group_Core */ static function registered_users() { - return model_cache::get("group", 2); + return Identity::instance()->everybody(); + } + + /** + * Look up a group by id. + * @param integer $id the user id + * @return Group_Model the group object, or null if the id was invalid. + */ + static function lookup($id) { + return Identity::instance()->lookup_group_by_field("id", $id); } /** * Look up a group by name. * @param integer $id the group name - * @return Group_Model the group object, or null if the name was invalid. + * @return Group_Core the group object, or null if the name was invalid. */ static function lookup_by_name($name) { - $group = model_cache::get("group", $name, "name"); - if ($group->loaded) { - return $group; - } - return null; + return Identity::instance()->lookup_group_by_field("name", $name); } /** - * List the users - * @param mixed filters (@see Database.php + * List the groups + * @param mixed options to apply to the selection of the user (@see Database.php) * @return array the group list. */ static function get_group_list($filter=array()) { - $group = ORM::factory("group"); - - foreach($filter as $method => $args) { - switch ($method) { - case "in": - $group->in($args[0], $args[1]); - break; - default: - $group->$method($args); - } - } - return $group->find_all(); - } - - static function get_edit_form_admin($group) { - $form = new Forge("admin/users/edit_group/$group->id", "", "post", array("id" => "g-edit-group-form")); - $form_group = $form->group("edit_group")->label(t("Edit Group")); - $form_group->input("name")->label(t("Name"))->id("g-name")->value($group->name); - $form_group->inputs["name"]->error_messages( - "in_use", t("There is already a group with that name")); - $form_group->submit("")->value(t("Save")); - $form->add_rules_from($group); - return $form; + return Identity::instance()->get_group_list($filter); } - static function get_add_form_admin() { - $form = new Forge("admin/users/add_group", "", "post", array("id" => "g-add-group-form")); - $form->set_attr('class', "g-narrow"); - $form_group = $form->group("add_group")->label(t("Add Group")); - $form_group->input("name")->label(t("Name"))->id("g-name"); - $form_group->inputs["name"]->error_messages( - "in_use", t("There is already a group with that name")); - $form_group->submit("")->value(t("Add Group")); - $group = ORM::factory("group"); - $form->add_rules_from($group); - return $form; - } - - static function get_delete_form_admin($group) { - $form = new Forge("admin/users/delete_group/$group->id", "", "post", - array("id" => "g-delete-group-form")); - $form_group = $form->group("delete_group")->label( - t("Are you sure you want to delete group %group_name?", array("group_name" => $group->name))); - $form_group->submit("")->value(t("Delete")); - return $form; + /** + * Return the edit rules associated with an group. + * + * @return stdClass containing the rules + */ + static function get_edit_rules() { + return Identity::instance()->get_edit_rules("group"); } } diff --git a/modules/gallery/helpers/locales.php b/modules/gallery/helpers/locales.php index f0807c99..17286adf 100644 --- a/modules/gallery/helpers/locales.php +++ b/modules/gallery/helpers/locales.php @@ -136,6 +136,23 @@ class locales_Core { return in_array($language, array("he", "fa", "ar")); } + static function set_request_locale() { + // 1. Check the session specific preference (cookie) + $locale = user::cookie_locale(); + // 2. Check the user's preference + if (!$locale) { + $locale = user::active()->locale; + } + // 3. Check the browser's / OS' preference + if (!$locale) { + $locale = self::locale_from_http_request(); + } + // If we have any preference, override the site's default locale + if ($locale) { + I18n::instance()->locale($locale); + } + } + /** * Returns the best match comparing the HTTP accept-language header * with the installed locales. diff --git a/modules/user/helpers/user.php b/modules/gallery/helpers/user.php index 7aa990e1..f0509030 100644 --- a/modules/user/helpers/user.php +++ b/modules/gallery/helpers/user.php @@ -25,24 +25,34 @@ */ class user_Core { static function get_edit_form($user) { + $writable = self::is_writable(); $form = new Forge("users/update/$user->id", "", "post", array("id" => "g-edit-user-form")); $form->set_attr("class", "g-narrow"); $group = $form->group("edit_user")->label(t("Edit User: %name", array("name" => $user->name))); $group->input("full_name")->label(t("Full Name"))->id("g-fullname")->value($user->full_name); self::_add_locale_dropdown($group, $user); - $group->password("password")->label(t("Password"))->id("g-password"); - $group->password("password2")->label(t("Confirm Password"))->id("g-password2") - ->matches($group->password); + if ($writable) { + $group->password("password")->label(t("Password"))->id("g-password"); + $group->password("password2")->label(t("Confirm Password"))->id("g-password2") + ->matches($group->password); + } $group->input("email")->label(t("Email"))->id("g-email")->value($user->email); $group->input("url")->label(t("URL"))->id("g-url")->value($user->url); - $form->add_rules_from($user); + $form->add_rules_from(self::get_edit_rules()); module::event("user_edit_form", $user, $form); $group->submit("")->value(t("Save")); + + if (!$writable) { + foreach ($group->inputs as $input) { + $input->disabled("disabled"); + } + } return $form; } static function get_edit_form_admin($user) { + $writable = self::is_writable(); $form = new Forge( "admin/users/edit_user/$user->id", "", "post", array("id" => "g-edit-user-form")); $group = $form->group("edit_user")->label(t("Edit User")); @@ -51,17 +61,23 @@ class user_Core { "in_use", t("There is already a user with that username")); $group->input("full_name")->label(t("Full Name"))->id("g-fullname")->value($user->full_name); self::_add_locale_dropdown($group, $user); - $group->password("password")->label(t("Password"))->id("g-password"); - $group->password("password2")->label(t("Confirm Password"))->id("g-password2") - ->matches($group->password); + if ($writable) { + $group->password("password")->label(t("Password"))->id("g-password"); + $group->password("password2")->label(t("Confirm Password"))->id("g-password2") + ->matches($group->password); + } $group->input("email")->label(t("Email"))->id("g-email")->value($user->email); $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"); + $form->add_rules_from(self::get_edit_rules()); module::event("user_edit_form_admin", $user, $form); $group->submit("")->value(t("Modify User")); + if (!$writable) { + foreach ($group->inputs as $input) { + $input->disabled("disabled"); + } + } return $form; } @@ -79,8 +95,7 @@ class user_Core { $group->input("url")->label(t("URL"))->id("g-url"); self::_add_locale_dropdown($group); $group->checkbox("admin")->label(t("Admin"))->id("g-admin"); - $user = ORM::factory("user"); - $form->add_rules_from($user); + $form->add_rules_from(self::get_edit_rules()); module::event("user_add_form_admin", $user, $form); $group->submit("")->value(t("Add User")); @@ -124,19 +139,76 @@ class user_Core { } /** - * Make sure that we have a session and group_ids cached in the session. + * Return the active user. If there's no active user, return the guest user. + * + * @return User_Model + */ + static function active() { + // @todo (maybe) cache this object so we're not always doing session lookups. + $user = Session::instance()->get("user", null); + if (!isset($user)) { + // Don't do this as a fallback in the Session::get() call because it can trigger unnecessary + // work. + $user = self::guest(); + } + return $user; + } + + /** + * Change the active user. + * + * @return User_Model + */ + static function set_active($user) { + $session = Session::instance(); + $session->set("user", $user); + $session->delete("group_ids"); + self::load_user(); + } + + /** + * Return the array of group ids this user belongs to + * + * @return array + */ + static function group_ids() { + return Session::instance()->get("group_ids", array(1)); + } + + + static function cookie_locale() { + $cookie_data = Input::instance()->cookie("g_locale"); + $locale = null; + if ($cookie_data) { + if (preg_match("/^([a-z]{2,3}(?:_[A-Z]{2})?)$/", trim($cookie_data), $matches)) { + $requested_locale = $matches[1]; + $installed_locales = locales::installed(); + if (isset($installed_locales[$requested_locale])) { + $locale = $requested_locale; + } + } + } + return $locale; + } + + /** + * Make sure that we have a session and group_ids cached in the session. This is one + * of the first calls to reference the user so call the Identity::instance to load the + * driver classes. */ static function load_user() { + Identity::instance(); $session = Session::instance(); if (!($user = $session->get("user"))) { - $session->set("user", $user = user::guest()); + $session->set("user", $user = self::guest()); } // The installer cannot set a user into the session, so it just sets an id which we should // upconvert into a user. + // @todo what is user id===2 if ($user === 2) { $user = model_cache::get("user", 2); - user::login($user); + self::login($user); $session->set("user", $user); } @@ -150,51 +222,54 @@ class user_Core { } /** - * Return the array of group ids this user belongs to - * - * @return array + * Log in as a given user. + * @param object $user the user object. */ - static function group_ids() { - return Session::instance()->get("group_ids", array(1)); + static function login($user) { + // @todo make this an interface call + $user->login_count += 1; + $user->last_login = time(); + $user->save(); + + self::set_active($user); + module::event("user_login", $user); } /** - * Return the active user. If there's no active user, return the guest user. - * - * @return User_Model + * Log out the active user and destroy the session. + * @param object $user the user object. */ - static function active() { - // @todo (maybe) cache this object so we're not always doing session lookups. - $user = Session::instance()->get("user", null); - if (!isset($user)) { - // Don't do this as a fallback in the Session::get() call because it can trigger unnecessary - // work. - $user = user::guest(); + static function logout() { + $user = self::active(); + if (!$user->guest) { + try { + Session::instance()->destroy(); + } catch (Exception $e) { + Kohana::log("error", $e); + } + module::event("user_logout", $user); } - return $user; } /** - * Return the guest user. - * - * @todo consider caching + * Determine if a feature is supported by the driver. * - * @return User_Model + * @param string $feature the name of the feature to check + * @return boolean true if supported */ - static function guest() { - return model_cache::get("user", 1); + static function is_writable() { + return Identity::instance()->is_writable(); } /** - * Change the active user. + * Return the guest user. + * + * @todo consider caching * * @return User_Model */ - static function set_active($user) { - $session = Session::instance(); - $session->set("user", $user); - $session->delete("group_ids"); - self::load_user(); + static function guest() { + return Identity::instance()->guest(); } /** @@ -206,21 +281,7 @@ class user_Core { * @return User_Model */ static function create($name, $full_name, $password) { - $user = ORM::factory("user")->where("name", $name)->find(); - if ($user->loaded) { - throw new Exception("@todo USER_ALREADY_EXISTS $name"); - } - - $user->name = $name; - $user->full_name = $full_name; - $user->password = $password; - - // Required groups - $user->add(group::everybody()); - $user->add(group::registered_users()); - - $user->save(); - return $user; + return Identity::instance()->create_user($name, $full_name, $password); } /** @@ -231,31 +292,7 @@ class user_Core { * @return boolean true if the password is correct */ static function is_correct_password($user, $password) { - $valid = $user->password; - - // Try phpass first, since that's what we generate. - if (strlen($valid) == 34) { - require_once(MODPATH . "user/lib/PasswordHash.php"); - $hashGenerator = new PasswordHash(10, true); - return $hashGenerator->CheckPassword($password, $valid); - } - - $salt = substr($valid, 0, 4); - // Support both old (G1 thru 1.4.0; G2 thru alpha-4) and new password schemes: - $guess = (strlen($valid) == 32) ? md5($password) : ($salt . md5($salt . $password)); - if (!strcmp($guess, $valid)) { - return true; - } - - // Passwords with <&"> created by G2 prior to 2.1 were hashed with entities - $sanitizedPassword = html::specialchars($password, false); - $guess = (strlen($valid) == 32) ? md5($sanitizedPassword) - : ($salt . md5($salt . $sanitizedPassword)); - if (!strcmp($guess, $valid)) { - return true; - } - - return false; + return Identity::instance()->is_correct_password($user, $password); } /** @@ -264,38 +301,7 @@ class user_Core { * @return string hashed password */ static function hash_password($password) { - require_once(MODPATH . "user/lib/PasswordHash.php"); - $hashGenerator = new PasswordHash(10, true); - return $hashGenerator->HashPassword($password); - } - - /** - * Log in as a given user. - * @param object $user the user object. - */ - static function login($user) { - $user->login_count += 1; - $user->last_login = time(); - $user->save(); - - user::set_active($user); - module::event("user_login", $user); - } - - /** - * Log out the active user and destroy the session. - * @param object $user the user object. - */ - static function logout() { - $user = user::active(); - if (!$user->guest) { - try { - Session::instance()->destroy(); - } catch (Exception $e) { - Kohana::log("error", $e); - } - module::event("user_logout", $user); - } + return Identity::instance()->hash_password($password); } /** @@ -304,7 +310,7 @@ class user_Core { * @return User_Model the user object, or null if the id was invalid. */ static function lookup($id) { - return self::_lookup_user_by_field("id", $id); + return Identity::instance()->lookup_user_by_field("id", $id); } /** @@ -313,55 +319,34 @@ class user_Core { * @return User_Model the user object, or null if the name was invalid. */ static function lookup_by_name($name) { - return self::_lookup_user_by_field("name", $name); + return Identity::instance()->lookup_user_by_field("name", $name); } + /** * Look up a user by hash. - * @param integer $hash the user hash value + * @param string $name the user name * @return User_Model the user object, or null if the name was invalid. */ static function lookup_by_hash($hash) { - return self::_lookup_user_by_field("hash", $hash); + return Identity::instance()->lookup_user_by_field("hash", $hash); } /** * List the users - * @param mixed filters (@see Database.php - * @return array the user list. + * @param mixed options to apply to the selection of the user(optional) + * @return array the group list. */ static function get_user_list($filter=array()) { - $user = ORM::factory("user"); - - foreach($filter as $method => $args) { - switch ($method) { - case "in": - $user->in($args[0], $args[1]); - break; - default: - $user->$method($args); - } - } - return $user->find_all(); + return Identity::instance()->get_user_list($filter); } /** - * Look up a user by field value. - * @param string search field - * @param string search value - * @return User_Core the user object, or null if the name was invalid. + * Return the edit rules associated with an user. + * + * @return stdClass containing the rules */ - private static function _lookup_user_by_field($field_name, $value) { - try { - $user = model_cache::get("user", $value, $field_name); - if ($user->loaded) { - return $user; - } - } catch (Exception $e) { - if (strpos($e->getMessage(), "MISSING_MODEL") === false) { - throw $e; - } - } - return null; + static function get_edit_rules() { + return Identity::instance()->get_edit_rules("user"); } }
\ No newline at end of file diff --git a/modules/gallery/libraries/Identity.php b/modules/gallery/libraries/Identity.php new file mode 100644 index 00000000..488cc535 --- /dev/null +++ b/modules/gallery/libraries/Identity.php @@ -0,0 +1,223 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** + * Provides a driver-based interface for managing users and groups. + */ +class Identity_Core { + protected static $instances = array(); + + // Configuration + protected $config; + + // Driver object + protected $driver; + + /** + * Returns a singleton instance of Identity. + * + * @param string configuration + * @return Identity_Core + */ + static function & instance($config="default") { + if (!isset(Identity::$instances[$config])) { + // Create a new instance + Identity::$instances[$config] = new Identity($config); + } + + return Identity::$instances[$config]; + } + + /** + * Loads the configured driver and validates it. + * + * @param array|string custom configuration or config group name + * @return void + */ + public function __construct($config="default") { + if (is_string($config)) { + $name = $config; + + // Test the config group name + if (($config = Kohana::config("identity.".$config)) === NULL) { + throw new Exception("@todo NO USER LIBRARY CONFIGURATION FOR: $name"); + } + + if (is_array($config)) { + // Append the default configuration options + $config += Kohana::config("identity.default"); + } else { + // Load the default group + $config = Kohana::config("identity.default"); + } + + // Cache the config in the object + $this->config = $config; + + // Set driver name + $driver = "Identity_".ucfirst($this->config["driver"])."_Driver"; + + // Load the driver + if ( ! Kohana::auto_load($driver)) { + throw new Kohana_Exception("core.driver_not_found", $this->config["driver"], + get_class($this)); + } + + // Initialize the driver + $this->driver = new $driver($this->config["params"]); + + // Validate the driver + if ( !($this->driver instanceof Identity_Driver)) + throw new Kohana_Exception("core.driver_implements", $this->config["driver"], + get_class($this), "Identity_Driver"); + + Kohana::log("debug", "Identity Library initialized"); + } + } + + /** + * Determine if a feature is supported by the driver. + * + * @param string $feature the name of the feature to check + * @return boolean true if supported + */ + public function is_writable() { + return !empty($this->config["allow_updates"]); + } + + + /** + * Return the guest user. + * + * @todo consider caching + * + * @return Identity_Model + */ + public function guest() { + return $this->driver->guest(); + } + + /** + * Create a new user. + * + * @param string $name + * @param string $full_name + * @param string $password + * @return Identity_Model + */ + public function create_user($name, $full_name, $password) { + return $this->driver->create_user($name, $full_name, $password); + } + + /** + * Is the password provided correct? + * + * @param user Identity Model + * @param string $password a plaintext password + * @return boolean true if the password is correct + */ + public function is_correct_password($user, $password) { + return $this->driver->is_correct_password($user, $password); + } + + /** + * Create the hashed passwords. + * @param string $password a plaintext password + * @return string hashed password + */ + public function hash_password($password) { + return $this->driver->hash_password($password); + } + + /** + * Look up a user by field value. + * @param string search field + * @param string search value + * @return Identity_Model the user object, or null if the name was invalid. + */ + public function lookup_user_by_field($field_name, $value) { + return $this->driver->lookup_user_by_field($field_name, $value); + } + + /** + * Create a new group. + * + * @param string $name + * @return Group_Model + */ + public function create_group($name) { + return $this->driver->create_group($name); + } + + /** + * The group of all possible visitors. This includes the guest user. + * + * @return Group_Model + */ + public function everybody() { + return $this->driver->everybody(); + } + + /** + * The group of all logged-in visitors. This does not include guest users. + * + * @return Group_Model + */ + public function registered_users() { + return $this->driver->everybody(); + } + + /** + * Look up a group by name. + * @param integer $id the group name + * @return Group_Model the group object, or null if the name was invalid. + */ + public function lookup_group_by_field($field_name, $value) { + return $this->driver->lookup_group_by_field($field_name, $value); + } + + /** + * List the users + * @param mixed options to apply to the selection of the user + * @return array the group list. + */ + public function get_user_list($filter=array()) { + return $this->driver->get_user_list($filter); + } + + /** + * List the groups + * @param mixed options to apply to the selection of the user + * @return array the group list. + */ + public function get_group_list($filter=array()) { + return $this->driver->get_group_list($filter); + } + + /** + * Return the edit rules associated with an group. + * + * @param string $object_type to return rules for ("user"|"group") + * @return stdClass containing the rules + */ + public function get_edit_rules($object_type) { + return $this->driver->get_edit_rules($object_type); + } +} // End Identity diff --git a/modules/gallery/libraries/drivers/Identity.php b/modules/gallery/libraries/drivers/Identity.php new file mode 100644 index 00000000..ca80aad5 --- /dev/null +++ b/modules/gallery/libraries/drivers/Identity.php @@ -0,0 +1,286 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +interface Identity_Driver { + /** + * Return the guest user. + * + * @todo consider caching + * + * @return User_Model + */ + public function guest(); + + /** + * Create a new user. + * + * @param string $name + * @param string $full_name + * @param string $password + * @return User_Core + */ + public function create_user($name, $full_name, $password); + + /** + * Is the password provided correct? + * + * @param user User Model + * @param string $password a plaintext password + * @return boolean true if the password is correct + */ + public function is_correct_password($user, $password); + + /** + * Create the hashed passwords. + * @param string $password a plaintext password + * @return string hashed password + */ + public function hash_password($password); + + /** + * Look up a user by by search the specified field. + * @param string search field + * @param string search value + * @return User_Core the user object, or null if the name was invalid. + */ + public function lookup_user_by_field($field, $value); + + /** + * Create a new group. + * + * @param string $name + * @return Group_Model + */ + public function create_group($name); + + /** + * The group of all possible visitors. This includes the guest user. + * + * @return Group_Model + */ + public function everybody(); + + /** + * The group of all logged-in visitors. This does not include guest users. + * + * @return Group_Model + */ + public function registered_users(); + + /** + * List the users + * @param mixed options to apply to the selection of the user + * @todo Do a longer write up on format of filters (@see Database.php) + * @return array the group list. + */ + public function get_user_list($filter=array()); + + /** + * List the groups + * @param mixed options to apply to the selection of the group + * @todo Do a longer write up on format of filters (@see Database.php) + * @return array the group list. + */ + public function get_group_list($filter=array()); + + /** + * Return the edit rules associated with an group. + * + * @param string $object_type to return rules for ("user"|"group") + * @return stdClass containing the rules + */ + public function get_edit_rules($object_type); +} // End Identity Driver Definition + +/** + * User Data wrapper + */ +abstract class User_Definition { + protected $user; + public function __get($column) { + switch ($column) { + case "id": + case "name": + case "full_name": + case "password": + case "login_count": + case "last_login": + case "email": + case "admin": + case "guest": + case "hash": + case "url": + case "locale": + case "groups": + return $this->user->$column; + case "hashed_password": + throw new Exception("@todo WRITE ONLY FIELD: $column"); + break; + default: + throw new Exception("@todo UNSUPPORTED FIELD: $column"); + break; + } + } + + public function __set($column, $value) { + switch ($column) { + case "id": + case "groups": + throw new Exception("@todo READ ONLY FIELD: $column"); + break; + case "name": + case "full_name": + case "hashed_password": + case "password": + case "login_count": + case "last_login": + case "email": + case "admin": + case "guest": + case "hash": + case "url": + case "locale": + $this->user->$column = $value; + break; + default: + throw new Exception("@todo UNSUPPORTED FIELD: $column"); + break; + } + } + + public function __isset($column) { + return isset($this->user->$column); + } + + public function __unset($column) { + switch ($column) { + case "id": + case "groups": + throw new Exception("@todo READ ONLY FIELD: $column"); + break; + case "name": + case "full_name": + case "password": + case "login_count": + case "last_login": + case "email": + case "admin": + case "guest": + case "hash": + case "url": + case "locale": + unset($this->user->$column); + break; + case "hashed_password": + throw new Exception("@todo WRITE ONLY FIELD: $column"); + default: + throw new Exception("@todo UNSUPPORTED FIELD: $column"); + break; + } + } + + /** + * Return a url to the user's avatar image. + * @param integer $size the target size of the image (default 80px) + * @return string a url + */ + public function avatar_url($size=80, $default=null) { + return sprintf("http://www.gravatar.com/avatar/%s.jpg?s=%d&r=pg%s", + md5($this->user->email), $size, $default ? "&d=" . urlencode($default) : ""); + } + + /** + * Return the best version of the user's name. Either their specified full name, or fall back + * to the user name. + * @return string + */ + public function display_name() { + return empty($this->user->full_name) ? $this->user->name : $this->user->full_name; + } + + public function uncloaked() { + return $this->user; + } + + abstract public function save(); + abstract public function delete(); +} + +/** + * Group Data wrapper + */ +abstract class Group_Definition { + protected $group; + + public function __get($column) { + switch ($column) { + case "id": + case "name": + case "special": + case "users": + return $this->group->$column; + default: + throw new Exception("@todo UNSUPPORTED FIELD: $column"); + break; + } + } + + public function __set($column, $value) { + switch ($column) { + case "id": + case "users": + throw new Exception("@todo READ ONLY FIELD: $column"); + break; + case "name": + case "special": + $this->group->$column = $value; + default: + throw new Exception("@todo UNSUPPORTED FIELD: $column"); + break; + } + } + + public function __isset($column) { + return isset($this->group->$column); + } + + public function __unset($column) { + switch ($column) { + case "id": + case "users": + throw new Exception("@todo READ ONLY FIELD: $column"); + break; + case "name": + case "special": + unset($this->group->$column); + default: + throw new Exception("@todo UNSUPPORTED FIELD: $column"); + break; + } + } + + public function uncloaked() { + return $this->group; + } + + abstract public function save(); + abstract public function delete(); + abstract public function add($user); + abstract public function remove($user); +} diff --git a/modules/user/views/admin_users.html.php b/modules/gallery/views/admin_users.html.php index a127bc15..82d0926c 100644 --- a/modules/user/views/admin_users.html.php +++ b/modules/gallery/views/admin_users.html.php @@ -2,7 +2,7 @@ <script type="text/javascript"> var add_user_to_group_url = "<?= url::site("admin/users/add_user_to_group/__USERID__/__GROUPID__?csrf=$csrf") ?>"; $(document).ready(function(){ - $("#g-user-admin-list .core-info").draggable({ + $("#g-user-admin-list .g-draggable").draggable({ helper: "clone" }); $("#g-group-admin .g-group").droppable({ @@ -20,6 +20,7 @@ }); $("#group-1").droppable("destroy"); $("#group-2").droppable("destroy"); + $(".g-group-disable").droppable("destroy"); }); var reload_group = function(group_id) { @@ -42,12 +43,14 @@ } </script> <div class="g-block"> + <? if (!empty($writable)): ?> <a href="<?= url::site("admin/users/add_user_form") ?>" class="g-dialog-link g-button g-right ui-icon-left ui-state-default ui-corner-all" title="<?= t("Create a new user")->for_html_attr() ?>"> <span class="ui-icon ui-icon-circle-plus"></span> <?= t("Add a new user") ?> </a> + <? endif ?> <h2> <?= t("User Admin") ?> @@ -65,7 +68,7 @@ <? foreach ($users as $i => $user): ?> <tr id="g-user-<?= $user->id ?>" class="<?= text::alternate("g-odd", "g-even") ?> user <?= $user->admin ? "admin" : "" ?>"> - <td id="user-<?= $user->id ?>" class="core-info g-draggable"> + <td id="user-<?= $user->id ?>" class="core-info <?= !empty($writable) ? "g-draggable" : "" ?> "> <img src="<?= $user->avatar_url(20, $theme->url("images/avatar.jpg", true)) ?>" title="<?= t("Drag user onto group below to add as a new member")->for_html_attr() ?>" alt="<?= html::clean_attribute($user->name) ?>" @@ -86,15 +89,19 @@ <a href="<?= url::site("admin/users/edit_user_form/$user->id") ?>" open_text="<?= t("close") ?>" class="g-panel-link g-button ui-state-default ui-corner-all ui-icon-left"> - <span class="ui-icon ui-icon-pencil"></span><span class="g-button-text"><?= t("edit") ?></span></a> - <? if (user::active()->id != $user->id && !$user->guest): ?> - <a href="<?= url::site("admin/users/delete_user_form/$user->id") ?>" - class="g-dialog-link g-button ui-state-default ui-corner-all ui-icon-left"> - <span class="ui-icon ui-icon-trash"></span><?= t("delete") ?></a> - <? else: ?> - <span title="<?= t("This user cannot be deleted")->for_html_attr() ?>" - class="g-button ui-state-disabled ui-corner-all ui-icon-left"> - <span class="ui-icon ui-icon-trash"></span><?= t("delete") ?></span> + <span class="ui-icon ui-icon-pencil"></span><span class="g-button-text"> + <?= (!empty($writable)) ? t("edit") : t("display") ?> + </span></a> + <? if (!empty($writable)): ?> + <? if (user::active()->id != $user->id && !$user->guest): ?> + <a href="<?= url::site("admin/users/delete_user_form/$user->id") ?>" + class="g-dialog-link g-button ui-state-default ui-corner-all ui-icon-left"> + <span class="ui-icon ui-icon-trash"></span><?= t("delete") ?></a> + <? else: ?> + <span title="<?= t("This user cannot be deleted")->for_html_attr() ?>" + class="g-button ui-state-disabled ui-corner-all ui-icon-left"> + <span class="ui-icon ui-icon-trash"></span><?= t("delete") ?></span> + <? endif ?> <? endif ?> </td> </tr> @@ -104,12 +111,14 @@ </div> <div id="g-group-admin" class="g-block g-clearfix"> + <? if (!empty($writable)): ?> <a href="<?= url::site("admin/users/add_group_form") ?>" class="g-dialog-link g-button g-right ui-icon-left ui-state-default ui-corner-all" title="<?= t("Create a new group")->for_html_attr() ?>"> <span class="ui-icon ui-icon-circle-plus"></span> <?= t("Add a new group") ?> </a> + <? endif ?> <h2> <?= t("Group Admin") ?> @@ -118,8 +127,9 @@ <div class="g-block-content"> <ul> <? foreach ($groups as $i => $group): ?> - <li id="group-<?= $group->id ?>" class="g-group <?= ($group->special ? "g-default-group" : "") ?>" /> - <? $v = new View("admin_users_group.html"); $v->group = $group; ?> + <? $class = !empty($writable) ? "" : "g-group-disable" ?> + <li id="group-<?= $group->id ?>" class="g-group <?= $class ?> <?= ($group->special ? "g-default-group" : "") ?>" /> + <? $v = new View("admin_users_group.html"); $v->group = $group; $v->writable = !empty($writable) ?> <?= $v ?> </li> <? endforeach ?> diff --git a/modules/user/views/admin_users_group.html.php b/modules/gallery/views/admin_users_group.html.php index db3645a0..539f69b7 100644 --- a/modules/user/views/admin_users_group.html.php +++ b/modules/gallery/views/admin_users_group.html.php @@ -4,7 +4,7 @@ <? if (!$group->special): ?> <a href="<?= url::site("admin/users/delete_group_form/$group->id") ?>" title="<?= t("Delete the %name group", array("name" => $group->name))->for_html_attr() ?>" - class="g-dialog-link g-button ui-state-default ui-corner-all"> + class="g-dialog-link g-button ui-state-default ui-corner-all <?= !empty($writable) ? "" : "ui-state-disabled" ?>"> <span class="ui-icon ui-icon-trash"><?= t("delete") ?></span></a> <? else: ?> <a title="<?= t("This default group cannot be deleted")->for_html_attr() ?>" @@ -20,7 +20,7 @@ <?= html::clean($user->name) ?> <? if (!$group->special): ?> <a href="javascript:remove_user(<?= $user->id ?>, <?= $group->id ?>)" - class="g-button ui-state-default ui-corner-all ui-icon-left" + class="g-button ui-state-default ui-corner-all ui-icon-left <?= !empty($writable) ? "" : "ui-state-disabled" ?>" title="<?= t("Remove %user from %group group", array("user" => $user->name, "group" => $group->name))->for_html_attr() ?>"> <span class="ui-icon ui-icon-closethick"><?= t("remove") ?></span> diff --git a/modules/user/views/login.html.php b/modules/gallery/views/login.html.php index 049ba043..fa6308ae 100644 --- a/modules/user/views/login.html.php +++ b/modules/gallery/views/login.html.php @@ -10,7 +10,7 @@ <li class="first"> <?= t('Logged in as %name', array('name' => html::mark_clean( '<a href="' . url::site("form/edit/users/{$user->id}") . - '" title="' . t("Edit Your Profile")->for_html_attr() . + '" title="' . ($writable ? t("Edit Your Profile")->for_html_attr() : t("Display Your Profile")->for_html_attr()) . '" id="g-user-profile-link" class="g-dialog-link">' . html::clean($user->display_name()) . '</a>'))) ?> </li> diff --git a/modules/user/views/login_ajax.html.php b/modules/gallery/views/login_ajax.html.php index d3364b46..332a5365 100644 --- a/modules/user/views/login_ajax.html.php +++ b/modules/gallery/views/login_ajax.html.php @@ -36,8 +36,10 @@ <li id="g-login-form"> <?= $form ?> </li> + <? if (!empty($writable)): ?> <li> <a href="#" id="g-password-reset" class="g-right g-txt-small"><?= t("Forgot Your Password?") ?></a> </li> + <? endif ?> </ul> </div> diff --git a/modules/user/views/reset_password.html.php b/modules/gallery/views/reset_password.html.php index 92ca4917..92ca4917 100644 --- a/modules/user/views/reset_password.html.php +++ b/modules/gallery/views/reset_password.html.php diff --git a/modules/user/views/user_languages_block.html.php b/modules/gallery/views/user_languages_block.html.php index 89185967..89185967 100644 --- a/modules/user/views/user_languages_block.html.php +++ b/modules/gallery/views/user_languages_block.html.php diff --git a/modules/user/libraries/drivers/Identity/Gallery.php b/modules/user/libraries/drivers/Identity/Gallery.php new file mode 100644 index 00000000..f631bd63 --- /dev/null +++ b/modules/user/libraries/drivers/Identity/Gallery.php @@ -0,0 +1,293 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +/* + * Based on the Cache_Sqlite_Driver developed by the Kohana Team + */ +class Identity_Gallery_Driver implements Identity_Driver { + /** + * Return the guest user. + * + * @todo consider caching + * + * @return User_Model + */ + public function guest() { + return new Gallery_User(model_cache::get("user", 1)); + } + + /** + * Create a new user. + * + * @param string $name + * @param string $full_name + * @param string $password + * @return User_Model + */ + public function create_user($name, $full_name, $password) { + $user = ORM::factory("user")->where("name", $name)->find(); + if ($user->loaded) { + throw new Exception("@todo USER_ALREADY_EXISTS $name"); + } + + $user->name = $name; + $user->full_name = $full_name; + $user->password = $password; + + // Required groups + $user->add($this->everybody()->uncloaked()); + $user->add($this->registered_users()->uncloaked()); + + $user->save(); + return new Gallery_User($user); + } + + /** + * Is the password provided correct? + * + * @param user User Model + * @param string $password a plaintext password + * @return boolean true if the password is correct + */ + public function is_correct_password($user, $password) { + $valid = $user->password; + + // Try phpass first, since that's what we generate. + if (strlen($valid) == 34) { + require_once(MODPATH . "user/lib/PasswordHash.php"); + $hashGenerator = new PasswordHash(10, true); + return $hashGenerator->CheckPassword($password, $valid); + } + + $salt = substr($valid, 0, 4); + // Support both old (G1 thru 1.4.0; G2 thru alpha-4) and new password schemes: + $guess = (strlen($valid) == 32) ? md5($password) : ($salt . md5($salt . $password)); + if (!strcmp($guess, $valid)) { + return true; + } + + // Passwords with <&"> created by G2 prior to 2.1 were hashed with entities + $sanitizedPassword = html::specialchars($password, false); + $guess = (strlen($valid) == 32) ? md5($sanitizedPassword) + : ($salt . md5($salt . $sanitizedPassword)); + if (!strcmp($guess, $valid)) { + return true; + } + + return false; + } + + /** + * Create the hashed passwords. + * @param string $password a plaintext password + * @return string hashed password + */ + public function hash_password($password) { + require_once(MODPATH . "user/lib/PasswordHash.php"); + $hashGenerator = new PasswordHash(10, true); + return $hashGenerator->HashPassword($password); + } + + /** + * Look up a user by field value. + * @param string search field + * @param string search value + * @return User_Core the user object, or null if the name was invalid. + */ + public function lookup_user_by_field($field_name, $value) { + try { + $user = model_cache::get("user", $value, $field_name); + if ($user->loaded) { + return new Gallery_User($user); + } + } catch (Exception $e) { + if (strpos($e->getMessage(), "MISSING_MODEL") === false) { + throw $e; + } + } + return null; + } + + /** + * Create a new group. + * + * @param string $name + * @return Group_Model + */ + public function create_group($name) { + $group = ORM::factory("group")->where("name", $name)->find(); + if ($group->loaded) { + throw new Exception("@todo GROUP_ALREADY_EXISTS $name"); + } + + $group->name = $name; + $group->save(); + + return new Gallery_Group($group); + } + + /** + * The group of all possible visitors. This includes the guest user. + * + * @return Group_Model + */ + public function everybody() { + return new Gallery_Group(model_cache::get("group", 1)); + } + + /** + * The group of all logged-in visitors. This does not include guest users. + * + * @return Group_Model + */ + public function registered_users() { + return new Gallery_Group(model_cache::get("group", 2)); + } + + /** + * Look up a group by field value. + * @param string search field + * @param string search value + * @return Group_Core the group object, or null if the name was invalid. + */ + public function lookup_group_by_field($field_name, $value) { + try { + $user = model_cache::get("group", $value, $field_name); + if ($user->loaded) { + return new Gallery_Group($group); + } + } catch (Exception $e) { + if (strpos($e->getMessage(), "MISSING_MODEL") === false) { + throw $e; + } + } + return null; + } + + + /** + * List the users + * @param mixed options to apply to the selection of the user + * @return array the group list. + */ + public function get_user_list($filter=array()) { + $results = $this->_do_search("user", $filter); + $users = array(); + foreach ($results->as_array() as $user) { + $users[] = new Gallery_User($user); + } + return $users; + } + + + /** + * List the groups + * @param mixed options to apply to the selection of the group + * @return array the group list. + */ + public function get_group_list($filter=array()) { + $results = $this->_do_search("group", $filter); + $groups = array(); + foreach ($results->as_array() as $group) { + $groups[] = new Gallery_Group($group); + } + return $groups; + } + + /** + * Return the edit rules associated with an group. + * + * @param string $object_type to return rules for ("user"|"group") + * @return stdClass containing the rules + */ + public function get_edit_rules($object_type) { + return (object)ORM::factory($object_type)->rules; + } + + /** + * Build the query based on the supplied filters for the specified model. + * @param string $object_type to return rules for ("user"|"group") + * @param mixed $filters options to apply to the selection. + */ + private function _do_search($object_type, $filter) { + $object = ORM::factory($object_type); + + foreach ($filter as $method => $args) { + switch ($method) { + case "in": + $object->in($args[0], $args[1]); + break; + default: + $object->$method($args); + } + } + + return $object->find_all(); + } + +} // End Identity Gallery Driver + +/** + * User Data wrapper + */ +class Gallery_User extends User_Definition { + /* + * Not for general user, allows the back-end to easily create the interface object + */ + function __construct($user) { + $this->user = $user; + } + + public function save() { + $this->user->save(); + } + + public function delete() { + $this->user->delete(); + } + +} + +/** + * Group Data wrapper + */ +class Gallery_Group extends Group_Definition { + /* + * Not for general user, allows the back-end to easily create the interface object + */ + function __construct($group) { + $this->group = $group; + } + + public function save() { + $this->group->save(); + } + + public function delete() { + $this->group->delete(); + } + + public function add($user) { + $this->group->add($user->uncloaked()); + } + + public function remove($user) { + $this->group->remove($user->uncloaked()); + } +} diff --git a/modules/user/models/user.php b/modules/user/models/user.php index 55562f34..1993bd05 100644 --- a/modules/user/models/user.php +++ b/modules/user/models/user.php @@ -51,16 +51,6 @@ class User_Model extends ORM { module::event("user_deleted", $old); } - /** - * Return a url to the user's avatar image. - * @param integer $size the target size of the image (default 80px) - * @return string a url - */ - public function avatar_url($size=80, $default=null) { - return sprintf("http://www.gravatar.com/avatar/%s.jpg?s=%d&r=pg%s", - md5($this->email), $size, $default ? "&d=" . urlencode($default) : ""); - } - public function save() { if (!$this->loaded) { $created = 1; @@ -73,13 +63,4 @@ class User_Model extends ORM { } return $this; } - - /** - * Return the best version of the user's name. Either their specified full name, or fall back - * to the user name. - * @return string - */ - public function display_name() { - return empty($this->full_name) ? $this->name : $this->full_name; - } -}
\ No newline at end of file +} diff --git a/themes/admin_wind/css/screen.css b/themes/admin_wind/css/screen.css index 3c58a282..22f49d21 100644 --- a/themes/admin_wind/css/screen.css +++ b/themes/admin_wind/css/screen.css @@ -542,7 +542,8 @@ li.g-group .g-user .g-button { vertical-align: middle; } -li.g-default-group h4, li.g-default-group .g-user { +li.g-default-group h4, li.g-default-group .g-user, +li.g-group-disable h4, li.g-group-disable .g-user { color: gray; } |