|
Archive /
LoginLogoutSummary: Add login and logout actions and pages Status: Superseded Version: 1 Prerequisites: pmwiki-2.0 Maintainer: Categories: Superceded Votes: 5 QuestionHow can I provide a Login page for valid users with passwords and a Logout page for removing used passwords and author names from the session, to help especially someone to log out when using the wiki from a public computer? Answer As of 2.1.beta9 ?action=login and ?action=logout are a part of the core distribution.
Add a LoginInstallationSee below for code fragments you can place in the Then just add the following line to your config.php: include_once('cookbook/login.php');
This adds LogoutAdmins may implement a short session (one that expires in 5min, for example) But that's frustrating when editing long pages and having to re-enter the read password. OR we could add a bit of code to kill the current session and related cookies. The following code adds
##adds action=logout
global $HandleActions;
SDV($HandleActions['logout'], 'HandleLogout');
function HandleLogout($pagename) {
session_start();
session_unset();
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time() - 42000, '/');
}
if (isset($_COOKIE['author'])) {
setcookie('author', '', time() - 42000, '/');
}
session_destroy();
Redirect('Main.Logout');
}
Main.Logout is a page giving some positive feedback that the action was successful, like \\ %center%%red%[+You have successfully logged out and started a new session.+] \\ \\ Of course, you can redirect to Main.HomePage or any other page that's not read-protected. To redirect to the page you were before the Redirect($pagename); To provide the interface, for instance place in the skin template as part of the page action links <a href='$PageUrl?action=logout'>$[Logout]</a> or place on a page to be included in the page template (preferably at the top), markup like:
Author: - %green%'''''{$Author}'''''%% - [[{$Name}?action=logout | Logout]]
or the following, which includes a login/logout switch, i.e only one set of links will be shown:
*%green%(:if ! auth edit:)''Welcome Guest''%%
*[[Main/Login]]
*%green%(:if auth edit:)''Welcome {$Author}''%%
*[[{$Name}?action=logout|logout]]
*[[{$Name}?action=edit | Edit]]
*%item diff%[[{$Name}?action=diff | History]](:if:)
ToDo: add code fit to be placed in the skin template itself. Hint: check the calls available in LayoutAdvanced. Other Hint (for skin.php):
$page = RetrieveAuthPage($pagename, 'read', false, READPAGE_CURRENT);
if ($page['=auth']['edit']) {
# visitor has edit permission
} else {
# visitor doesn't have edit permission
LoginMethod 1If you want also to use a
##adds action=login
SDV($HandleActions['login'], 'HandleLogin');
$DefaultPasswords['LoginAction'] = ' ';
function HandleLogin($pagename) {
RetrieveAuthPage($pagename,'LoginAction',true,READPAGE_CURRENT);
Redirect($pagename);
}
Here As an alternative AuthUser provides a way to prompt for a user name and password. If AuthUser is installed a simple Login page can be created, lets call it `Main.Login, with a simple message, like !!Welcome plus perhaps content which may be conditionally displayed, depending on who is accessing the page. Now set the page attribute read:somepassword. With AuthUser you can set several passwords like id:guest,bob,nancy. Finally provide a link to this read-protected page, in the SideBar or the page top menu, as outlined above. A user can click Login, which opens the username and password prompt, and after succesful login a welcome message. Note that this needs AuthUser installed, and login not through the Login page is also possible. If AuthUser is not used a password will still be prompted. Method 2Here's another approach, which I believe has the following advantages:
## Login actions
global $HandleActions;
// Edit
SDV($HandleActions['login'], 'HandleLogin');
function HandleLogin($pagename) {
RetrieveAuthPage($pagename, 'edit');
Redirect($pagename);
}
// Upload
SDV($HandleActions['loginupload'], 'HandleLoginUpload');
function HandleLoginUpload($pagename) {
RetrieveAuthPage($pagename, 'upload');
Redirect($pagename);
}
// Admin
SDV($HandleActions['loginadmin'], 'HandleLoginAdmin');
function HandleLoginAdmin($pagename) {
RetrieveAuthPage($pagename, 'admin');
Redirect($pagename);
}
--HaganFox InstallationIf you don't want to place the above code fragments in the Then just add the following line to your include_once('cookbook/loginlogout.php');
In this version you are redirected to the actual page you were before calling the action Notes and CommentsThe script doesn't work with PmWiki 2.1.beta3. What has changed? Can one define markup for an action=login, similar to the action=logout, so login can happen while staying on the current page?
PmWiki 2.0.5 onwards adds an action=logout (so you won't need to define it). If you want the visitor to be redirected to another page upon logging out, use the pmwiki 2.1.betaXX: I've encountered a similiar problem using method 1 with authuser, only admin users got directed correctly, other users will fall into an infinite loop of login prompt. See AlsoContributors |