AuthenticationDatabaseTiein: ezcAuthenticationDatabaseFilter
[ ]
[ ]
[ ]
[ ]
[ ]
Class: ezcAuthenticationDatabaseFilter
|
Filter to authenticate against a database. [
source]
Implemented Interfaces
The database instance to use is specified using a ezcAuthenticationDatabaseInfo structure. Table name and field names are specified in the same structure.
Example:
1. $credentials = new ezcAuthenticationPasswordCredentials( 'jan.modaal', 'b1b3773a05c0ed0176787a4f1574ff0075f7521e' );
2. $database = new ezcAuthenticationDatabaseInfo( ezcDbInstance::get(), 'users', array( 'user', 'password' ) );
3. $authentication = new ezcAuthentication( $credentials );
4. $authentication->addFilter( new ezcAuthenticationDatabaseFilter( $database ) );
5. if ( !$authentication->run() )
6. {
7. // authentication did not succeed, so inform the user
8. $status = $authentication->getStatus();
9. $err = array(
10. 'ezcAuthenticationDatabaseFilter' => array(
11. ezcAuthenticationDatabaseFilter::STATUS_USERNAME_INCORRECT => 'Incorrect username',
12. ezcAuthenticationDatabaseFilter::STATUS_PASSWORD_INCORRECT => 'Incorrect password'
13. )
14. );
15. foreach ( $status as $line )
16. {
17. list( $key, $value ) = each( $line );
18. echo $err[$key][$value] . "\n";
19. }
20. }
21. else
22. {
23. // authentication succeeded, so allow the user to see his content
24. }
Extra data can be fetched from the database during the authentication process, by registering the data to be fetched before calling run(). Example:
1. // $filter is an ezcAuthenticationDatabaseFilter object
2. $filter->registerFetchData( array( 'name', 'country' ) );
3.
4. // after run()
5. $data = $filter->fetchData();
The $data array will be something like:
1. array( 'name' => array( 'John Doe' ),
2. 'country' => array( 'US' )
3. );
Parents
ezcAuthenticationFilter
|
--ezcAuthenticationDatabaseFilter
Constants
Inherited Constants
From
ezcAuthenticationFilter:
Properties
Member Variables
|
protected array(string=>mixed) |
$data
= array()
Holds the extra data fetched during the authentication process.
Usually it has this structure: 1. array( 'name' => array( 'John Doe' ),
2. 'country' => array( 'US' )
3. );
|
|
protected array(string) |
$requestedData
= array()
Holds the attributes which will be requested during the authentication process.
Usually it has this structure: 1. array( 'fullname', 'gender', 'country', 'language' );
|
Inherited Member Variables
From
ezcAuthenticationFilter:
Method Summary
|
public ezcAuthenticationDatabaseFilter |
__construct(
$database, [$options = null] )
Creates a new object of this class. |
|
public array(string=>mixed) |
fetchData(
)
Returns the extra data which was fetched during the authentication process. |
|
public void |
registerFetchData(
[$data = array()] )
Registers the extra data which will be fetched by the filter during the authentication process. |
|
public int |
run(
$credentials )
Runs the filter and returns a status code when finished. |
Inherited Methods
From
ezcAuthenticationFilter :
Methods
__construct
Creates a new object of this class.
Parameters
fetchData
array(string=>mixed) fetchData(
)
Returns the extra data which was fetched during the authentication process.
Example of returned array:
1. array( 'name' => array( 'John Doe' ),
2. 'country' => array( 'US' )
3. );
registerFetchData
void registerFetchData(
[
$data = array()] )
Registers the extra data which will be fetched by the filter during the authentication process.
The input $data should be an array of attributes, for example:
1. array( 'name', 'country' );
Parameters
| Name |
Type |
Description |
$data |
array(string) |
The extra data to fetch during authentication |
run
Runs the filter and returns a status code when finished.
Parameters
Redefinition of
Last updated: Mon, 05 Jan 2009