From 48cb5021c6bd7e65a13a0ff50a9e76f72da7d3a1 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 1 Feb 2010 16:28:52 -0800 Subject: Add the scheduler component to the admin maintenance screen. --- modules/gallery/views/admin_maintenance.html.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'modules/gallery/views') diff --git a/modules/gallery/views/admin_maintenance.html.php b/modules/gallery/views/admin_maintenance.html.php index ac597715..15d04caa 100644 --- a/modules/gallery/views/admin_maintenance.html.php +++ b/modules/gallery/views/admin_maintenance.html.php @@ -33,12 +33,20 @@ class="g-dialog-link g-button ui-icon-left ui-state-default ui-corner-all"> + + callback?csrf=$csrf") ?>" + class="g-dialog-link g-button ui-icon-left ui-state-default ui-corner-all"> + + + + + count()): ?>

-- cgit v1.2.3 From 370faf5f265e634b0828be9695cd6eb9676ff6f7 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 2 Feb 2010 10:55:22 -0800 Subject: Display the error message for the in place edit. Also improve the double click guard. Fixes ticket #1000. --- lib/gallery.in_place_edit.js | 44 ++++++++++++---------------- modules/gallery/views/in_place_edit.html.php | 6 ++++ 2 files changed, 24 insertions(+), 26 deletions(-) (limited to 'modules/gallery/views') diff --git a/lib/gallery.in_place_edit.js b/lib/gallery.in_place_edit.js index c10400e3..5a815dac 100644 --- a/lib/gallery.in_place_edit.js +++ b/lib/gallery.in_place_edit.js @@ -10,10 +10,10 @@ }, _show: function(target) { - if ($(this).data("gallery_in_place_edit") == true) { + if ($(target).data("gallery_in_place_edit") == true) { return; } - $(this).data("gallery_in_place_edit", true); + $(target).data("gallery_in_place_edit", true); var self = this; var tag_width = $(target).width(); $(self).data("tag_width", tag_width); @@ -27,26 +27,28 @@ var parent = $(target).parent(); parent.children().hide(); parent.append(data); - parent.find("form :text") - .width(tag_width) - .focus(); - $(".g-short-form").gallery_short_form(); - parent.find("form .g-cancel").click(function(event) { - self._cancel(); - event.preventDefault(); - return false; - }); - self._ajaxify_edit(); + self._setup_form(parent.find("form")); }); + }, + _setup_form: function(form) { + var self = this; + var width = $(self).data("tag_width"); + form.find(":text").width(width).focus(); + form.find(".g-cancel").click(function(event) { + self._cancel(); + event.preventDefault(); + return false; + }); + $(".g-short-form").gallery_short_form(); + this._ajaxify_edit(); }, _cancel: function() { var parent = $("#g-in-place-edit-form").parent(); - $(parent).find("form").remove(); + $("#g-in-place-edit-form").remove(); $(parent).children().show(); - $("#g-in-place-edit-message").remove(); - $(this).data("gallery_in_place_edit", false); + $(parent).find(".g-editable").data("gallery_in_place_edit", false); }, _ajaxify_edit: function() { @@ -60,17 +62,7 @@ } else { var parent = $(form).parent(); $(form).replaceWith(data.form); - var width = $(self).data("tag_width"); - $(parent).find("form :text") - .width(width) - .focus(); - $(".g-short-form").gallery_short_form(); - $(parent).find("form .g-cancel").click(function(event) { - self._cancel(); - event.preventDefault(); - return false; - }); - self._ajaxify_edit(); + self._setup_form(parent.find("form")); } } }); diff --git a/modules/gallery/views/in_place_edit.html.php b/modules/gallery/views/in_place_edit.html.php index 05a16ad4..2d6cbe90 100644 --- a/modules/gallery/views/in_place_edit.html.php +++ b/modules/gallery/views/in_place_edit.html.php @@ -9,7 +9,13 @@ "submit ui-state-default"), t("Save")) ?>
  • + +
  • +

    +
  • + + -- cgit v1.2.3 From fe11e34cea8ea31c048af5f38d63220850b0293d Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 2 Feb 2010 11:42:13 -0800 Subject: Change the view to display 'empty' when the variable value is a null string(""). Fixes ticket #987. --- modules/gallery/views/admin_advanced_settings.html.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'modules/gallery/views') diff --git a/modules/gallery/views/admin_advanced_settings.html.php b/modules/gallery/views/admin_advanced_settings.html.php index 2d4b11a1..1f7d2f64 100644 --- a/modules/gallery/views/admin_advanced_settings.html.php +++ b/modules/gallery/views/admin_advanced_settings.html.php @@ -25,10 +25,10 @@ module_name/" . html::clean($var->name)) ?>" class="g-dialog-link" title=" $var->name, "module_name" => $var->module_name))->for_html_attr() ?>"> - value)): ?> - value) ?> - + value) || $var->value === ""): ?> + + value) ?> -- cgit v1.2.3 From 19fee6b5e4ceb8a5f90cafe4ad770856ece108ef Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 2 Feb 2010 14:34:50 -0800 Subject: Refactor the admin maintenance screen so that events are used to pupluate the action buttons and other content such as the list of scheduled tasks. --- modules/gallery/controllers/admin_maintenance.php | 11 +++++++++-- modules/gallery/views/admin_maintenance.html.php | 16 +++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'modules/gallery/views') diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index 487e77a6..8e4845a9 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -44,10 +44,17 @@ class Admin_Maintenance_Controller extends Admin_Controller { $view->content->task_definitions = task::get_definitions(); $view->content->running_tasks = ORM::factory("task") ->where("done", "=", 0)->order_by("updated", "DESC")->find_all(); - $view->content->schedule_definitions = - module::is_active("scheduler") ? scheduler::get_definitions() : ""; $view->content->finished_tasks = ORM::factory("task") ->where("done", "=", 1)->order_by("updated", "DESC")->find_all(); + $task_buttons = + new ArrayObject(array((object)array("text" => t("run"), + "url" =>url::site("admin/maintenance/start")))); + module::event("admin_maintenance_task_buttons", $task_buttons); + $view->content->task_buttons = $task_buttons; + + $maintenance_content = new ArrayObject(); + module::event("admin_maintenance_content", $maintenance_content); + $view->content->task_maintenance_content = $maintenance_content; print $view; } diff --git a/modules/gallery/views/admin_maintenance.html.php b/modules/gallery/views/admin_maintenance.html.php index 15d04caa..444bf1fe 100644 --- a/modules/gallery/views/admin_maintenance.html.php +++ b/modules/gallery/views/admin_maintenance.html.php @@ -29,23 +29,21 @@ description ?> - callback?csrf=$csrf") ?>" + + url}/$task->callback?csrf=$csrf" ?>" class="g-dialog-link g-button ui-icon-left ui-state-default ui-corner-all"> - + text) ?> - - callback?csrf=$csrf") ?>" - class="g-dialog-link g-button ui-icon-left ui-state-default ui-corner-all"> - - - +
    - + + + count()): ?>
    -- cgit v1.2.3 From 1c0e5eaa0d9b65863c9fd04aff940c1a2b7e682d Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 2 Feb 2010 15:00:05 -0800 Subject: use html::purify to cleans the additional content on the admin maintence page. --- modules/gallery/tests/xss_data.txt | 1 - modules/gallery/views/admin_maintenance.html.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'modules/gallery/views') diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index 8d7236fa..e53502ee 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -82,7 +82,6 @@ modules/gallery/views/admin_maintenance.html.php 25 DIRTY_ATTR log: modules/gallery/views/admin_maintenance.html.php 26 DIRTY $task->name modules/gallery/views/admin_maintenance.html.php 29 DIRTY $task->description modules/gallery/views/admin_maintenance.html.php 33 DIRTY_JS "{$button->url}/$task->callback?csrf=$csrf" -modules/gallery/views/admin_maintenance.html.php 45 DIRTY $content modules/gallery/views/admin_maintenance.html.php 76 DIRTY_ATTR text::alternate("g-odd","g-even") modules/gallery/views/admin_maintenance.html.php 76 DIRTY_ATTR $task->state=="stalled"?"g-warning":"" modules/gallery/views/admin_maintenance.html.php 77 DIRTY_ATTR $task->state=="stalled"?"g-warning":"" diff --git a/modules/gallery/views/admin_maintenance.html.php b/modules/gallery/views/admin_maintenance.html.php index 444bf1fe..19375670 100644 --- a/modules/gallery/views/admin_maintenance.html.php +++ b/modules/gallery/views/admin_maintenance.html.php @@ -42,7 +42,7 @@
    - + count()): ?> -- cgit v1.2.3 From 6e1b761b12e13566875804c33efe2ae130ffa32e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 2 Feb 2010 21:36:01 -0800 Subject: Require the current password to change your password. Fixes ticket #585. Separate out the password change form from the regular edit user form. Require the old password to enter a new one. While I'm at it, roll the password strength javascript into a Form_Script element so that we can get rid of the old view (which incidentally fixes a bug where the password strength meter would go away on form errors). --- modules/gallery/views/user_profile.html.php | 7 ++- modules/user/controllers/users.php | 78 +++++++++++++++++++++++------ modules/user/helpers/user.php | 6 +++ modules/user/views/user_form.html.php | 7 --- 4 files changed, 75 insertions(+), 23 deletions(-) delete mode 100644 modules/user/views/user_form.html.php (limited to 'modules/gallery/views') diff --git a/modules/gallery/views/user_profile.html.php b/modules/gallery/views/user_profile.html.php index f35f8c3f..78e1c579 100644 --- a/modules/gallery/views/user_profile.html.php +++ b/modules/gallery/views/user_profile.html.php @@ -57,13 +57,16 @@ - id}") ?>"> + id}") ?>"> + id}") ?>"> + + - \ No newline at end of file + diff --git a/modules/user/controllers/users.php b/modules/user/controllers/users.php index 43a92b44..c11f22ff 100644 --- a/modules/user/controllers/users.php +++ b/modules/user/controllers/users.php @@ -20,7 +20,6 @@ class Users_Controller extends Controller { public function update($id) { $user = user::lookup($id); - if ($user->guest || $user->id != identity::active_user()->id) { access::forbidden(); } @@ -29,9 +28,6 @@ class Users_Controller extends Controller { try { $valid = $form->validate(); $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; @@ -57,7 +53,38 @@ class Users_Controller extends Controller { $user->save(); module::event("user_edit_form_completed", $user, $form); - message::success(t("User information updated.")); + 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" => (string) $form)); + } + } + + public function change_password($id) { + $user = user::lookup($id); + if ($user->guest || $user->id != identity::active_user()->id) { + access::forbidden(); + } + + $form = $this->_get_change_password_form($user); + try { + $valid = $form->validate(); + $user->password = $form->change_password->password->value; + $user->validate(); + } catch (ORM_Validation_Exception $e) { + // Translate ORM validation errors into form error messages + foreach ($e->validation->errors() as $key => $error) { + $form->change_password->inputs[$key]->add_error($error, 1); + } + $valid = false; + } + + if ($valid) { + $user->save(); + module::event("user_change_password_form_completed", $user, $form); + message::success(t("Password changed")); print json_encode( array("result" => "success", "resource" => url::site("users/{$user->id}"))); @@ -72,22 +99,45 @@ class Users_Controller extends Controller { access::forbidden(); } - $v = new View("user_form.html"); - $v->form = $this->_get_edit_form($user); - print $v; + print $this->_get_edit_form($user); + } + + public function form_change_password($id) { + $user = user::lookup($id); + if ($user->guest || $user->id != identity::active_user()->id) { + access::forbidden(); + } + + print $this->_get_change_password_form($user); + } + + private function _get_change_password_form($user) { + $form = new Forge( + "users/change_password/$user->id", "", "post", array("id" => "g-change-password-user-form")); + $group = $form->group("change_password")->label(t("Change your password")); + $group->password("old_password")->label(t("Old password"))->id("g-password") + ->callback("user::valid_password") + ->error_messages("invalid", t("Incorrect password")); + $group->password("password")->label(t("New password"))->id("g-password") + ->error_messages("min_length", t("Your new password is too short")); + $group->script("") + ->text( + '$("form").ready(function(){$(\'input[name="password"]\').user_password_strength();});'); + $group->password("password2")->label(t("Confirm new password"))->id("g-password2") + ->matches($group->password) + ->error_messages("matches", t("The passwords you entered do not match")); + + module::event("user_change_password_form", $user, $form); + $group->submit("")->value(t("Save")); + return $form; } private function _get_edit_form($user) { $form = new Forge("users/update/$user->id", "", "post", array("id" => "g-edit-user-form")); - $group = $form->group("edit_user")->label(t("Edit User: %name", array("name" => $user->name))); + $group = $form->group("edit_user")->label(t("Edit your profile")); $group->input("full_name")->label(t("Full Name"))->id("g-fullname")->value($user->full_name) ->error_messages("length", t("Your name is too long")); self::_add_locale_dropdown($group, $user); - $group->password("password")->label(t("Password"))->id("g-password") - ->error_messages("min_length", t("Your password is too short")); - $group->password("password2")->label(t("Confirm Password"))->id("g-password2") - ->matches($group->password) - ->error_messages("matches", t("The passwords you entered do not match")); $group->input("email")->label(t("Email"))->id("g-email")->value($user->email) ->error_messages("email", t("You must enter a valid email address")) ->error_messages("length", t("Your email address is too long")) diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php index 3561021f..7ceca6a5 100644 --- a/modules/user/helpers/user.php +++ b/modules/user/helpers/user.php @@ -70,6 +70,12 @@ class user_Core { return false; } + static function valid_password($password_input) { + if (!user::is_correct_password(identity::active_user(), $password_input->value)) { + $password_input->add_error("invalid", 1); + } + } + /** * Create the hashed passwords. * @param string $password a plaintext password diff --git a/modules/user/views/user_form.html.php b/modules/user/views/user_form.html.php deleted file mode 100644 index 4ce2b532..00000000 --- a/modules/user/views/user_form.html.php +++ /dev/null @@ -1,7 +0,0 @@ - - - -- cgit v1.2.3