Re: [Phplib-users] Giancarlo Pinerolo (pingus) auth patch
Brought to you by:
nhruby,
richardarcher
|
From: Giancarlo P. <gia...@na...> - 2002-06-06 13:35:08
|
Michele Marcucci wrote: > > Hi there, > i'm looking for a method to put everywhere the loginform (like many > site, like phpnuke for example) so i get this patch > ( > https://sourceforge.net/tracker/index.php?func=detail&aid=561500&group_id=31885&atid=403613 > ) > but i dont understand how it works, please can you help me? > That is something supposed to be tried throughout first. You must understand that, if phplib is doing less, being less invadent, there's something more you have to do. Phplib used to occupy a full page with its login/register forms, and exit. You don't want that, you don't want even to show the login form on top of the page, when the auth class is started. You simply want to set a switch, that you can use right on top of your script, or in a fancy login box right down at the end. So I attach you 2 examples: index.php3 is a modified 'simple page from the examples. showoff.php3 is a modified authenticated page. It can have or not have the user and perm classes correct the include prepend.php3 there. index is accessible to all users, but logged in ones will not see the login form showoff is only for registered users. Then you have to make a little change to new.page.inc. I coded it to mantain the same behavior of before: show a full blown login/register page, and exit. The one I send you should instead only set a global switch $needform, that you'd use later. the auth.inc in the patch is OK. In fact I realize that auth[uid] nobody has no more sense once you can intercept the behaviour of auth itself. I will be back soon to this, if there's any interest. Giancarlo ------------- showoff (protected page) -------------- <?php include("new.prepend.php3"); include($_PHPLIB["libdir"] . "table.inc"); page_open(array("sess" => "Example_Session", "auth" => "Example_Auth")); ## use this for no user storage ### use this if you want user storage too /******+ page_open(array("sess" => "Example_Session", "auth" => "Example_Auth", "perm" => "Example_Perm", "user" => "Example_User")); *///// if ($needform) { $auth->auth_loginform(); page_close(); ## You may want exit; ## to exit here } /* // page access requires that the user is authenticated and has "admin" permission if (!$perm->check("admin")) ## you need to modify perm->check to return ## true/false instead of 'perminvalid_page_and_exit { $auth->auth_loginform(); exit; } */ $sess->register("s"); ?> <a href="<?php $sess->purl("logout.php3") ?>">Logout</a> and delete your authentication information.<br> <?php // Demonstration of per session data: We are incrementing a scalar, $s. printf("<h1>Per Session Data: %s</h1>\n", ++$s); // Show how to access the session and the user id. printf("Your session id is %s<br>\n", $sess->id); // printf("Your user id is %s<br>\n", $user->id); // printf("This should be the same as %s<br>\n", $auth->auth["uid"]); printf("You have the permissions %s<br>\n", $auth->auth["perm"]); ?> <?php page_close() ?> ---------------------------- ----- index page ------------ <?php include("new.prepend.php3"); # sess for session variables // page_open(array("sess" => "Example_Session")); page_open(array("sess" => "Example_Session", "auth" => "Example_Auth")); # s is a per session variable, u is a per user variable. if (!isset($s)) { $s=0; }; $sess->register("s"); echo "<center><h1>some previous page content</h1></center>"; echo "session ID ".$sess->id."<p>"; echo "user ID ".$auth->auth['uid']."<p>"; echo "user NAME ".$auth->auth['uname']."<p>"; if ($needform) { $auth->auth_loginform(); // page_close(); ## You may want // exit; ## to exit here } // Demonstration of per session data: We are incrementing a scalar, $s. printf("<h1>Per Session Data: %s</h1>\n", ++$s); // Save data back to database. page_close() ?> <!-- $Id: index.php3,v 1.1.1.1 2000/04/17 16:40:06 kk Exp $ --> -------------- -------- page.inc -------------- <?php /* * Session Management for PHP3 * * Copyright (c) 1998-2000 NetUSE AG * Boris Erdmann, Kristian Koehntopp * * $Id: page.inc,v 1.4 2002/03/18 18:07:02 layne_weathers Exp $ * */ $needform=false; ### the switch function page_open($feature) { global $_PHPLIB,$HTTP_GET_VARS; # enable sess and all dependent features. if (isset($feature["sess"])) { global $sess; $sess = new $feature["sess"]; $sess->start(); # the auth feature depends on sess if (isset($feature["auth"])) { global $auth; if (!is_object($auth)) { $auth = new $feature["auth"]; } if (!$auth->start()) { page_showform(); // $sess->freeze(); ## here I don't exit // exit; } # the perm feature depends on auth and sess if (isset($feature["perm"])) { global $perm; if (!is_object($perm)) { $perm = new $feature["perm"]; } } # the user feature depends on auth and sess if (isset($feature["user"])) { global $user; if (!is_object($user)) { $user = new $feature["user"]; } $user->start($auth->auth["uid"]); } } ## Load the auto_init-File, if one is specified. if (($sess->auto_init != "") && !$sess->in) { $sess->in = 1; include($_PHPLIB["libdir"] . $sess->auto_init); if ($sess->secure_auto_init != "") { $sess->freeze(); } } } } function page_close() { global $sess, $user; if (is_object($sess)) { $sess->freeze(); if (is_object($user)) { $user->freeze(); } } } function sess_load($session) { reset($session); while (list($k,$v) = each($session)) { $GLOBALS[$k] = new $v; $GLOBALS[$k]->start(); } } function sess_save($session) { reset($session); while (list(,$v) = each($session)) { $GLOBALS[$v]->freeze(); } } function page_showform() { global $auth,$HTTP_GET_VARS; $mode=$HTTP_GET_VARS['mode']; global $needform; $needform=true; ### here I don't show a form, but only set the switch /* if ($mode=="reg") {$auth->auth_registerform();} else {$auth->auth_loginform();} */ } ?> |