From 59b5a0549635aa5c8320707cec75612746debdd0 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 30 Oct 2009 09:32:18 -0700 Subject: Rename the login helper to auth. Create a login and logout helper function to allow for programmically login in and out. --- modules/gallery/controllers/albums.php | 2 +- modules/gallery/controllers/login.php | 15 ++++----------- modules/gallery/controllers/logout.php | 12 +----------- 3 files changed, 6 insertions(+), 23 deletions(-) (limited to 'modules/gallery/controllers') diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index d393422e..a430b14d 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -29,7 +29,7 @@ class Albums_Controller extends Items_Controller { $view = new Theme_View("page.html", "login"); $view->page_title = t("Log in to Gallery"); $view->content = new View("login_ajax.html"); - $view->content->form = login::get_form("login/auth_html"); + $view->content->form = auth::get_login_form("login/auth_html"); print $view; return; } else { diff --git a/modules/gallery/controllers/login.php b/modules/gallery/controllers/login.php index 3978b64f..75ee6b9c 100644 --- a/modules/gallery/controllers/login.php +++ b/modules/gallery/controllers/login.php @@ -21,7 +21,7 @@ class Login_Controller extends Controller { public function ajax() { $view = new View("login_ajax.html"); - $view->form = login::get_form("login/auth_ajax"); + $view->form = auth::get_login_form("login/auth_ajax"); print $view; } @@ -40,7 +40,7 @@ class Login_Controller extends Controller { } public function html() { - print login::get_form("login/auth_html"); + print auth::get_login_form("login/auth_html"); } public function auth_html() { @@ -55,7 +55,7 @@ class Login_Controller extends Controller { } private function _auth($url) { - $form = login::get_form($url); + $form = auth::get_login_form($url); $valid = $form->validate(); if ($valid) { $user = identity::lookup_user_by_name($form->login->inputs["name"]->value); @@ -70,14 +70,7 @@ class Login_Controller extends Controller { } if ($valid) { - if (identity::is_writable()) { - $user->login_count += 1; - $user->last_login = time(); - $user->save(); - } - identity::set_active_user($user); - log::info("user", t("User %name logged in", array("name" => $user->name))); - module::event("user_login", $user); + auth::login($user); } // Either way, regenerate the session id to avoid session trapping diff --git a/modules/gallery/controllers/logout.php b/modules/gallery/controllers/logout.php index 1b0364fd..2b93655d 100644 --- a/modules/gallery/controllers/logout.php +++ b/modules/gallery/controllers/logout.php @@ -19,17 +19,7 @@ */ class Logout_Controller extends Controller { public function index() { - $user = identity::active_user(); - if (!$user->guest) { - try { - Session::instance()->destroy(); - } catch (Exception $e) { - Kohana::log("error", $e); - } - module::event("user_logout", $user); - } - log::info("user", t("User %name logged out", array("name" => $user->name)), - html::anchor("user/$user->id", html::clean($user->name))); + auth::logout(); if ($continue_url = $this->input->get("continue")) { $item = url::get_item_from_uri($continue_url); if (access::can("view", $item)) { -- cgit v1.2.3 From 80b892915f7286d3cb8daef3ba12c012738cef28 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 31 Oct 2009 14:22:12 -0700 Subject: Change the order of processing to allow various modules to respond to the identity change event after the new provider instance has been installed. Once the new provider is installed and activated, we can uninstall the old provider which causes users to be deleted. This should be safer, because at this point our new identity provider has been installed, most of the ownership issues have been resolved by the identity change handlers. If there are any ownership issues left, the user deleted event has the new identity provider to uses to rectify them. --- modules/gallery/controllers/admin_identity.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'modules/gallery/controllers') diff --git a/modules/gallery/controllers/admin_identity.php b/modules/gallery/controllers/admin_identity.php index 520b1966..acf71665 100644 --- a/modules/gallery/controllers/admin_identity.php +++ b/modules/gallery/controllers/admin_identity.php @@ -40,15 +40,11 @@ class Admin_Identity_Controller extends Admin_Controller { $active_provider = module::get_var("gallery", "identity_provider", "user"); $providers = identity::providers(); - $new_provider = $this->input->post("provider"); if ($new_provider != $active_provider) { - module::event("identity_before_change", $active_provider, $new_provider); - module::deactivate($active_provider); - module::uninstall($active_provider); // Switch authentication identity::reset(); @@ -57,6 +53,10 @@ class Admin_Identity_Controller extends Admin_Controller { module::install($new_provider); module::activate($new_provider); + module::event("identity_provider_changed", $active_provider, $new_provider); + + module::uninstall($active_provider); + message::success(t("Changed to %description", array("description" => $providers->$new_provider))); -- cgit v1.2.3