Zeta Components - high quality PHP components

Zeta Components Manual :: Docs For Class ezcAuthenticationDatabaseFilter

AuthenticationDatabaseTiein::ezcAuthenticationDatabaseFilter

Class ezcAuthenticationDatabaseFilter

Filter to authenticate against a database.

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.       );

Source for this file: /AuthenticationDatabaseTiein/src/filters/database/database_filter.php

Implements interfaces:

ezcAuthenticationFilter
   |
   --ezcAuthenticationDatabaseFilter
Version:   //autogentag//

Constants

STATUS_PASSWORD_INCORRECT = 2 Password is incorrect.
STATUS_USERNAME_INCORRECT = 1 Username is not found in the database.

Inherited Constants

From ezcAuthenticationFilter:
ezcAuthenticationFilter::STATUS_OK    Successful authentication.

Properties

ezcAuthenticationDatabaseInfo read/write $database
Structure which holds a database instance, table name and fields which are used for authentication.

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
protected ezcAuthenticationFilter::$options

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
public ezcAuthenticationFilterOptions ezcAuthenticationFilter::getOptions()
Returns the options of this class.
public abstract int ezcAuthenticationFilter::run()
Runs the filter and returns a status code when finished.
public void ezcAuthenticationFilter::setOptions()
Sets the options of this class to $options.

Methods

__construct

ezcAuthenticationDatabaseFilter __construct( ezcAuthenticationDatabaseInfo $database , [ezcAuthenticationDatabaseOptions $options = null] )

Creates a new object of this class.

Parameters:
Name Type Description
$database ezcAuthenticationDatabaseInfo Database to use in authentication
$options ezcAuthenticationDatabaseOptions Options for this class

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

int run( ezcAuthenticationPasswordCredentials $credentials )

Runs the filter and returns a status code when finished.

Parameters:
Name Type Description
$credentials ezcAuthenticationPasswordCredentials Authentication credentials
Redefinition of:
Method Description
ezcAuthenticationFilter::run() Runs the filter and returns a status code when finished.
Documentation generated by phpDocumentor 1.4.3