Login/logout redirection
See also: UserAccountModules
Here's a small suggestion for the login/logout page.
The idea came while hacking a previous version of wikka to create a content management system with a public, read-only area (with a limited number of visible pages) and a registered-users area giving read&write access to all the pages.
I thought it might be useful to give the site administrator the possibility to automatically redirect logged users to a specific page immediately after the login. Two possible suggestions:
A. Redirect logged users to a specific page
Add a line to wakka.config.php:"logged_in_homepage" => "IntraNet",
and modify the usersettings.php action so as to redirect logged users to logged_in_homepage:original:
// check password
if ($existingUser["password"] == md5($_POST["password"]))
{
$this->SetUser($existingUser);
$this->Redirect($this->href());
if ($existingUser["password"] == md5($_POST["password"]))
{
$this->SetUser($existingUser);
$this->Redirect($this->href());
- It should be noted that the original function now (v1.1.6.2) looks a little different. This also applies to the Logout part. Althought it's not very difficult to figure this out, but if somebody is trying to do a copy&paste mod (like in phpBB) he could get confused. Therefore I thought it is worth noting. --DaC
-
php// check password switch(TRUE){ case (strlen($_POST['password']) == 0): $error = ERROR_EMPTY_PASSWORD; $password_highlight = INPUT_ERROR_STYLE; break; case (md5($_POST['password']) != $existingUser['password']): $error = ERROR_WRONG_PASSWORD; $password_highlight = INPUT_ERROR_STYLE; break; default: $this->SetUser($existingUser); $this->Redirect($url, ''); }
modified:
// check password
if ($existingUser["password"] == md5($_POST["password"]))
{
$this->SetUser($existingUser);
$this->Redirect($this->config["logged_in_homepage"]);
if ($existingUser["password"] == md5($_POST["password"]))
{
$this->SetUser($existingUser);
$this->Redirect($this->config["logged_in_homepage"]);
B. Back to original page
Keep track of the referrer from which the user accesses the login page and redirect her to the page she came from.Any ideas how to implement this?
- Since referrer isn't reliable (with browsers or privacy software possibly preventing this from being sent back to the server), the best approach is probably to dynamically add a URL parameter to the Login link (for instance &from=[ThisPage]); the Login action can then pick up this parameter (after proper vetting that it's an existing page) an dredirect back to it. --JavaWoman
Same story for the logout screen. For automatic redirecting users to root_page on logout, here's how to modify usersettings.php:
original
<?php
if (isset($_REQUEST["action"]) && ($_REQUEST["action"] == "logout"))
{
$this->LogoutUser();
$this->SetMessage("You are now logged out.");
$this->Redirect($this->href());
if (isset($_REQUEST["action"]) && ($_REQUEST["action"] == "logout"))
{
$this->LogoutUser();
$this->SetMessage("You are now logged out.");
$this->Redirect($this->href());
- Original code looks different in v1.1.6.2. --DaC
-
if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'logout'))
{
$this->LogoutUser();
$params .= 'out=true';
$this->Redirect($url.$params);
}
modified
<?php
if (isset($_REQUEST["action"]) && ($_REQUEST["action"] == "logout"))
{
$this->LogoutUser();
$this->SetMessage("You are now logged out.");
$this->Redirect($this->config["root_page"]);
if (isset($_REQUEST["action"]) && ($_REQUEST["action"] == "logout"))
{
$this->LogoutUser();
$this->SetMessage("You are now logged out.");
$this->Redirect($this->config["root_page"]);
Perhaps these options, together with the default one [Stay on login page], might be added in wakka.config.php:
"login_redirect" => "1"
/*
"0" : redirection disabled (stay on UserSettings after login);
"1" : redirect to original page;
"2" : redirect to logged_in_homepage;
*/
/*
"0" : redirection disabled (stay on UserSettings after login);
"1" : redirect to original page;
"2" : redirect to logged_in_homepage;
*/
In the same way, the logout redirect behavior could be directly controlled by the wakka_config.php file:
"logout_redirect" => "1"
/*
"0" : redirection disabled (stay on UserSettings after logout);
"1" : redirect to original page;
"2" : redirect to root_page;
*/
/*
"0" : redirection disabled (stay on UserSettings after logout);
"1" : redirect to original page;
"2" : redirect to root_page;
*/
CategoryDevelopmentUserAccount