Subversion Repositories Applications.papyrus

Rev

Rev 1173 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1173 Rev 1713
Line 16... Line 16...
16
 * @package    Auth
16
 * @package    Auth
17
 * @author     Yavor Shahpasov <yavo@netsmart.com.cy>
17
 * @author     Yavor Shahpasov <yavo@netsmart.com.cy>
18
 * @author     Adam Ashley <aashley@php.net>
18
 * @author     Adam Ashley <aashley@php.net>
19
 * @copyright  2001-2006 The PHP Group
19
 * @copyright  2001-2006 The PHP Group
20
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
20
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
21
 * @version    CVS: $Id: Controller.php,v 1.1 2006-12-14 15:04:28 jp_milcent Exp $
21
 * @version    CVS: $Id: Controller.php,v 1.2 2007-11-19 15:11:00 jp_milcent Exp $
22
 * @link       http://pear.php.net/package/Auth
22
 * @link       http://pear.php.net/package/Auth
23
 * @since      File available since Release 1.3.0
23
 * @since      File available since Release 1.3.0
24
 */
24
 */
Line 25... Line 25...
25
 
25
 
26
/**
26
/**
27
 * Controlls access to a group of php access 
27
 * Controlls access to a group of php access
28
 * and redirects to a predefined login page as 
28
 * and redirects to a predefined login page as
29
 * needed
29
 * needed
30
 *
30
 *
31
 * In all pages
31
 * In all pages
32
 * <code>
32
 * <code>
Line 44... Line 44...
44
 * $_auth = new Auth('File', 'passwd');
44
 * $_auth = new Auth('File', 'passwd');
45
 * $authController = new Auth_Controller($_auth, 'login.php', 'index.php');
45
 * $authController = new Auth_Controller($_auth, 'login.php', 'index.php');
46
 * $authController->start();
46
 * $authController->start();
47
 * if( $authController->isAuthorised() ){
47
 * if( $authController->isAuthorised() ){
48
 *   $authController->redirectBack();
48
 *   $authController->redirectBack();
49
 * }  
49
 * }
50
 * </code>
50
 * </code>
51
 *
51
 *
52
 * @category   Authentication
52
 * @category   Authentication
53
 * @author     Yavor Shahpasov <yavo@netsmart.com.cy>
53
 * @author     Yavor Shahpasov <yavo@netsmart.com.cy>
54
 * @author     Adam Ashley <aashley@php.net>
54
 * @author     Adam Ashley <aashley@php.net>
55
 * @copyright  2001-2006 The PHP Group
55
 * @copyright  2001-2006 The PHP Group
56
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
56
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
57
 * @version    Release: 1.4.3  File: $Revision: 1.1 $
57
 * @version    Release: 1.5.4  File: $Revision: 1.2 $
58
 * @link       http://pear.php.net/package/Auth
58
 * @link       http://pear.php.net/package/Auth
59
 * @since      Class available since Release 1.3.0
59
 * @since      Class available since Release 1.3.0
60
 */
60
 */
61
class Auth_Controller
61
class Auth_Controller
62
{
62
{
Line 63... Line 63...
63
 
63
 
Line 64... Line 64...
64
    // {{{ properties
64
    // {{{ properties
65
 
65
 
66
    /** 
66
    /**
67
     * The Auth instance this controller is managing
67
     * The Auth instance this controller is managing
68
     *
68
     *
69
     * @var object Auth
69
     * @var object Auth
70
     */
70
     */
71
    var $auth = null;
71
    var $auth = null;
72
    
72
 
73
    /**
73
    /**
74
     * The login URL
74
     * The login URL
75
     * @var string
75
     * @var string
76
     * */
76
     * */
77
    var $login = null;
77
    var $login = null;
78
    
78
 
79
    /**
79
    /**
80
     * The default index page to use when the caller page is not set
80
     * The default index page to use when the caller page is not set
81
     *
81
     *
82
     * @var string 
82
     * @var string
83
     */
83
     */
84
    var $default = null;
84
    var $default = null;
85
    
85
 
86
    /** 
86
    /**
87
     * If this is set to true after a succesfull login the 
87
     * If this is set to true after a succesfull login the
88
     * Auth_Controller::redirectBack() is invoked automatically 
88
     * Auth_Controller::redirectBack() is invoked automatically
89
     *
89
     *
90
     * @var boolean
90
     * @var boolean
Line 91... Line 91...
91
     */
91
     */
92
    var $autoRedirectBack = false;
92
    var $autoRedirectBack = false;
93
 
93
 
94
    // }}}
94
    // }}}
95
    // {{{ Auth_Controller() [constructor]
95
    // {{{ Auth_Controller() [constructor]
96
    
96
 
97
    /**
97
    /**
98
     * Constructor
98
     * Constructor
Line 119... Line 119...
119
        }
119
        }
120
    }
120
    }
Line 121... Line 121...
121
 
121
 
122
    // }}}
122
    // }}}
123
    // {{{ setAutoRedirectBack()
123
    // {{{ setAutoRedirectBack()
124
    
124
 
125
    /** 
125
    /**
126
     * Enables auto redirection when login is done
126
     * Enables auto redirection when login is done
127
     * 
127
     *
128
     * @param bool Sets the autoRedirectBack flag to this
128
     * @param bool Sets the autoRedirectBack flag to this
129
     * @see Auth_Controller::autoRedirectBack
129
     * @see Auth_Controller::autoRedirectBack
130
     * @return void
130
     * @return void
131
     */
131
     */
Line 134... Line 134...
134
        $this->autoRedirectBack = $flag;
134
        $this->autoRedirectBack = $flag;
135
    }
135
    }
