summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers/identity.php
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-10-22 13:09:20 -0700
committerTim Almdal <tnalmdal@shaw.ca>2009-10-22 13:11:03 -0700
commit3c936d661a088fb43b47eb5b208958180e8f65eb (patch)
tree1a117dc1bfe54bec44f664cbd7c5f8c93aa5e993 /modules/gallery/helpers/identity.php
parent4cb9ec1d6d37b49ebafc68d0a94d794a1acb8b28 (diff)
Change the name of identity library from Identity to IdentityProvider. Create a helper class called identity to simplify call the Identity Provider. Move the contents of MY_Session.php to the new helper class and remove the MY_Session class
Diffstat (limited to 'modules/gallery/helpers/identity.php')
-rw-r--r--modules/gallery/helpers/identity.php225
1 files changed, 225 insertions, 0 deletions
diff --git a/modules/gallery/helpers/identity.php b/modules/gallery/helpers/identity.php
new file mode 100644
index 00000000..cf84c8a9
--- /dev/null
+++ b/modules/gallery/helpers/identity.php
@@ -0,0 +1,225 @@
+<?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.
+ */
+
+class identity_Core {
+ protected static $available;
+
+ /**
+ * Return a list of installed Identity Drivers.
+ *
+ * @return boolean true if the driver supports updates; false if read only
+ */
+ static function providers() {
+ if (empty(self::$available)) {
+ $drivers = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
+ foreach (module::available() as $module_name => $module) {
+ if (file_exists(MODPATH . "{$module_name}/config/identity.php")) {
+ $drivers->$module_name = $module->description;
+ }
+ }
+ self::$available = $drivers;
+ }
+ return self::$available;
+ }
+
+ /**
+ * Make sure that we have a session and group_ids cached in the session.
+ */
+ static function load_user() {
+ //try {
+ // Call IdentityProvider::instance() now to force the load of the user interface classes.
+ // We are about to load the active user from the session and which needs the user definition
+ // class, which can't be reached by Kohana's heiracrchical lookup.
+ IdentityProvider::instance();
+
+ $session = Session::instance();
+ if (!($user = $session->get("user"))) {
+ self::set_active_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 set the user name into the session instead of 2 and then use it to get the user object
+ if ($user === 2) {
+ $user = IdentityProvider::instance()->lookup_user_by_name("admin");
+ self::set_active_user($user);
+ $session->set("user", $user);
+ }
+
+ if (!$session->get("group_ids")) {
+ $ids = array();
+ foreach ($user->groups as $group) {
+ $ids[] = $group->id;
+ }
+ $session->set("group_ids", $ids);
+ }
+ //} 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());
+ //}
+ }
+
+ /**
+ * Return the array of group ids this user belongs to
+ *
+ * @return array
+ */
+ static function group_ids_for_active_user() {
+ return Session::instance()->get("group_ids", array(1));
+ }
+
+ /**
+ * Return the active user. If there's no active user, return the guest user.
+ *
+ * @return User_Definition
+ */
+ static function active_user() {
+ // @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 = identity::guest();
+ }
+ return $user;
+ }
+
+ /**
+ * Change the active user.
+ * @param User_Definition $user
+ */
+ static function set_active_user($user) {
+ $session = Session::instance();
+ $session->set("user", $user);
+ $session->delete("group_ids");
+ self::load_user();
+ }
+
+ /**
+ * Determine if if the current driver supports updates.
+ *
+ * @return boolean true if the driver supports updates; false if read only
+ */
+ static function is_writable() {
+ 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.
+ */
+ static function guest() {
+ return IdentityProvider::instance()->guest();
+ }
+
+ /**
+ * @see IdentityProvider_Driver::create_user.
+ */
+ static function create_user($name, $full_name, $password) {
+ return IdentityProvider::instance()->create_user($name, $full_name, $password);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::is_correct_password.
+ */
+ static function is_correct_password($user, $password) {
+ return IdentityProvider::instance()->is_correct_password($user, $password);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::lookup_user.
+ */
+ static function lookup_user($id) {
+ return IdentityProvider::instance()->lookup_user($id);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::lookup_user_by_name.
+ */
+ static function lookup_user_by_name($name) {
+ return IdentityProvider::instance()->lookup_user_by_name($name);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::create_group.
+ */
+ static function create_group($name) {
+ return IdentityProvider::instance()->create_group($name);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::everybody.
+ */
+ static function everybody() {
+ return IdentityProvider::instance()->everybody();
+ }
+
+ /**
+ * @see IdentityProvider_Driver::registered_users.
+ */
+ static function registered_users() {
+ return IdentityProvider::instance()->everybody();
+ }
+
+ /**
+ * @see IdentityProvider_Driver::lookup_group.
+ */
+ static function lookup_group($id) {
+ return IdentityProvider::instance()->lookup_group($id);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::lookup_group_by_name.
+ */
+ static function lookup_group_by_name($name) {
+ return IdentityProvider::instance()->lookup_group_by_name($name);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::get_user_list.
+ */
+ static function get_user_list($ids) {
+ return IdentityProvider::instance()->get_user_list($ids);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::groups.
+ */
+ static function groups() {
+ return IdentityProvider::instance()->groups();
+ }
+} \ No newline at end of file