cvs: pear /Auth Auth.php

From: Date: Thu, 01 Nov 2001 14:39:44 +0000
Subject: cvs: pear /Auth Auth.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-1228@lists.php.net to get a copy of this message
mj Thu Nov 1 09:39:44 2001 EDT Modified files: /pear/Auth Auth.php Log: * nuke un-necessary call require statement * Whitespace Index: pear/Auth/Auth.php diff -u pear/Auth/Auth.php:1.6 pear/Auth/Auth.php:1.7 --- pear/Auth/Auth.php:1.6 Thu Nov 1 09:32:03 2001 +++ pear/Auth/Auth.php Thu Nov 1 09:39:43 2001 @@ -16,7 +16,7 @@ // | Authors: Martin Jansen <mj@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Auth.php,v 1.6 2001/11/01 14:32:03 mj Exp $ +// $Id: Auth.php,v 1.7 2001/11/01 14:39:43 mj Exp $ // /** @@ -26,12 +26,12 @@ * authentication system using PHP. * * Usage example: - * + * * require_once "Auth/Auth.php"; - * + * * // We use a MySQL as storage container in this example * $a = new Auth("DB","mysql://martin:test@localhost/test"); - * + * * // Detect, if the user is already logged in. If not, draw the * // login form. * $a->start(); @@ -45,11 +45,9 @@ * * @author Martin Jansen <mj@php.net> * @package Auth - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ */ -require_once "PEAR.php"; - define("AUTH_IDLED", -1); define("AUTH_EXPIRED", -2); define("AUTH_WRONG_LOGIN", -3); @@ -60,7 +58,7 @@ /** * Auth lifetime in seconds - * + * * If this variable is set to 0, auth never expires * * @var integer @@ -109,7 +107,7 @@ * * @var string */ - var $loginFunc = ""; + var $loginFunction = ""; // {{{ Constructor @@ -126,11 +124,11 @@ * @param string Name of the function that creates the login form * @param bool Is authentication necessary or not */ - function Auth($storageDriver = "DB", $options = "", $loginFunc = "") - { - if ($loginFunc != "" && function_exists($loginFunc)) { - $this->loginFunc = $loginFunc; - } + function Auth($storageDriver = "DB", $options = "", $loginFunction = "") + { + if ($loginFunc != "" && function_exists($loginFunction)) { + $this->loginFunction = $loginFunction; + } $this->storage = $this->_factory($storageDriver,$options); } @@ -172,10 +170,10 @@ * @global $HTTP_POST_VARS * @see Auth */ - function assignData() + function assignData() { global $HTTP_POST_VARS; - + if ($HTTP_POST_VARS['username'] != "") { $this->username = $HTTP_POST_VARS['username']; } @@ -193,12 +191,12 @@ * * @access private */ - function start() + function start() { session_start(); $this->assignData(); - + if (!$this->checkAuth()) { $this->login(); } @@ -214,7 +212,6 @@ */ function login() { - /** * When the user has already entered a username, * we have to validate it. @@ -227,7 +224,6 @@ * If the login failed or the user entered not username, * output the login screen again. */ - if ($this->username != "" && !$login_ok) { $this->status = AUTH_WRONG_LOGIN; } @@ -246,9 +242,9 @@ * * @access private * @param integer time in seconds - * @param bool add time to current expire time or not + * @param bool add time to current expire time or not */ - function setExpire($time,$add = false) + function setExpire($time,$add = false) { if ($add) { $this->expire += $time; @@ -266,12 +262,12 @@ * @access private * @return boolean Whether or not the user is authenticated. */ - function checkAuth() + function checkAuth() { if (isset($GLOBALS['HTTP_SESSION_VARS']['auth'])) { /** Check if authentication session is expired */ - if ($this->expire > 0 && + if ($this->expire > 0 && ($GLOBALS['HTTP_SESSION_VARS']['auth']['timestamp'] + $this->expire) < time()) { $this->logout(); @@ -315,9 +311,9 @@ * * @param string Username */ - function setAuth($username) + function setAuth($username) { - + if (!isset($GLOBALS['HTTP_SESSION_VARS']['auth'])) { session_register('auth'); } @@ -328,7 +324,7 @@ $GLOBALS['auth']['timestamp'] = time(); $GLOBALS['auth']['idle'] = time(); } - + // }}} // {{{ getAuth() @@ -362,21 +358,21 @@ * @param string Username if already entered */ function drawLogin($username = "") - { - if ($this->loginFunc != "") { - call_user_func($this->loginFunc, $username, $this->status); + { + if ($this->loginFunction != "") { + call_user_func($this->loginFunction, $username, $this->status); } else { global $HTTP_SERVER_VARS; - + echo "<center>\n"; - + if ($this->status == AUTH_EXPIRED) { echo "<i>Your session expired. Please login again!</i>\n"; } else if ($this->status == AUTH_IDLED) { echo "<i>You have been idle for too long. Please login again!</i>\n"; } else if ($this->status == AUTH_WRONG_LOGIN) { - echo "<i>Wrong login data!</i>\n"; - } + echo "<i>Wrong login data!</i>\n"; + } echo "<form method=\"post\" action=\"" . $HTTP_SERVER_VARS['PHP_SELF'] . "\">\n"; echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n"; @@ -397,7 +393,7 @@ echo "</table>\n"; echo "</form>\n"; echo "</center>\n\n"; - } + } } // }}} @@ -409,7 +405,7 @@ * This function clears any auth tokes in the currently * active session */ - function logout() + function logout() { $this->username = ""; $this->password = ""; @@ -448,7 +444,7 @@ * Returns the time up to the session is valid * * @return integer - */ + */ function sessionValidThru() { return ($GLOBALS['HTTP_SESSION_VARS']['auth']['idle'] + $this->idle);

« previous php.pear.cvs (#1228) next »