Line 136... Line 136...
136
 
136
 
137
    // }}}
137
    // }}}
138
    // {{{ redirectBack()
138
    // {{{ redirectBack()
139
    
139
 
140
    /**
140
    /**
141
     * Redirects Back to the calling page
141
     * Redirects Back to the calling page
142
     *
142
     *
143
     * @return void
143
     * @return void
144
     */
144
     */
145
    function redirectBack()
145
    function redirectBack()
146
    {
146
    {
147
        // If redirectback go there
147
        // If redirectback go there
148
        // else go to the default page
148
        // else go to the default page
149
        
149
 
150
        $returnUrl = $this->auth->getAuthData('returnUrl');
150
        $returnUrl = $this->auth->getAuthData('returnUrl');
151
        if(!$returnUrl) {
151
        if(!$returnUrl) {
152
            $returnUrl = $this->_defaultPage;
152
            $returnUrl = $this->_defaultPage;
153
        }
153
        }
154
        
154
 
155
        // Add some entropy to the return to make it unique
155
        // Add some entropy to the return to make it unique
156
        // avoind problems with cached pages and proxies
156
        // avoind problems with cached pages and proxies
157
        if(strpos($returnUrl, '?') === false) {
157
        if(strpos($returnUrl, '?') === false) {
158
            $returnUrl .= '?';
158
            $returnUrl .= '?';
159
        }
159
        }
Line 160... Line 160...
160
        $returnUrl .= uniqid('');
160
        $returnUrl .= uniqid('');
161
 
161
 
162
        // Track the auth status
162
        // Track the auth status
163
        if($this->auth->status != '') {
163
        if($this->auth->status != '') {
164
            $url .= '&authstatus='.$this->auth->status;
164
            $url .= '&authstatus='.$this->auth->status;
165
        }        
165
        }
166
        header('Location:'.$returnUrl);
166
        header('Location:'.$returnUrl);
Line 167... Line 167...
167
        print("You could not be redirected to <a href=\"$returnUrl\">$returnUrl</a>");
167
        print("You could not be redirected to <a href=\"$returnUrl\">$returnUrl</a>");
168
    }
168
    }
169
 
169
 
170
    // }}}
170
    // }}}
171
    // {{{ redirectLogin()
171
    // {{{ redirectLogin()
172
    
172
 
173
    /**
173
    /**
174
      * Redirects to the login Page if not authorised
174
      * Redirects to the login Page if not authorised
175
      * 
175
      *
176
      * put return page on the query or in auth
176
      * put return page on the query or in auth
177
      *
177
      *
178
      * @return void
178
      * @return void
179
      */
179
      */
180
    function redirectLogin()
180
    function redirectLogin()
181
    {
181
    {
182
        // Go to the login Page
182
        // Go to the login Page
183
        
183
 
184
        // For Auth, put some check to avoid infinite redirects, this should at least exclude
184
        // For Auth, put some check to avoid infinite redirects, this should at least exclude
185
        // the login page
185
        // the login page
186
        
186
 
187
        $url = $this->_loginPage;
187
        $url = $this->_loginPage;
Line 202... Line 202...
202
        print("You could not be redirected to <a href=\"$url\">$url</a>");
202
        print("You could not be redirected to <a href=\"$url\">$url</a>");
203
    }
203
    }
Line 204... Line 204...
204
 
204
 
205
    // }}}
205
    // }}}
206
    // {{{ start()
206
    // {{{ start()
207
    
207
 
208
    /**
208
    /**
209
      * Starts the Auth Procedure
209
      * Starts the Auth Procedure
210
      *
210
      *
211
      * If the page requires login the user is redirected to the login page
211
      * If the page requires login the user is redirected to the login page
Line 224... Line 224...
224
            $this->redirectLogin();
224
            $this->redirectLogin();
225
        } else {
225
        } else {
226
            $this->auth->start();
226
            $this->auth->start();
227
            // Logged on and on login page
227
            // Logged on and on login page
228
            if(strstr($_SERVER['PHP_SELF'], $this->_loginPage) && $this->auth->checkAuth()){
228
            if(strstr($_SERVER['PHP_SELF'], $this->_loginPage) && $this->auth->checkAuth()){
229
                $this->autoRedirectBack ? 
229
                $this->autoRedirectBack ?
230
                    $this->redirectBack() :
230
                    $this->redirectBack() :
231
                    null ;
231
                    null ;
232
            }
232
            }
233
        }
233
        }
234
        
234
 
235
        
235
 
236
    }
236
    }
Line 237... Line 237...
237
 
237
 
238
    // }}}
238
    // }}}
239
    // {{{ isAuthorised()
239
    // {{{ isAuthorised()
240
  
240
 
241
    /**
241
    /**
242
      * Checks is the user is logged on
242
      * Checks is the user is logged on
243
      * @see Auth::checkAuth()
243
      * @see Auth::checkAuth()
244
      */
244
      */