Fix for ticket #1176. Have the gallery.dialog code add a g-in-dialog parameter to the url to let the controller know its in a dialog. The reauthenticate controller will format the password prompt as a page or a form content. If authentication is successful, then the original controller is called instead of being redirected to.

This commit is contained in:
Tim Almdal
2010-07-07 08:58:38 -07:00
parent cb4e18f9dd
commit 9538b3888d
3 changed files with 50 additions and 6 deletions

View File

@@ -22,7 +22,12 @@ class Reauthenticate_Controller extends Controller {
if (!identity::active_user()->admin) {
access::forbidden();
}
return self::_show_form(self::_form());
$reauthenticate = Session::instance()->get("reauthenticate", array());
if (empty($reauthenticate["in_dialog"])) {
self::_show_form(self::_form());
} else {
print json_encode(array("form" => (string) self::_form()));
}
}
public function auth() {
@@ -31,18 +36,30 @@ class Reauthenticate_Controller extends Controller {
}
access::verify_csrf();
$reauthenticate = Session::instance()->get("reauthenticate", array());
Kohana_Log::add("error", Kohana::debug($reauthenticate));
$form = self::_form();
$valid = $form->validate();
$user = identity::active_user();
if ($valid) {
message::success(t("Successfully re-authenticated!"));
module::event("user_auth", $user);
url::redirect($form->continue_url->value);
Session::instance()->delete("reauthenticate");
if (empty($reauthenticate["in_dialog"])) {
url::redirect($reauthenticate["continue_url"]);
} else {
self::_call_admin_function($reauthenticate);
}
} else {
$name = $user->name;
log::warning("user", t("Failed re-authentication for %name", array("name" => $name)));
module::event("user_auth_failed", $name);
return self::_show_form($form);
if (empty($reauthenticate["in_dialog"])) {
self::_show_form($form);
} else {
print json_encode(array("form" => (string) $form));
}
}
}
@@ -52,6 +69,7 @@ class Reauthenticate_Controller extends Controller {
$view->content = new View("reauthenticate.html");
$view->content->form = $form;
$view->content->user_name = identity::active_user()->name;
print $view;
}
@@ -70,4 +88,25 @@ class Reauthenticate_Controller extends Controller {
$group->submit("")->value(t("Submit"));
return $form;
}
private static function _call_admin_function($reauthenticate) {
$controller_name = $reauthenticate["controller"];
$args = $reauthenticate["args"];
if ($controller_name == "index") {
$controller_name = "dashboard";
}
$controller_name = "Admin_{$controller_name}_Controller";
if ($args) {
$method = array_shift($args);
} else {
$method = "index";
}
if (!method_exists($controller_name, $method)) {
throw new Kohana_404_Exception();
}
call_user_func_array(array(new $controller_name, $method), $args);
}
}