2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
5 * Anonymous authentication support
9 * LICENSE: This source file is subject to version 3.01 of the PHP license
10 * that is available through the world-wide-web at the following URI:
11 * http://www.php.net/license/3_01.txt. If you did not receive a copy of
12 * the PHP License and are unable to obtain it through the web, please
13 * send a note to license@php.net so we can mail you a copy immediately.
15 * @category Authentication
17 * @author Yavor Shahpasov <yavo@netsmart.com.cy>
18 * @author Adam Ashley <aashley@php.net>
19 * @copyright 2001-2006 The PHP Group
20 * @license http://www.php.net/license/3_01.txt PHP License 3.01
21 * @version CVS: $Id: Anonymous.php 289651 2009-10-15 04:39:07Z aashley $
22 * @link http://pear.php.net/package/Auth
23 * @since File available since Release 1.3.0
27 * Include Auth package
29 require_once 'Auth.php';
32 * Anonymous Authentication
34 * This class provides anonymous authentication if username and password
37 * @category Authentication
39 * @author Yavor Shahpasov <yavo@netsmart.com.cy>
40 * @author Adam Ashley <aashley@php.net>
41 * @copyright 2001-2006 The PHP Group
42 * @license http://www.php.net/license/3_01.txt PHP License 3.01
43 * @version Release: 1.6.2 File: $Revision: 289651 $
44 * @link http://pear.php.net/package/Auth
45 * @since Class available since Release 1.3.0
47 class Auth_Anonymous extends Auth
53 * Whether to allow anonymous authentication
57 var $allow_anonymous = true;
60 * Username to use for anonymous user
64 var $anonymous_username = 'anonymous';
67 // {{{ Auth_Anonymous() [constructor]
70 * Pass all parameters to Parent Auth class
72 * Set up the storage driver.
74 * @param string Type of the storage driver
75 * @param mixed Additional options for the storage driver
76 * (example: if you are using DB as the storage
77 * driver, you have to pass the dsn string here)
79 * @param string Name of the function that creates the login form
80 * @param boolean Should the login form be displayed if necessary?
84 function Auth_Anonymous($storageDriver, $options = '', $loginFunction = '', $showLogin = true) {
85 parent::Auth($storageDriver, $options, $loginFunction, $showLogin);
94 * If no username & password is passed then login as the username
95 * provided in $this->anonymous_username else call standard login()
103 if ( $this->allow_anonymous
104 && empty($this->username)
105 && empty($this->password) ) {
106 $this->setAuth($this->anonymous_username);
107 if (is_callable($this->loginCallback)) {
108 call_user_func_array($this->loginCallback, array($this->username, $this) );
111 // Call normal login system
120 * Force the user to login
122 * Calling this function forces the user to provide a real username and
123 * password before continuing.
127 function forceLogin() {
128 $this->allow_anonymous = false;
129 if( !empty($this->session['username']) && $this->session['username'] == $this->anonymous_username ) {