From 2af48060117bdf30fb48929dd8c9d22800a70843 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 13 Oct 2009 13:19:17 -0700 Subject: Refactor the ui component of the user module into the gallery core module. --- modules/gallery/controllers/users.php | 68 +++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 modules/gallery/controllers/users.php (limited to 'modules/gallery/controllers/users.php') diff --git a/modules/gallery/controllers/users.php b/modules/gallery/controllers/users.php new file mode 100644 index 00000000..07c5a457 --- /dev/null +++ b/modules/gallery/controllers/users.php @@ -0,0 +1,68 @@ +guest || $user->id != user::active()->id) { + access::forbidden(); + } + + $form = user::get_edit_form($user); + $valid = $form->validate(); + if ($valid) { + $user->full_name = $form->edit_user->full_name->value; + if ($form->edit_user->password->value) { + $user->password = $form->edit_user->password->value; + } + $user->email = $form->edit_user->email->value; + $user->url = $form->edit_user->url->value; + if ($form->edit_user->locale) { + $desired_locale = $form->edit_user->locale->value; + $new_locale = $desired_locale == "none" ? null : $desired_locale; + if ($new_locale != $user->locale) { + // Delete the session based locale preference + setcookie("g_locale", "", time() - 24 * 3600, "/"); + } + $user->locale = $new_locale; + } + $user->save(); + module::event("user_edit_form_completed", $user, $form); + + message::success(t("User information updated.")); + print json_encode( + array("result" => "success", + "resource" => url::site("users/{$user->id}"))); + } else { + print json_encode( + array("result" => "error", + "form" => $form->__toString())); + } + } + + public function form_edit($id) { + $user = user::lookup($id); + if ($user->guest || $user->id != user::active()->id) { + access::forbidden(); + } + + print user::get_edit_form($user); + } +} -- cgit v1.2.3