summaryrefslogtreecommitdiff
path: root/modules/user/helpers
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-10-16 07:41:33 -0700
committerTim Almdal <tnalmdal@shaw.ca>2009-10-16 08:55:26 -0700
commitbc241e44c2e4d10ac19ccc32a40c90426672d963 (patch)
treeaade0e13346a059c061e2f2f4a767e25a45fe17b /modules/user/helpers
parent00eacd659f27df9c13246c510057c4f42c8866a2 (diff)
Cleanup merge of user/group helpers into Identity interface. Reduce redundant code in the user module and remove references to the Identity helper from the user module as the user module should be able to access things directly. Simplify the get_user_list api method to just accept an array of ids to return user objects for.
Diffstat (limited to 'modules/user/helpers')
-rw-r--r--modules/user/helpers/group.php34
-rw-r--r--modules/user/helpers/user.php56
2 files changed, 43 insertions, 47 deletions
diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php
index 295e5f50..cf5c050f 100644
--- a/modules/user/helpers/group.php
+++ b/modules/user/helpers/group.php
@@ -28,7 +28,14 @@ class group_Core {
* @see Identity_Driver::create.
*/
static function create($name) {
- return Identity::instance()->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 $group;
}
/**
@@ -51,7 +58,7 @@ class group_Core {
* @return Group_Definition the group object, or null if the id was invalid.
*/
static function lookup($id) {
- return Identity::instance()->lookup_group_by_field("id", $id);
+ return self::lookup_by_field("id", $id);
}
/**
@@ -60,20 +67,23 @@ class group_Core {
* @return Group_Definition the group object, or null if the name was invalid.
*/
static function lookup_by_name($name) {
- return Identity::instance()->lookup_group_by_field("name", $name);
+ return self::lookup_by_field("name", $name);
}
/**
* @see Identity_Driver::get_group_list.
*/
- static function get_group_list($filter=array()) {
- return Identity::instance()->get_group_list($filter);
- }
-
- /**
- * @see Identity_Driver::get_edit_rules.
- */
- static function get_edit_rules() {
- return Identity::instance()->get_edit_rules("group");
+ 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
index 394f8185..fa7b320f 100644
--- a/modules/user/helpers/user.php
+++ b/modules/user/helpers/user.php
@@ -28,28 +28,37 @@ class user_Core {
* @see Identity_Driver::guest.
*/
static function guest() {
- return Identity::guest();
+ return model_cache::get("user", 1);
}
/**
* @see Identity_Driver::create_user.
*/
static function create($name, $full_name, $password) {
- return Identity::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");
+ }
- /**
- * @see Identity_Driver::is_correct_password.
- */
- static function is_correct_password($user, $password) {
- return Identity::is_correct_password($user, $password);
+ $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) {
- return Identity::hash_password($password);
+ require_once(MODPATH . "user/lib/PasswordHash.php");
+ $hashGenerator = new PasswordHash(10, true);
+ return $hashGenerator->HashPassword($password);
}
/**
@@ -58,7 +67,7 @@ class user_Core {
* @return User_Definition the user object, or null if the id was invalid.
*/
static function lookup($id) {
- return self::_lookup_user_by_field("id", $id);
+ return self::lookup_by_field("id", $id);
}
/**
@@ -67,33 +76,10 @@ class user_Core {
* @return User_Definition the user object, or null if the name was invalid.
*/
static function lookup_by_name($name) {
- return self::_lookup_user_by_field("name", $name);
- }
-
- /**
- * Look up a user by hash.
- * @param string $name the user name
- * @return User_Definition the user object, or null if the name was invalid.
- */
- static function lookup_by_hash($hash) {
- return self::_lookup_user_by_field("hash", $hash);
- }
-
- /**
- * @see Identity_Driver::get_user_list.
- */
- static function get_user_list($filter=array()) {
- return Identity::get_user_list($filter);
- }
-
- /**
- * @see Identity_Driver::get_edit_rules.
- */
- static function get_edit_rules() {
- return Identity::get_edit_rules("user");
+ return self::lookup_by_field("name", $name);
}
- private static function _lookup_user_by_field($field_name, $value) {
+ static function lookup_by_field($field_name, $value) {
try {
$user = model_cache::get("user", $value, $field_name);
if ($user->loaded) {