summaryrefslogtreecommitdiff
path: root/modules/user
diff options
context:
space:
mode:
Diffstat (limited to 'modules/user')
-rw-r--r--modules/user/config/identity.php37
-rw-r--r--modules/user/controllers/admin_users.php20
-rw-r--r--modules/user/controllers/password.php6
-rw-r--r--modules/user/controllers/users.php4
-rw-r--r--modules/user/helpers/group.php47
-rw-r--r--modules/user/helpers/user.php11
-rw-r--r--modules/user/helpers/user_event.php16
-rw-r--r--modules/user/helpers/user_installer.php10
-rw-r--r--modules/user/libraries/drivers/IdentityProvider/Gallery.php136
-rw-r--r--modules/user/models/group.php2
-rw-r--r--modules/user/models/user.php4
-rw-r--r--modules/user/views/admin_users.html.php2
12 files changed, 220 insertions, 75 deletions
diff --git a/modules/user/config/identity.php b/modules/user/config/identity.php
new file mode 100644
index 00000000..f9f013aa
--- /dev/null
+++ b/modules/user/config/identity.php
@@ -0,0 +1,37 @@
+<?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.
+ */
+/*
+ * @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.
+ * allow_updates - Flag to indicate that the back end allows updates.
+ * params - Driver parameters, specific to each driver.
+ */
+$config["user"] = array (
+ "driver" => "gallery",
+ "allow_updates" => true,
+ "params" => array(),
+);
diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php
index a34d152a..4d80521e 100644
--- a/modules/user/controllers/admin_users.php
+++ b/modules/user/controllers/admin_users.php
@@ -21,8 +21,12 @@ 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->users = user::get_user_list(array("orderby" => array("name" => "ASC")));
- $view->content->groups = group::get_group_list(array("orderby" => array("name" => "ASC")));
+ $view->content->users = ORM::factory("user")
+ ->orderby("name", "ASC")
+ ->find_all();
+ $view->content->groups = ORM::factory("group")
+ ->orderby("name", "ASC")
+ ->find_all();
print $view;
}
@@ -65,7 +69,7 @@ class Admin_Users_Controller extends Admin_Controller {
public function delete_user($id) {
access::verify_csrf();
- if ($id == user::active()->id || $id == user::guest()->id) {
+ if ($id == identity::active_user()->id || $id == user::guest()->id) {
access::forbidden();
}
@@ -132,7 +136,7 @@ class Admin_Users_Controller extends Admin_Controller {
}
// An admin can change the admin status for any user but themselves
- if ($user->id != user::active()->id) {
+ if ($user->id != identity::active_user()->id) {
$user->admin = $form->edit_user->admin->checked;
}
$user->save();
@@ -154,7 +158,7 @@ class Admin_Users_Controller extends Admin_Controller {
$form = $this->_get_user_edit_form_admin($user);
// Don't allow the user to control their own admin bit, else you can lock yourself out
- if ($user->id == user::active()->id) {
+ if ($user->id == identity::active_user()->id) {
$form->edit_user->admin->disabled(1);
}
print $form;
@@ -324,8 +328,7 @@ class Admin_Users_Controller extends Admin_Controller {
$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(ORM::factory("user"));
module::event("user_add_form_admin", $user, $form);
$group->submit("")->value(t("Add User"));
@@ -377,8 +380,7 @@ class Admin_Users_Controller extends Admin_Controller {
$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);
+ $form->add_rules_from(ORM::factory("group"));
return $form;
}
diff --git a/modules/user/controllers/password.php b/modules/user/controllers/password.php
index e8b08960..6bef1a17 100644
--- a/modules/user/controllers/password.php
+++ b/modules/user/controllers/password.php
@@ -32,7 +32,7 @@ class Password_Controller extends Controller {
if (request::method() == "post") {
$this->_change_password();
} else {
- $user = user::lookup_by_hash(Input::instance()->get("key"));
+ $user = user::lookup_user_by_field("hash", Input::instance()->get("key"));
if (!empty($user)) {
print $this->_new_password_form($user->hash);
} else {
@@ -46,7 +46,7 @@ class Password_Controller extends Controller {
$valid = $form->validate();
if ($valid) {
- $user = user::lockup_by_name($form->reset->inputs["name"]->value);
+ $user = identity::lookup_user_by_name($form->reset->inputs["name"]->value);
if (!$user->loaded || empty($user->email)) {
$form->reset->inputs["name"]->add_error("no_email", 1);
$valid = false;
@@ -116,7 +116,7 @@ class Password_Controller extends Controller {
private function _change_password() {
$view = $this->_new_password_form();
if ($view->content->validate()) {
- $user = user::lookup_by_hash(Input::instance()->get("key"));
+ $user = user::lookup_user_by_field("hash", Input::instance()->get("key"));
if (empty($user)) {
throw new Exception("@todo FORBIDDEN", 503);
}
diff --git a/modules/user/controllers/users.php b/modules/user/controllers/users.php
index 2be49065..28164e9c 100644
--- a/modules/user/controllers/users.php
+++ b/modules/user/controllers/users.php
@@ -21,7 +21,7 @@ class Users_Controller extends Controller {
public function update($id) {
$user = user::lookup($id);
- if ($user->guest || $user->id != user::active()->id) {
+ if ($user->guest || $user->id != identity::active_user()->id) {
access::forbidden();
}
@@ -59,7 +59,7 @@ class Users_Controller extends Controller {
public function form_edit($id) {
$user = user::lookup($id);
- if ($user->guest || $user->id != user::active()->id) {
+ if ($user->guest || $user->id != identity::active_user()->id) {
access::forbidden();
}
diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php
index 1702fb87..e65b6c96 100644
--- a/modules/user/helpers/group.php
+++ b/modules/user/helpers/group.php
@@ -28,7 +28,7 @@ class group_Core {
* Create a new group.
*
* @param string $name
- * @return Group_Model
+ * @return Group_Definition the group object
*/
static function create($name) {
$group = ORM::factory("group")->where("name", $name)->find();
@@ -38,14 +38,13 @@ class group_Core {
$group->name = $name;
$group->save();
-
return $group;
}
/**
* The group of all possible visitors. This includes the guest user.
*
- * @return Group_Model
+ * @return Group_Definition the group object
*/
static function everybody() {
return model_cache::get("group", 1);
@@ -54,37 +53,37 @@ class group_Core {
/**
* The group of all logged-in visitors. This does not include guest users.
*
- * @return Group_Model
+ * @return Group_Definition the group object
*/
static function registered_users() {
return model_cache::get("group", 2);
}
/**
- * Look up a user by id.
+ * Look up a group by id.
* @param integer $id the user id
- * @return User_Model the user object, or null if the id was invalid.
+ * @return Group_Definition the group object, or null if the id was invalid.
*/
static function lookup($id) {
- return self::_lookup_group_by_field("id", $id);
+ return self::_lookup_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_Definition the group object, or null if the name was invalid.
*/
static function lookup_by_name($name) {
- return self::_lookup_group_by_field("name", $name);
+ return self::_lookup_by_field("name", $name);
}
/**
- * Look up a user by field value.
- * @param string search field
- * @param string search value
- * @return Group_Model the user object, or null if the name was invalid.
+ * Search the groups by the field and value.
+ * @param string $field_name column to look up the user by
+ * @param string $value value to match
+ * @return Group_Definition the group object, or null if the name was invalid.
*/
- private static function _lookup_group_by_field($field_name, $value) {
+ private function _lookup_by_field($field_name, $value) {
try {
$user = model_cache::get("group", $value, $field_name);
if ($user->loaded) {
@@ -97,24 +96,4 @@ class group_Core {
}
return null;
}
-
- /**
- * List the users
- * @param mixed filters (@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();
- }
}
diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php
index 47f57d3d..f67429c7 100644
--- a/modules/user/helpers/user.php
+++ b/modules/user/helpers/user.php
@@ -24,17 +24,6 @@
* Note: by design, this class does not do any permission checking.
*/
class user_Core {
- static function get_login_form($url) {
- $form = new Forge($url, "", "post", array("id" => "g-login-form"));
- $form->set_attr('class', "g-one-quarter");
- $group = $form->group("login")->label(t("Login"));
- $group->input("name")->label(t("Username"))->id("g-username")->class(null);
- $group->password("password")->label(t("Password"))->id("g-password")->class(null);
- $group->inputs["name"]->error_messages("invalid_login", t("Invalid name or password"));
- $group->submit("")->value(t("Login"));
- return $form;
- }
-
/**
* Make sure that we have a session and group_ids cached in the session.
*/
diff --git a/modules/user/helpers/user_event.php b/modules/user/helpers/user_event.php
index 78b009eb..a4a6e5da 100644
--- a/modules/user/helpers/user_event.php
+++ b/modules/user/helpers/user_event.php
@@ -20,11 +20,17 @@
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")));
+ $user_group_menu = Menu::factory("link")
+ ->id("users_groups")
+ ->label(t("Users/Groups"))
+ ->url(url::site("admin/users"));
+ $identity_menu = $menu->get("identity_menu");
+ if (empty($identity_menu)) {
+ $menu->add_after("appearance_menu", $user_group_menu);
+ }else {
+ $identity_menu->append($user_group_menu);
+ }
+
return $menu;
}
}
diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php
index 8ef4f13d..520f580c 100644
--- a/modules/user/helpers/user_installer.php
+++ b/modules/user/helpers/user_installer.php
@@ -71,8 +71,7 @@ class user_installer {
$admin->save();
// Let the admin own everything
- $db->update("items", array("owner_id" => $admin->id), array("owner_id" => "IS NULL"));
- module::set_version("user", 1);
+ $db->query("update {items} set owner_id = {$admin->id}");
$root = ORM::factory("item", 1);
access::allow($everybody, "view", $root);
@@ -80,6 +79,8 @@ 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);
}
static function uninstall() {
@@ -92,11 +93,6 @@ class user_installer {
$group->delete();
}
- 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};");
diff --git a/modules/user/libraries/drivers/IdentityProvider/Gallery.php b/modules/user/libraries/drivers/IdentityProvider/Gallery.php
new file mode 100644
index 00000000..c789e8ea
--- /dev/null
+++ b/modules/user/libraries/drivers/IdentityProvider/Gallery.php
@@ -0,0 +1,136 @@
+<?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 IdentityProvider_Gallery_Driver implements IdentityProvider_Driver {
+ /**
+ * @see IdentityProvider_Driver::guest.
+ */
+ public function guest() {
+ return user::guest();
+ }
+
+ /**
+ * @see IdentityProvider_Driver::create_user.
+ */
+ public function create_user($name, $full_name, $password) {
+ return user::create($name, $full_name, $password);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::is_correct_password.
+ */
+ 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;
+ }
+
+ /**
+ * @see IdentityProvider_Driver::lookup_user.
+ */
+ public function lookup_user($id) {
+ return user::lookup($id);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::lookup_user_by_name.
+ */
+ public function lookup_user_by_name($name) {
+ return user::lookup_by_name($name);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::create_group.
+ */
+ public function create_group($name) {
+ return group::create($name);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::everybody.
+ */
+ public function everybody() {
+ return group::everybody();
+ }
+
+ /**
+ * @see IdentityProvider_Driver::registered_users.
+ */
+ public function registered_users() {
+ return group::registered_users();
+ }
+
+ /**
+ * @see IdentityProvider_Driver::lookup_group.
+ */
+ public function lookup_group($id) {
+ return group::lookup($id);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::lookup_group_by_name.
+ */
+ public function lookup_group_by_name($name) {
+ return group::lookup_by_name($name);
+ }
+
+ /**
+ * @see IdentityProvider_Driver::get_user_list.
+ */
+ public function get_user_list($ids) {
+ return ORM::factory("user")
+ ->in("id", $ids)
+ ->find_all()
+ ->as_array();
+ }
+
+ /**
+ * @see IdentityProvider_Driver::groups.
+ */
+ public function groups() {
+ return ORM::factory("group")->find_all();
+ }
+
+} // End Identity Gallery Driver
+
diff --git a/modules/user/models/group.php b/modules/user/models/group.php
index 8af78012..4432fc69 100644
--- a/modules/user/models/group.php
+++ b/modules/user/models/group.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Group_Model extends ORM {
+class Group_Model extends ORM implements Group_Definition {
protected $has_and_belongs_to_many = array("users");
var $rules = array(
diff --git a/modules/user/models/user.php b/modules/user/models/user.php
index 55562f34..c51fc720 100644
--- a/modules/user/models/user.php
+++ b/modules/user/models/user.php
@@ -17,7 +17,7 @@
* 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_Model extends ORM {
+class User_Model extends ORM implements User_Definition {
protected $has_and_belongs_to_many = array("groups");
var $rules = array(
@@ -82,4 +82,4 @@ class User_Model extends ORM {
public function display_name() {
return empty($this->full_name) ? $this->name : $this->full_name;
}
-} \ No newline at end of file
+}
diff --git a/modules/user/views/admin_users.html.php b/modules/user/views/admin_users.html.php
index aae39c8c..b64f93b1 100644
--- a/modules/user/views/admin_users.html.php
+++ b/modules/user/views/admin_users.html.php
@@ -90,7 +90,7 @@
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): ?>
+ <? if (identity::active_user()->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>