Subversion Repositories Applications.papyrus

Rev

Rev 1713 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1173 jp_milcent 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3
 
4
/**
5
 * Anonymous authentication support
6
 *
7
 * PHP versions 4 and 5
8
 *
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.
14
 *
15
 * @category   Authentication
16
 * @package    Auth
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
2150 mathias 21
 * @version    CVS: $Id: Anonymous.php,v 1.6 2007/06/12 03:11:26 aashley Exp $
1173 jp_milcent 22
 * @link       http://pear.php.net/package/Auth
23
 * @since      File available since Release 1.3.0
24
 */
25
 
26
/**
27
 * Include Auth package
28
 */
29
require_once 'Auth.php';
30
 
31
/**
32
 * Anonymous Authentication
1713 jp_milcent 33
 *
34
 * This class provides anonymous authentication if username and password
1173 jp_milcent 35
 * were not supplied
36
 *
37
 * @category   Authentication
38
 * @package    Auth
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
2150 mathias 43
 * @version    Release: 1.5.4  File: $Revision: 1.6 $
1173 jp_milcent 44
 * @link       http://pear.php.net/package/Auth
45
 * @since      Class available since Release 1.3.0
46
 */
1713 jp_milcent 47
class Auth_Anonymous extends Auth
1173 jp_milcent 48
{
49
 
50
    // {{{ properties
51
 
52
    /**
53
     * Whether to allow anonymous authentication
54
     *
55
     * @var boolean
56
     */
57
    var $allow_anonymous = true;
58
 
59
    /**
60
     * Username to use for anonymous user
61
     *
62
     * @var string
63
     */
64
    var $anonymous_username = 'anonymous';
65
 
66
    // }}}
67
    // {{{ Auth_Anonymous() [constructor]
1713 jp_milcent 68
 
1173 jp_milcent 69
    /**
70
     * Pass all parameters to Parent Auth class
1713 jp_milcent 71
     *
1173 jp_milcent 72
     * Set up the storage driver.
73
     *
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)
78
     *
79
     * @param string    Name of the function that creates the login form
80
     * @param boolean   Should the login form be displayed if neccessary?
81
     * @return void
82
     * @see Auth::Auth()
83
     */
84
    function Auth_Anonymous($storageDriver, $options = '', $loginFunction = '', $showLogin = true) {
85
        parent::Auth($storageDriver, $options, $loginFunction, $showLogin);
86
    }
87
 
88
    // }}}
89
    // {{{ login()
1713 jp_milcent 90
 
1173 jp_milcent 91
    /**
92
     * Login function
1713 jp_milcent 93
     *
1173 jp_milcent 94
     * If no username & password is passed then login as the username
95
     * provided in $this->anonymous_username else call standard login()
96
     * function.
97
     *
98
     * @return void
99
     * @access private
100
     * @see Auth::login()
101
     */
102
    function login() {
1713 jp_milcent 103
        if (   $this->allow_anonymous
104
            && empty($this->username)
1173 jp_milcent 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) );
109
            }
110
        } else {
111
            // Call normal login system
112
            parent::login();
113
        }
114
    }
115
 
116
    // }}}
117
    // {{{ forceLogin()
1713 jp_milcent 118
 
1173 jp_milcent 119
    /**
120
     * Force the user to login
121
     *
122
     * Calling this function forces the user to provide a real username and
123
     * password before continuing.
124
     *
125
     * @return void
126
     */
127
    function forceLogin() {
128
        $this->allow_anonymous = false;
129
        if( !empty($this->session['username']) && $this->session['username'] == $this->anonymous_username ) {
130
            $this->logout();
131
        }
132
    }
133
 
134
    // }}}
135
 
136
}
137
 
138
?>