Class: Auth


public    class Auth

User authentication component. This is the basic authentication component; you can use this class if you only need toallow/disallow access to a page. If you need groups and roles support see the classGroupAuth and the class RoleAuth documentation.

Auth

Author(s): Julio César Carrascal Urquijo <jcesar@phreaker.net>
Version: 2.4 pl3
Direct known subclasses: GroupAuth, RoleAuth

Public Method Summary

void Auth([ string $options ])
Constructor.
void startSession()
Initialize the session.
void forceLogin()
Force the user to identify him self.
void logout()
Delete all session information and logout the user.
void refreshInfo()
Updates the user's information from the database.

Private Method Summary

void _callback(int $action, [ string $message ])
Just calls the callback function and dies.
void _connect()
Connect to the database only if necesary.
array _findByUsername(string $username, string $password)
Search the user in the database by his username and password.
array _findById(int $userId)
Search the user in the database by his user_id field.
bool _checkSession()
Validates the current session.

Public Field Summary

array $user Holds user information.
boolean $isIdentified If the user has been identified
string $cacheLevel Wich cache level to use.
string $dbdriver Database driver. Example 'mysql', 'mssql', 'oci8'...
string $hostname Database hostname server.
string $username Database username
string $password Database password
string $database Database.

Private Field Summary

string $_conn Holds an ADOConnection instance.
array $_options This array hold database configuration and execution options.

Public Constant Summary

AUTH_INVALID_USER »-2« The username/password pair is invalid.
AUTH_EXPIRED »-3« The session has expired.
AUTH_ACCESS_DENIED »-4« You don't have access to this area.
AUTH_CACHE »2« Allow the browser to cache the page but proxys can't.
AUTH_NO_CACHE »1« Do not allow anyone to cache the page.

Private Constant Summary

AUTH_NEED_LOGIN »-1« Need a valid username/password pair.

Public Method Details

Auth


public    void Auth( [ string $options ] );

Constructor.

Parameters:
string $options = >>null<<
  => val of configuration parameters.
Returns: void

startSession


public    void startSession(  );

Initialize the session. Use this method only if loggin in to the current page is optional but you willwant to have access to the user's information if he has already been identified.

Returns: void

forceLogin


public    void forceLogin(  );

Force the user to identify him self.

Returns: void

logout


public    void logout(  );

Delete all session information and logout the user.

Returns: void

refreshInfo


public    void refreshInfo(  );

Updates the user's information from the database. The user must be identified already. Usefull if you just updated the database andyou need to update your session variable.

Returns: void

Private Method Details

_callback


private    void _callback( int $action, [ string $message ] );

Just calls the callback function and dies.

Parameters:
int $action
  action should the callback function take. Has to be one
of AUTH_NEED_LOGIN, AUTH_INVALID_USER, AUTH_ACCESS_DENIED or
AUTH_EXPIRED.
string $message = >>''<<
  to show to the user, optional.
Returns: void

_connect


private    void _connect(  );

Connect to the database only if necesary.

Returns: void

_findByUsername


private    array _findByUsername( string $username, string $password );

Search the user in the database by his username and password.

Parameters:
string $username
 
string $password
 
Returns: array
users information.
See Also: _findById()

_findById


private    array _findById( int $userId );

Search the user in the database by his user_id field.

Parameters:
int $userId
  the user.
Returns: array
users information.
See Also: _findByUsername()

_checkSession


private    bool _checkSession(  );

Validates the current session.

Returns: bool

Public Field Details

$user


public   array $user

Holds user information.

$isIdentified


public   boolean $isIdentified

If the user has been identified

$cacheLevel


public   string $cacheLevel

Wich cache level to use.

$dbdriver


public   string $dbdriver

Database driver. Example 'mysql', 'mssql', 'oci8'...

$hostname


public   string $hostname

Database hostname server.

$username


public   string $username

Database username

$password


public   string $password

Database password

$database


public   string $database

Database.

Private Field Details

$_conn


private   string $_conn

Holds an ADOConnection instance.

$_options


private   array $_options

This array hold database configuration and execution options.

Public Constant Details

const AUTH_INVALID_USER


define( AUTH_INVALID_USER, »-2« );

The username/password pair is invalid.

const AUTH_EXPIRED


define( AUTH_EXPIRED, »-3« );

The session has expired.

const AUTH_ACCESS_DENIED


define( AUTH_ACCESS_DENIED, »-4« );

You don't have access to this area.

const AUTH_CACHE


define( AUTH_CACHE, »2« );

Allow the browser to cache the page but proxys can't.

const AUTH_NO_CACHE


define( AUTH_NO_CACHE, »1« );

Do not allow anyone to cache the page.

Private Constant Details

const AUTH_NEED_LOGIN


define( AUTH_NEED_LOGIN, »-1« );

Need a valid username/password pair.