Browse files

First pass on converting calls to the Identity interface. Will worry …

…about writes and saves later.

Convert the Admin_User controller
Convert the login and password change controller
Change the item model to call user::lookup to get the owner.
On the log model, delete the relationship between the log and user table, and replace with a
call to user::lookup
  • Loading branch information...
1 parent 08c01fe commit 194cc3b27a73afe5119da9f09407c1e068dc6fa3 @talmdal talmdal committed Oct 5, 2009
View
2 modules/gallery/models/item.php
@@ -332,7 +332,7 @@ public function __get($column) {
// This relationship depends on an outside module, which may not be present so handle
// failures gracefully.
try {
- return model_cache::get("user", $this->owner_id);
+ return user::lookup($this->owner_id);
} catch (Exception $e) {
return null;
}
View
17 modules/gallery/models/log.php
@@ -18,5 +18,20 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Log_Model extends ORM {
- protected $has_one = array("user");
+ /**
+ * @see ORM::__get()
+ */
+ public function __get($column) {
+ if ($column == "user") {
+ // This relationship depends on an outside module, which may not be present so handle
+ // failures gracefully.
+ try {
+ return user::lookup($this->user_id);
+ } catch (Exception $e) {
+ return null;
+ }
+ } else {
+ return parent::__get($column);
+ }
+ }
}
View
65 modules/user/controllers/admin_users.php
@@ -21,8 +21,8 @@ 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 = ORM::factory("user")->orderby("name")->find_all();
- $view->content->groups = ORM::factory("group")->orderby("name")->find_all();
+ $view->content->users = user::users(array("orderby" => array("name")));
+ $view->content->groups = group::groups(array("orderby" => array("name")));
print $view;
}
@@ -32,8 +32,7 @@ public function add_user() {
$form = user::get_add_form_admin();
$valid = $form->validate();
$name = $form->add_user->inputs["name"]->value;
- $user = ORM::factory("user")->where("name", $name)->find();
- if ($user->loaded) {
+ if ($user = user::lookup_by_name($name)) {
$form->add_user->inputs["name"]->add_error("in_use", 1);
$valid = false;
}
@@ -70,8 +69,8 @@ public function delete_user($id) {
access::forbidden();
}
- $user = ORM::factory("user", $id);
- if (!$user->loaded) {
+ $user = user::lookup($id);
+ if (empty($user)) {
kohana::show_404();
}
@@ -91,8 +90,8 @@ public function delete_user($id) {
}
public function delete_user_form($id) {
- $user = ORM::factory("user", $id);
- if (!$user->loaded) {
+ $user = user::lookup($id);
+ if (empty($user)) {
kohana::show_404();
}
print user::get_delete_form_admin($user);
@@ -101,21 +100,18 @@ public function delete_user_form($id) {
public function edit_user($id) {
access::verify_csrf();
- $user = ORM::factory("user", $id);
- if (!$user->loaded) {
+ $user = user::lookup($id);
+ if (empty($user)) {
kohana::show_404();
}
$form = user::get_edit_form_admin($user);
$valid = $form->validate();
if ($valid) {
$new_name = $form->edit_user->inputs["name"]->value;
+ $temp_user = user::lookup_by_name($new_name);
if ($new_name != $user->name &&
- ORM::factory("user")
- ->where("name", $new_name)
- ->where("id !=", $user->id)
- ->find()
- ->loaded) {
+ ($temp_user && $temp_user->id != $user->id)) {
$form->edit_user->inputs["name"]->add_error("in_use", 1);
$valid = false;
} else {
@@ -151,8 +147,8 @@ public function edit_user($id) {
}
public function edit_user_form($id) {
- $user = ORM::factory("user", $id);
- if (!$user->loaded) {
+ $user = user::lookup($id);
+ if (empty($user)) {
kohana::show_404();
}
@@ -166,23 +162,23 @@ public function edit_user_form($id) {
public function add_user_to_group($user_id, $group_id) {
access::verify_csrf();
- $group = ORM::factory("group", $group_id);
- $user = ORM::factory("user", $user_id);
+ $group = group::lookup($group_id);
+ $user = user::lookup($user_id);
$group->add($user);
$group->save();
}
public function remove_user_from_group($user_id, $group_id) {
access::verify_csrf();
- $group = ORM::factory("group", $group_id);
- $user = ORM::factory("user", $user_id);
+ $group = group::lookup($group_id);
+ $user = user::lookup($user_id);
$group->remove($user);
$group->save();
}
public function group($group_id) {
$view = new View("admin_users_group.html");
- $view->group = ORM::factory("group", $group_id);
+ $view->group = group::lookup($group_id);
print $view;
}
@@ -193,8 +189,8 @@ public function add_group() {
$valid = $form->validate();
if ($valid) {
$new_name = $form->add_group->inputs["name"]->value;
- $group = ORM::factory("group")->where("name", $new_name)->find();
- if ($group->loaded) {
+ $group = group::lookup_by_name($new_name);
+ if (!empty($group)) {
$form->add_group->inputs["name"]->add_error("in_use", 1);
$valid = false;
}
@@ -219,8 +215,8 @@ public function add_group_form() {
public function delete_group($id) {
access::verify_csrf();
- $group = ORM::factory("group", $id);
- if (!$group->loaded) {
+ $group = group::lookup($id);
+ if (empty($group)) {
kohana::show_404();
}
@@ -240,27 +236,28 @@ public function delete_group($id) {
}
public function delete_group_form($id) {
- $group = ORM::factory("group", $id);
- if (!$group->loaded) {
+ $group = group::lookup($id);
+ if (empty($group)) {
kohana::show_404();
}
+
print group::get_delete_form_admin($group);
}
public function edit_group($id) {
access::verify_csrf();
- $group = ORM::factory("group", $id);
- if (!$group->loaded) {
- kohana::show_404();
+ $group = group::lookup($id);
+ if (empty($group)) {
+ kohana::show_404();
}
$form = group::get_edit_form_admin($group);
$valid = $form->validate();
if ($valid) {
$new_name = $form->edit_group->inputs["name"]->value;
- $group = ORM::factory("group")->where("name", $new_name)->find();
+ $group = group::lookup_by_name($name);
if ($group->loaded) {
$form->edit_group->inputs["name"]->add_error("in_use", 1);
$valid = false;
@@ -282,8 +279,8 @@ public function edit_group($id) {
}
public function edit_group_form($id) {
- $group = ORM::factory("group", $id);
- if (!$group->loaded) {
+ $group = group::lookup($id);
+ if (empty($group)) {
kohana::show_404();
}
View
5 modules/user/controllers/login.php
@@ -53,13 +53,12 @@ public function auth_html() {
print $form;
}
}
-
private function _auth($url) {
$form = user::get_login_form($url);
$valid = $form->validate();
if ($valid) {
- $user = ORM::factory("user")->where("name", $form->login->inputs["name"]->value)->find();
- if (!$user->loaded || !user::is_correct_password($user, $form->login->password->value)) {
+ $user = user::lookup_by_name($form->login->inputs["name"]->value);
+ if (empty($user) || !user::is_correct_password($user, $form->login->password->value)) {
log::warning(
"user",
t("Failed login for %name",
View
15 modules/user/controllers/password.php
@@ -32,10 +32,8 @@ public function do_reset() {
if (request::method() == "post") {
$this->_change_password();
} else {
- $user = ORM::factory("user")
- ->where("hash", Input::instance()->get("key"))
- ->find();
- if ($user->loaded) {
+ $user = user::lookyp_by_hash(Input::instance()->get("key"));
+ if (!empty($user)) {
print $this->_new_password_form($user->hash);
} else {
throw new Exception("@todo FORBIDDEN", 503);
@@ -48,7 +46,7 @@ private function _send_reset() {
$valid = $form->validate();
if ($valid) {
- $user = ORM::factory("user")->where("name", $form->reset->inputs["name"]->value)->find();
+ $user = user::lockup_by_name($form->reset->inputs["name"]->value);
if (!$user->loaded || empty($user->email)) {
$form->reset->inputs["name"]->add_error("no_email", 1);
$valid = false;
@@ -118,11 +116,8 @@ private function _new_password_form($hash=null) {
private function _change_password() {
$view = $this->_new_password_form();
if ($view->content->validate()) {
- $user = ORM::factory("user")
- ->where("hash", $view->content->reset->hash->value)
- ->find();
-
- if (!$user->loaded) {
+ $user = user::lookyp_by_hash(Input::instance()->get("key"));
+ if (empty($user)) {
throw new Exception("@todo FORBIDDEN", 503);
}

0 comments on commit 194cc3b

Please sign in to comment.