cvs: pear /Auth Auth.php /Auth/Container DB.php

From: Date: Fri, 16 Nov 2001 21:03:11 +0000
Subject: cvs: pear /Auth Auth.php /Auth/Container DB.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-1347@lists.php.net to get a copy of this message
mj Fri Nov 16 16:03:11 2001 EDT Modified files: /pear/Auth Auth.php /pear/Auth/Container DB.php Log: * Added addUser(), removeUser(), listUsers() to add, remove or list users to/from the storage container. Index: pear/Auth/Auth.php diff -u pear/Auth/Auth.php:1.10 pear/Auth/Auth.php:1.11 --- pear/Auth/Auth.php:1.10 Fri Nov 2 06:24:50 2001 +++ pear/Auth/Auth.php Fri Nov 16 16:03:10 2001 @@ -16,9 +16,10 @@ // | Authors: Martin Jansen <mj@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Auth.php,v 1.10 2001/11/02 11:24:50 mj Exp $ +// $Id: Auth.php,v 1.11 2001/11/16 21:03:10 mj Exp $ // + /** * PEAR::Auth * @@ -45,7 +46,7 @@ * * @author Martin Jansen <mj@php.net> * @package Auth - * @version $Revision: 1.10 $ + * @version $Revision: 1.11 $ */ define("AUTH_IDLED", -1); @@ -220,7 +221,7 @@ } /** - * If the login failed or the user entered not username, + * If the login failed or the user entered no username, * output the login screen again. */ if ($this->username != "" && !$login_ok) { @@ -332,7 +333,8 @@ * * @return bool True if the user is logged in, otherwise false. */ - function getAuth() { + function getAuth() + { if ($GLOBALS['HTTP_SESSION_VARS']['auth']['registered'] == true) { return true; @@ -418,7 +420,8 @@ /** * Update the idletime */ - function updateIdle() { + function updateIdle() + { $GLOBALS['auth'] = &$GLOBALS['HTTP_SESSION_VARS']['auth']; $GLOBALS['auth']['idle'] = time(); } @@ -447,6 +450,47 @@ function sessionValidThru() { return ($GLOBALS['HTTP_SESSION_VARS']['auth']['idle'] + $this->idle); + } + + // }}} + // {{{ listUsers() + + /** + * List all users that are currently available in the storage + * container + * + * @return array + */ + function listUsers() + { + return $this->storage->listUsers(); + } + + // {{{ addUser() + + /** + * Add user to the storage container + * + * @param string Username + * @param string Password + * @param mixed Additional parameters + */ + function addUser($username, $password, $additional = "") + { + return $this->storage->addUser($username, $password, $additional); + } + + // }}} + // {{{ removeUser() + + /** + * Remove user from the storage container + * + * @param string Username + */ + function removeUser($username) + { + return $this->storage->removeUser($username); } // }}} Index: pear/Auth/Container/DB.php diff -u pear/Auth/Container/DB.php:1.6 pear/Auth/Container/DB.php:1.7 --- pear/Auth/Container/DB.php:1.6 Fri Nov 2 06:24:50 2001 +++ pear/Auth/Container/DB.php Fri Nov 16 16:03:11 2001 @@ -16,7 +16,7 @@ // | Authors: Martin Jansen <mj@php.net> | // +----------------------------------------------------------------------+ // -// $Id: DB.php,v 1.6 2001/11/02 11:24:50 mj Exp $ +// $Id: DB.php,v 1.7 2001/11/16 21:03:11 mj Exp $ // require_once "Auth/Container.php"; @@ -30,7 +30,7 @@ * * @author Martin Jansen <mj@php.net> * @package Auth - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ */ class Auth_Container_DB extends Auth_Container { @@ -128,6 +128,7 @@ $this->options['usernamecol'] = "username"; $this->options['passwordcol'] = "password"; $this->options['dsn'] = ""; + $this->options['db_fields'] = "*"; } // }}} @@ -192,6 +193,90 @@ } else { return false; } + } + } + + // }}} + // {{{ listUsers() + + function listUsers() + { + $retVal = array(); + + $query = sprintf("SELECT %s FROM %s", + $this->options['db_fields'], + $this->options['table'] + ); + + $res = $this->db->query($query); + + if (DB::isError($res)) { + return new DB_Error($res->code, PEAR_ERROR_DIE); + } else { + while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) { + $retVal[] = $row; + } + } + + return $retVal; + } + + // }}} + // {{{ addUser() + + /** + * Add user to the storage container + * + * @access public + * @param string Username + * @param string Password + * + * @return mixed True on success, otherwise error object + */ + function addUser($username, $password) + { + $query = sprintf("INSERT INTO %s (%s, %s) VALUES ('%s', '%s')", + $this->options['table'], + $this->options['usernamecol'], + $this->options['passwordcol'], + $username, + md5($password) + ); + + $res = $this->db->query($query); + + if (DB::isError($res)) { + return new DB_Error($res->code, PEAR_ERROR_DIE); + } else { + return true; + } + } + + // }}} + // {{{ removeUser() + + /** + * Remove user from the storage container + * + * @access public + * @param string Username + * + * @return mixed True on success, otherwise error object + */ + function removeUser($username) + { + $query = sprintf("DELETE FROM %s WHERE %s = '%s'", + $this->options['table'], + $this->options['usernamecol'], + $username + ); + + $res = $this->db->query($query); + + if (DB::isError($res)) { + return new DB_Error($res->code, PEAR_ERROR_DIE); + } else { + return true; } }

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