diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-03-16 04:33:45 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-03-16 04:33:45 +0000 |
commit | 736d74d05f70be5b72e44eafe2cc8efae52b0af7 (patch) | |
tree | 31cda57354967ecb717026f3f631daaa54801aec | |
parent | cbc7c870fa8b54c2c320fedaf02b5b6010c55277 (diff) |
Clean up the login, maintenance login and required-top-level-login code.
We now have two clear and separate login approaches:
login/ajax
login/html
Choose the one that's appropriate. Totally simplified the maintenance
page to be separate from the theme and dead simple, and use login/html
approach there. Totally simplified the top level login
(login_page.html.php) to just be a login page, not the rest of the
chrome on the page and use the login/ajax approach there.
Don't use access::required in albums and then catch the exception,
instead use access::can and check the return code.
Improve the text for maintenance mode.
-rw-r--r-- | core/controllers/albums.php | 11 | ||||
-rw-r--r-- | core/controllers/maintenance.php | 10 | ||||
-rw-r--r-- | core/libraries/Theme_View.php | 10 | ||||
-rw-r--r-- | core/views/maintenance.html.php | 49 | ||||
-rw-r--r-- | modules/user/controllers/login.php | 58 | ||||
-rw-r--r-- | modules/user/helpers/user.php | 10 | ||||
-rw-r--r-- | modules/user/views/login.html.php | 2 | ||||
-rw-r--r-- | modules/user/views/login_prompt.html.php | 44 | ||||
-rw-r--r-- | themes/default/views/login_page.html.php | 24 | ||||
-rw-r--r-- | themes/default/views/maintenance.html.php | 56 |
10 files changed, 101 insertions, 173 deletions
diff --git a/core/controllers/albums.php b/core/controllers/albums.php index 9811ba13..bcfdd8c2 100644 --- a/core/controllers/albums.php +++ b/core/controllers/albums.php @@ -23,13 +23,12 @@ class Albums_Controller extends Items_Controller { * @see REST_Controller::_show($resource) */ public function _show($album) { - try { - access::required("view", $album); - } catch (Exception $e) { + if (!access::can("view", $album)) { if ($album->id != 1) { - throw $e; + access::forbidden(); } else { - url::redirect("login/page"); + print new Theme_View("login_page.html"); + return; } } @@ -163,7 +162,7 @@ class Albums_Controller extends Items_Controller { $album->description = $form->edit_album->description->value; $album->sort_column = $form->edit_album->sort_order->column->value; $album->sort_order = $form->edit_album->sort_order->direction->value; - + $album->save(); module::event("item_updated", $orig, $album); diff --git a/core/controllers/maintenance.php b/core/controllers/maintenance.php index 908e90b5..32295a45 100644 --- a/core/controllers/maintenance.php +++ b/core/controllers/maintenance.php @@ -19,12 +19,6 @@ */ class Maintenance_Controller extends Controller { function index() { - $album = ORM::factory("item", 1); - $v = new Theme_View("maintenance.html", "reset"); - $v->title = t("%title Unavailable", array("title" => $album->title)); - $v->content = t("%title is currently unavailable as it is undergoing maintenance", - array("title" => $album->title)); - - print $v; - } + print new View("maintenance.html"); + } }
\ No newline at end of file diff --git a/core/libraries/Theme_View.php b/core/libraries/Theme_View.php index ecae3946..797679fd 100644 --- a/core/libraries/Theme_View.php +++ b/core/libraries/Theme_View.php @@ -36,15 +36,13 @@ class Theme_View_Core extends View { if (user::active()->admin) { $this->theme_name = Input::instance()->get("theme", $this->theme_name); } - $this->set_global('theme', $this); - $this->set_global('user', user::active()); + $this->set_global("theme", $this); + $this->set_global("user", user::active()); $this->set_global("page_type", $page_type); $maintenance_mode = Kohana::config("core.maintenance_mode", false, false); - if (!empty($maintenance_mode)) { - $album = ORM::factory("item", 1); - message::warning(t("%title is currently unavailable as it is undergoing maintenance", - array("title" => $album->title))); + if ($maintenance_mode) { + message::warning(t("This site is currently in maintenance mode")); } } diff --git a/core/views/maintenance.html.php b/core/views/maintenance.html.php new file mode 100644 index 00000000..d970233d --- /dev/null +++ b/core/views/maintenance.html.php @@ -0,0 +1,49 @@ +<html> + <head> + <title> + <?= t("Gallery - Maintenance Mode") ?> + </title> + <style> + body { + background: #ccc; + } + form { + border: 1px solid #555; + background: #999; + width: 300px; + } + fieldset { + border: none; + } + fieldset legend { + font-size: 24px; + display: none !important; + padding-left: 0px; + } + ul { + list-style-type: none; + margin-top: 0px; + padding-left: 0px; + bullet-style: none; + } + ul li { + margin-left: 0px; + } + label { + width: 60px; + display: block; + } + </style> + </head> + <body> + <h1> + <?= t("Gallery - Maintenance Mode") ?> + </h1> + <p> + <?= t("This site is currently only accessible by site administrators.") ?> + </p> + <?= user::get_login_form("login/auth_html") ?> + </body> +</html> + + diff --git a/modules/user/controllers/login.php b/modules/user/controllers/login.php index 62420ab1..12301ce5 100644 --- a/modules/user/controllers/login.php +++ b/modules/user/controllers/login.php @@ -18,23 +18,41 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Login_Controller extends Controller { - public function index() { - if (request::method() == "post") { - $this->_try_login(); + + public function ajax() { + $view = new View("login_ajax.html"); + $view->form = user::get_login_form("login/auth_ajax"); + print $view; + } + + public function auth_ajax() { + list ($valid, $form) = $this->_auth(); + if ($valid) { + print json_encode( + array("result" => "success", + "location" => url::site(""))); } else { - print $this->_login_form(); + print json_encode( + array("result" => "error", + "form" => $form->__toString())); } } - public function page() { - $view = new Theme_View("login_page.html"); - $view->page_type = "login"; - print $view; + public function html() { + print user::get_login_form("login/auth_html"); } - private function _try_login() { - $form = $this->_login_form()->form; + public function auth_html() { + list ($valid, $form) = $this->_auth(); + if ($valid) { + url::redirect("albums/1"); + } else { + print $form; + } + } + private function _auth() { + $form = user::get_login_form(); $valid = $form->validate(); if ($valid) { $user = ORM::factory("user")->where("name", $form->login->inputs["name"]->value)->find(); @@ -49,26 +67,8 @@ class Login_Controller extends Controller { if ($valid) { user::login($user); log::info("user", t("User %name logged in", array("name" => $user->name))); - print json_encode( - array("result" => "success", - "location" => url::site(""))); - } else { - print json_encode( - array("result" => "error", - "form" => $form->__toString())); } - } - - private function _login_form() { - $view = new View("login_prompt.html"); - - $view->form = new Forge(url::current(true), "", "post", array("id" => "gLoginForm")); - $group = $view->form->group("login")->label(t("Login")); - $group->input("name")->label(t("Name"))->id("gName")->class(null); - $group->password("password")->label(t("Password"))->id("gPassword")->class(null); - $group->inputs["name"]->error_messages("invalid_login", t("Invalid name or password")); - $group->submit("")->value(t("Login")); - return $view; + return array($valid, $form); } }
\ No newline at end of file diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php index a15fa463..dbb9b613 100644 --- a/modules/user/helpers/user.php +++ b/modules/user/helpers/user.php @@ -99,6 +99,16 @@ class user_Core { return $form; } + static function get_login_form($url) { + $form = new Forge($url, "", "post", array("id" => "gLoginForm")); + $group = $form->group("login")->label(t("Login")); + $group->input("name")->label(t("Name"))->id("gName")->class(null); + $group->password("password")->label(t("Password"))->id("gPassword")->class(null); + $group->inputs["name"]->error_messages("invalid_login", t("Invalid name or password")); + $group->submit("")->value(t("Login")); + return $form; + } + /** * Make sure that we have a session and group_ids cached in the session. */ diff --git a/modules/user/views/login.html.php b/modules/user/views/login.html.php index d06f2a45..27373f02 100644 --- a/modules/user/views/login.html.php +++ b/modules/user/views/login.html.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> <ul id="gLoginMenu"> <? if ($user->guest): ?> - <li class="first"><a href="<?= url::site("login") ?>" + <li class="first"><a href="<?= url::site("login/ajax") ?>" title="<?= t("Login to Gallery") ?>" id="gLoginLink"><?= t("Login") ?></a></li> <? else: ?> diff --git a/modules/user/views/login_prompt.html.php b/modules/user/views/login_prompt.html.php deleted file mode 100644 index 56a6f111..00000000 --- a/modules/user/views/login_prompt.html.php +++ /dev/null @@ -1,44 +0,0 @@ -<?php defined("SYSPATH") or die("No direct script access.") ?> -<script type="text/javascript"> - $("#gLoginForm").ready(function() { - $("#gForgotPasswordLink").click(function() { - $.ajax({ - url: "<?= url::site("password/reset") ?>", - success: function(data) { - $("div#gLoginView").html(data); - $("#ui-dialog-title-gDialog").text("<?= t("Reset Password") ?>"); - ajaxify_login_reset_form(); - } - }); - }); - }); - - function ajaxify_login_reset_form() { - $("#gLoginView form").ajaxForm({ - dataType: "json", - success: function(data) { - if (data.form) { - $("#gLoginView form").replaceWith(data.form); - ajaxify_login_reset_form(); - } - if (data.result == "success") { - $("#gDialog").dialog("close"); - window.location.reload(); - } - - } - }); - }; -</script> -<div id="gLoginView"> - <ul> - <li> - <div id="gLoginViewForm"> - <?= $form ?> - </div> - </li> - <li> - <a href="#" id="gForgotPasswordLink"><?= t("Forgot your Password?") ?></a> - </li> - </ul> -</div> diff --git a/themes/default/views/login_page.html.php b/themes/default/views/login_page.html.php index ffe1762b..1bd76c18 100644 --- a/themes/default/views/login_page.html.php +++ b/themes/default/views/login_page.html.php @@ -26,7 +26,6 @@ <script src="<?= url::file("lib/gallery.dialog.js") ?>" type="text/javascript"></script> <script src="<?= url::file("lib/superfish/js/superfish.js") ?>" type="text/javascript"></script> <script src="<?= $theme->url("js/ui.init.js") ?>" type="text/javascript"></script> - <?= $theme->head() ?> <script> $("#gLoginLink").ready(function() { $("#gLoginLink").click(); @@ -35,27 +34,6 @@ </head> <body> - <?= $theme->page_top() ?> - <div id="doc4" class="yui-t5 gView"> - <div id="hd"> - <div id="gHeader"> - <?= $theme->display("header.html") ?> - </div> - </div> - <div id="bd"> - <div id="yui-main"> - <div class="yui-b"> - <div id="gContent" class="yui-g"> </div> - </div> - </div> - <div id="gSidebar" class="yui-b"> </div> - </div> - <div id="ft"> - <div id="gFooter"> - <?= $theme->display("footer.html") ?> - </div> - </div> - </div> - <?= $theme->page_bottom() ?> + <a id="gLoginLink" href="<?= url::site("login/ajax") ?>">Log in</a> </body> </html> diff --git a/themes/default/views/maintenance.html.php b/themes/default/views/maintenance.html.php deleted file mode 100644 index fde3973d..00000000 --- a/themes/default/views/maintenance.html.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php defined("SYSPATH") or die("No direct script access.") ?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tranisitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> - <head> - <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> - <title><?= $title ?></title> - <link rel="shortcut icon" href="<?= $theme->url("images/favicon.ico") ?>" type="image/x-icon" /> - <link rel="stylesheet" type="text/css" href="<?= url::file("lib/yui/reset-fonts-grids.css") ?>" - media="screen,print,projection" /> - <link rel="stylesheet" type="text/css" href="<?= url::file("lib/superfish/css/superfish.css") ?>" - media="screen" /> - <link rel="stylesheet" type="text/css" href="<?= url::file("lib/themeroller/ui.base.css") ?>" - media="screen,print,projection" /> - <link rel="stylesheet" type="text/css" href="<?= $theme->url("css/screen.css") ?>" - media="screen,print,projection" /> - <!--[if IE]> - <link rel="stylesheet" type="text/css" href="<?= $theme->url("css/fix-ie.css") ?>" - media="screen,print,projection" /> - <![endif]--> - <script src="<?= url::file("lib/jquery.js") ?>" type="text/javascript"></script> - <script src="<?= url::file("lib/jquery.form.js") ?>" type="text/javascript"></script> - <script src="<?= url::file("lib/jquery-ui.js") ?>" type="text/javascript"></script> - <script src="<?= url::file("lib/gallery.dialog.js") ?>" type="text/javascript"></script> - <script src="<?= url::file("lib/superfish/js/superfish.js") ?>" type="text/javascript"></script> - <script src="<?= $theme->url("js/jquery.scrollTo.js") ?>" type="text/javascript"></script> - <script src="<?= $theme->url("js/jquery.localscroll.js") ?>" type="text/javascript"></script> - <script src="<?= $theme->url("js/ui.init.js") ?>" type="text/javascript"></script> - <?= $theme->head() ?> - </head> - - <body> - <?= $theme->page_top() ?> - <div id="doc4" class="yui-t5 gView"> - <div id="hd"> - <?= $theme->site_status() ?> - <div id="gHeader"> - <?= $theme->display("header.html") ?> - </div> - </div> - <div id="bd"> - <div id="gContent" style="float:left"> - <ul id="gMessage"> - <li class="gWarning"><?= $content ?></li> - </ul> - </div> - </div> - <div id="ft"> - <div id="gFooter"> - <?= $theme->display("footer.html") ?> - </div> - </div> - </div> - <?= $theme->page_bottom() ?> - </body> -</html> |