summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-11-15 08:15:00 +0000
committerBharat Mediratta <bharat@menalto.com>2008-11-15 08:15:00 +0000
commit9d1a598ec0826b0e8c3b6fc0ff64863f5dde7edc (patch)
tree5235cdef37003a27a91b1bc40a553adf703f2564
parentae7839ffaada72c522ffcd9b3f4f1cc04027a720 (diff)
Add support for modifying user data. It still needs work.
Make the continue= param a GET only parameter so that it's not part of the form.
-rw-r--r--modules/user/controllers/login.php8
-rw-r--r--modules/user/controllers/user.php22
-rw-r--r--themes/default/views/header.html.php2
3 files changed, 15 insertions, 17 deletions
diff --git a/modules/user/controllers/login.php b/modules/user/controllers/login.php
index a0e9f403..586c9fa7 100644
--- a/modules/user/controllers/login.php
+++ b/modules/user/controllers/login.php
@@ -19,12 +19,11 @@
*/
class Login_Controller extends Controller {
public function index() {
- $form = new Forge("login", "", "post", array("id" => "gLogin"));
+ $form = new Forge(url::current(true), "", "post", array("id" => "gLogin"));
$group = $form->group(_("Login"));
$group->input("name")->label(_("Name"))->id("gName")->class(null);
$group->password("password")->label(_("Password"))->id("gPassword")->class(null);
$group->submit(_("Login"));
- $form->hidden("continue")->value($this->input->get("continue"));
$group->inputs["name"]->error_messages("invalid_login", _("Invalid name or password"));
if ($form->validate()) {
@@ -32,9 +31,8 @@ class Login_Controller extends Controller {
if ($user->loaded &&
user::is_correct_password($user, $group->password->value)) {
user::login($user);
- $continue = $form->hidden["continue"]->value;
- if ($continue) {
- url::redirect($form->hidden["continue"]->value);
+ if ($continue = $this->input->get("continue")) {
+ url::redirect($continue);
}
return;
} else {
diff --git a/modules/user/controllers/user.php b/modules/user/controllers/user.php
index a1085ae5..d3370dbe 100644
--- a/modules/user/controllers/user.php
+++ b/modules/user/controllers/user.php
@@ -24,7 +24,7 @@ class User_Controller extends REST_Controller {
* Return the form for creating / modifying users.
*/
private function _get_form($user) {
- $form = new Forge("user/{$user->id}", "", "post", array("id" => "gUser"));
+ $form = new Forge(url::current(true), "", "post", array("id" => "gUser"));
$group = $form->group(_("User Info"));
$group->input("name")
->label(_("Name"))
@@ -46,7 +46,6 @@ class User_Controller extends REST_Controller {
->class(null)
->value($user->email);
$group->submit(_("Modify"));
- $form->hidden("continue")->value($this->input->get("continue"));
$this->_add_validation_rules(ORM::factory("user")->validation_rules, $form);
@@ -72,7 +71,7 @@ class User_Controller extends REST_Controller {
*/
public function _get($user) {
$form = $this->_get_form($user);
- print $form->render("form.html", false);
+ print $form->render("form.html");
}
/**
@@ -88,15 +87,16 @@ class User_Controller extends REST_Controller {
public function _post($user) {
$form = $this->_get_form($user);
if ($form->validate()) {
- // @todo if we use the Validation class here, the ORM can just read the inputs directly. We
- // need to investigate that.
- //
- // @todo
- // Verify the user input, store it in the object.
- // Show errors on validation failure.
- // On success, redirect if there's a form->continue, else show an empty page.
+ foreach ($form->as_array() as $key => $value) {
+ $user->$key = $value;
+ }
+ $user->save();
+ if ($continue = $this->input->get("continue")) {
+ url::redirect($continue);
+ }
+ return;
}
- throw new Exception("@todo User_Controller::_post NOT IMPLEMENTED");
+ print $form->render("form.html");
}
/**
diff --git a/themes/default/views/header.html.php b/themes/default/views/header.html.php
index 8cba82ba..112da0db 100644
--- a/themes/default/views/header.html.php
+++ b/themes/default/views/header.html.php
@@ -4,7 +4,7 @@
<ul id="gLoginMenu">
<? if ($user): ?>
- <a href="<?= url::site("user/update")?>"><?= _("Modify Profile") ?></a>
+ <a href="<?= url::site("user/{$user->id}?continue=" . url::current(true))?>"><?= _("Modify Profile") ?></a>
| <a href="<?= url::site("logout?continue=" . url::current(true)) ?>" id="gLogoutLink">
<?= _("Logout") ?>
</a>