summaryrefslogtreecommitdiff
path: root/modules/user/helpers
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-12-25 05:12:46 +0000
committerBharat Mediratta <bharat@menalto.com>2008-12-25 05:12:46 +0000
commitfdc0f83024ee8a10f223132d9e02a9e10466e46a (patch)
tree38dc87629f8063ac3997edbd2a852c318ffb089f /modules/user/helpers
parent6e68c5ca28e52773fca16e77aecdde2b92351af2 (diff)
Big round of normalization of the way that our controllers
communicate. Almost all controllers now use JSON to speak to the theme when we're dealing with form processing. This means tht we only send the form back and forth, but we use a JSON protocol to tell the browser success/error status as well as the location of any newly created resources, or where the browser should redirect the user. Lots of small changes: 1) Admin -> Edit Profile is gone. Instead I fixed the "Modify Profile" link in the top right corner to be a modal dialog 2) We use json_encode everywhere. No more Atom/XML for now. We can bring those back later, though. For now there's a lot of code duplication but that'll be easy to clean up. 3) REST_Controller is no longer abstract. All methods its subclasses should create throw exceptions, which means that subclasses don't have to implement stubs for those methods. 4) New pattern: helper method get_add_form calls take an Item_Model, not an id since we have to load the Item_Model in the controller anyway to check permissions. 5) User/Groups REST resources are separate from User/Group in the site admin. They do different things, we should avoid confusing overlap.
Diffstat (limited to 'modules/user/helpers')
-rw-r--r--modules/user/helpers/group.php26
-rw-r--r--modules/user/helpers/user.php36
-rw-r--r--modules/user/helpers/user_menu.php11
3 files changed, 31 insertions, 42 deletions
diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php
index 673f7d92..a1aea90f 100644
--- a/modules/user/helpers/group.php
+++ b/modules/user/helpers/group.php
@@ -46,50 +46,40 @@ class group_Core {
/**
* The group of all possible visitors. This includes the guest user.
*
- * @todo consider caching
- *
* @return Group_Model
*/
static function everybody() {
- return ORM::factory("group", 1);
+ return model_cache::get("group", 1);
}
/**
* The group of all logged-in visitors. This does not include guest users.
*
- * @todo consider caching
- *
* @return Group_Model
*/
static function registered_users() {
- return ORM::factory("group", 2);
+ return model_cache::get("group", 2);
}
-
- /**
- * This is the API for handling groups.
- * @TODO incorporate rules!
- */
+
public static function get_edit_form($group, $action = NULL) {
$form = new Forge($action);
$form_group = $form->group("edit_group")->label(_("Edit Group"));
- $form_group->input("gname")->label(_("Name"))->id("gName")->value($group->name);
+ $form_group->input("name")->label(_("Name"))->id("gName")->value($group->name);
$form_group->submit(_("Modify"));
$form->add_rules_from($group);
- $form->edit_group->gname->rules($group->rules["name"]);
return $form;
}
-
+
public static function get_add_form($action = NULL) {
$form = new Forge($action);
$form_group = $form->group("add_group")->label(_("Add Group"));
- $form_group->input("gname")->label(_("Name"))->id("gName");
+ $form_group->input("name")->label(_("Name"))->id("gName");
$form_group->submit(_("Create"));
$group = ORM::factory("group");
$form->add_rules_from($group);
- $form->add_group->gname->rules($group->rules["name"]);
return $form;
}
-
+
public static function get_delete_form($group, $action = NULL) {
$form = new Forge($action);
$form_group = $form->group("delete_group")->label(_("Delete Group"));
@@ -97,4 +87,4 @@ class group_Core {
$form_group->submit(_("Delete"));
return $form;
}
-} \ No newline at end of file
+}
diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php
index 34611dbd..83f9ca2b 100644
--- a/modules/user/helpers/user.php
+++ b/modules/user/helpers/user.php
@@ -25,39 +25,50 @@
*/
class user_Core {
public static function get_edit_form($user, $action = NULL) {
- $form = new Forge($action, "", "post", array("id" => "gUserForm"));
+ $form = new Forge("users/$user->id?_method=put", "", "post", array("id" => "gUserForm"));
$group = $form->group("edit_user")->label(_("Edit User"));
- $group->input("uname")->label(_("Name"))->id("gName")->value($user->name);
+ $group->input("name")->label(_("Name"))->id("gName")->value($user->name);
$group->input("full_name")->label(_("Full Name"))->id("gFullName")->value($user->full_name);
$group->password("password")->label(_("Password"))->id("gPassword");
$group->input("email")->label(_("Email"))->id("gEmail")->value($user->email);
$group->submit(_("Modify"));
$form->add_rules_from($user);
- $form->edit_user->uname->rules($user->rules["name"]);
return $form;
}
- public static function get_add_form($action = NULL) {
- $form = new Forge($action);
+ public static function get_edit_form_admin($user, $action = NULL) {
+ $form = new Forge("admin/users/edit/$user->id", "", "post", array("id" => "gUserForm"));
+ $group = $form->group("edit_user")->label(_("Edit User"));
+ $group->input("name")->label(_("Name"))->id("gName")->value($user->name);
+ $group->input("full_name")->label(_("Full Name"))->id("gFullName")->value($user->full_name);
+ $group->password("password")->label(_("Password"))->id("gPassword");
+ $group->input("email")->label(_("Email"))->id("gEmail")->value($user->email);
+ $group->submit(_("Modify"));
+ $form->add_rules_from($user);
+ return $form;
+ }
+
+ public static function get_add_form_admin($action = NULL) {
+ $form = new Forge("admin/users/create");
$group = $form->group("add_user")->label(_("Add User"));
- $group->input("uname")->label(_("Name"))->id("gName");
+ $group->input("name")->label(_("Name"))->id("gName");
$group->input("full_name")->label(_("Full Name"))->id("gFullName");
$group->password("password")->label(_("Password"))->id("gPassword");
$group->input("email")->label(_("Email"))->id("gEmail");
$group->submit(_("Add"));
$user = ORM::factory("user");
$form->add_rules_from($user);
- $form->add_user->uname->rules($user->rules["name"]);
return $form;
}
-
- public static function get_delete_form($user, $action = NULL) {
+
+ public static function get_delete_form_admin($user, $action = NULL) {
$form = new Forge($action);
$group = $form->group("delete_user")->label(_("Delete User"));
$group->label(sprintf(_("Are you sure you want to delete %s?"), $user->name));
$group->submit(_("Delete"));
return $form;
}
+
/**
* Make sure that we have a session and group_ids cached in the session.
*/
@@ -145,10 +156,9 @@ class user_Core {
$user->full_name = $full_name;
$user->password = $password;
- // Everybody group
- $user->add(ORM::factory("group", 1));
- // Registered Users group
- $user->add(ORM::factory("group", 2));
+ // Required groups
+ $user->add(group::everybody());
+ $user->add(group::registered_users());
$user->save();
module::event("user_created", $user);
diff --git a/modules/user/helpers/user_menu.php b/modules/user/helpers/user_menu.php
index 654a0d89..88f30f29 100644
--- a/modules/user/helpers/user_menu.php
+++ b/modules/user/helpers/user_menu.php
@@ -18,17 +18,6 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class user_menu_Core {
- public static function site($menu, $theme) {
- $user = user::active();
- if (!$user->guest) {
- $menu->get("admin_menu")->append(
- Menu::Factory("dialog")
- ->id("edit_profile")
- ->label(_("Edit Profile"))
- ->url(url::site("users/form/edit/$user->id")));
- }
- }
-
public static function admin($menu, $theme) {
$menu->get("users_groups_menu")
->append(Menu::factory("link")