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/users.php4
-rw-r--r--modules/user/helpers/group.php89
-rw-r--r--modules/user/helpers/user.php95
-rw-r--r--modules/user/helpers/user_event.php15
-rw-r--r--modules/user/libraries/drivers/Identity/Gallery.php188
-rw-r--r--modules/user/models/user.php2
-rw-r--r--modules/user/views/admin_users.html.php11
9 files changed, 440 insertions, 21 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 5950c358..258de843 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 == Session::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 != Session::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 == Session::active_user()->id) {
$form->edit_user->admin->disabled(1);
}
print $form;
@@ -325,8 +329,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"));
@@ -378,8 +381,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/users.php b/modules/user/controllers/users.php
index b03a47cc..0ccf3e2a 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 != Session::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 != Session::active_user()->id) {
access::forbidden();
}
diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php
new file mode 100644
index 00000000..cf5c050f
--- /dev/null
+++ b/modules/user/helpers/group.php
@@ -0,0 +1,89 @@
+<?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.
+ */
+
+/**
+ * This is the API for handling groups.
+ *
+ * Note: by design, this class does not do any permission checking.
+ */
+class group_Core {
+ /**
+ * @see Identity_Driver::create.
+ */
+ 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;
+ }
+
+ /**
+ * @see Identity_Driver::everbody.
+ */
+ static function everybody() {
+ return Identity::instance()->everybody();
+ }
+
+ /**
+ * @see Identity_Driver::registered_users.
+ */
+ static function registered_users() {
+ return Identity::instance()->everybody();
+ }
+
+ /**
+ * Look up a group by id.
+ * @param integer $id the user id
+ * @return Group_Definition the group object, or null if the id was invalid.
+ */
+ static function lookup($id) {
+ return self::lookup_by_field("id", $id);
+ }
+
+ /**
+ * Look up a group by name.
+ * @param integer $id the group name
+ * @return Group_Definition the group object, or null if the name was invalid.
+ */
+ static function lookup_by_name($name) {
+ return self::lookup_by_field("name", $name);
+ }
+
+ /**
+ * @see Identity_Driver::get_group_list.
+ */
+ static function lookup_by_field($field_name, $value) {
+ try {
+ $user = model_cache::get("group", $value, $field_name);
+ if ($user->loaded) {
+ return $user;
+ }
+ } catch (Exception $e) {
+ if (strpos($e->getMessage(), "MISSING_MODEL") === false) {
+ throw $e;
+ }
+ }
+ return null;
+ }
+}
diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php
new file mode 100644
index 00000000..fa7b320f
--- /dev/null
+++ b/modules/user/helpers/user.php
@@ -0,0 +1,95 @@
+<?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.
+ */
+
+/**
+ * This is the API for handling users.
+ *
+ * Note: by design, this class does not do any permission checking.
+ */
+class user_Core {
+ /**
+ * @see Identity_Driver::guest.
+ */
+ static function guest() {
+ return model_cache::get("user", 1);
+ }
+
+ /**
+ * @see Identity_Driver::create_user.
+ */
+ 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;
+ }
+
+ /**
+ * @see Identity_Driver::hash_password.
+ */
+ static 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 id.
+ * @param integer $id the user id
+ * @return User_Definition the user object, or null if the id was invalid.
+ */
+ static function lookup($id) {
+ return self::lookup_by_field("id", $id);
+ }
+
+ /**
+ * Look up a user by name.
+ * @param integer $name the user name
+ * @return User_Definition the user object, or null if the name was invalid.
+ */
+ static function lookup_by_name($name) {
+ return self::lookup_by_field("name", $name);
+ }
+
+ static function lookup_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;
+ }
+} \ No newline at end of file
diff --git a/modules/user/helpers/user_event.php b/modules/user/helpers/user_event.php
index 78b009eb..00ccbb29 100644
--- a/modules/user/helpers/user_event.php
+++ b/modules/user/helpers/user_event.php
@@ -20,11 +20,16 @@
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/libraries/drivers/Identity/Gallery.php b/modules/user/libraries/drivers/Identity/Gallery.php
new file mode 100644
index 00000000..77db11a3
--- /dev/null
+++ b/modules/user/libraries/drivers/Identity/Gallery.php
@@ -0,0 +1,188 @@
+<?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 {
+ /**
+ * @see Identity_Driver::guest.
+ */
+ public function guest() {
+ return new Gallery_User(user::guest());
+ }
+
+ /**
+ * @see Identity_Driver::create_user.
+ */
+ public function create_user($name, $full_name, $password) {
+ return new Gallery_User(user::create($name, $full_name, $password));
+ }
+
+ /**
+ * @see Identity_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 Identity_Driver::hash_password.
+ */
+ public function hash_password($password) {
+ return user::hash_password($password);
+ }
+
+ /**
+ * @see Identity_Driver::lookup_user_by_field.
+ */
+ public function lookup_user_by_field($field_name, $value) {
+ return new Gallery_User(user::lookup_by_field($field_name, $value));
+ }
+
+ /**
+ * @see Identity_Driver::create_group.
+ */
+ public function create_group($name) {
+ return new Gallery_Group(group::create($name));
+ }
+
+ /**
+ * @see Identity_Driver::everybody.
+ */
+ public function everybody() {
+ return new Gallery_Group(group::everybody());
+ }
+
+ /**
+ * @see Identity_Driver::registered_users.
+ */
+ public function registered_users() {
+ return new Gallery_Group(group::registered_users());
+ }
+
+ /**
+ * @see Identity_Driver::lookup_group_by_field.
+ */
+ public function lookup_group_by_field($field_name, $value) {
+ return new Gallery_Group(group::lookup_by_field($field_name, $value));
+ }
+
+ /**
+ * @see Identity_Driver::get_user_list.
+ */
+ public function get_user_list($ids) {
+ $results = ORM::factory("user")
+ ->in("id", ids)
+ ->find_all()
+ ->as_array();;
+ $users = array();
+ foreach ($results as $user) {
+ $users[] = new Gallery_User($user);
+ }
+ return $users;
+ }
+} // 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;
+ }
+
+ /**
+ * @see User_Definition::avatar_url
+ */
+ public function avatar_url($size=80, $default=null) {
+ return $this->user->avatar_url($size, $default);
+ }
+
+ /**
+ * @see User_Definition::display_name
+ */
+ public function display_name() {
+ return $this->user->display_name();
+ }
+
+ 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..d99603b2 100644
--- a/modules/user/models/user.php
+++ b/modules/user/models/user.php
@@ -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 2f8d8673..cee7c1eb 100644
--- a/modules/user/views/admin_users.html.php
+++ b/modules/user/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) {
@@ -86,10 +87,12 @@
<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): ?>
+ <span class="ui-icon ui-icon-pencil"></span><span class="g-button-text">
+ <?= t("edit") ?>
+ </span></a>
+ <? if (Session::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">
+ 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() ?>"