LiveUser
[ class tree: LiveUser ] [ index: LiveUser ] [ all elements ]

Class: LiveUser

Source Location: /LiveUser-0.14.0/LiveUser.php

Class Overview


This is a manager class for a user login system using the LiveUser class. It creates a LiveUser object, takes care of the whole login process and stores the LiveUser object in a session.


Author(s):

Version:

  • $Id: LiveUser.php,v 1.30 2004/12/19 10:20:06 lsmith Exp $

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 162]
This is a manager class for a user login system using the LiveUser class. It creates a LiveUser object, takes care of the whole login process and stores the LiveUser object in a session.

You can also configure this class to try to connect to more than one server that can store user information - each server requiring a different backend class. This way you can for example create a login system for a live website that first queries the local database and if the requested user is not found, it tries to find im in your company's LDAP server. That way you don't have to create lots of user accounts for your employees so that they can access closed sections of your website - everyone can use his existing account.

NOTE: No browser output may be made before using this class, because it will try to send HTTP headers such as cookies and redirects.

Requirements:

  • Should run on PHP version 4.2.0 (required for PEAR_Errorstack or higher, tested only from 4.2.1 onwards
Thanks to: Bjoern Schotte, Kristian Koehntopp, Antonio Guerra



[ Top ]


Class Variables

$events = array(
        'onLogin',     // successfully logged in
        'forceLogin',  // login required -> you could display a login form
        'onLogout',    // before logout -> can be used to cleanup own stuff
        'postLogout',  // after logout -> e.g. do a redirect to another page
        'onIdled',     // maximum idle time is reached
        'onExpired'    // authentication session is expired
    )

[line 298]

Events that are allowed to be triggered (built in events are preset).
  • Access: protected

Type:   array


[ Top ]

$_observers = array()

[line 313]

Used to store attached observers.
  • Access: protected

Type:   array


[ Top ]



Method Detail

LiveUser (Constructor)   [line 321]

void LiveUser( )

Constructor
  • Access: protected

[ Top ]

addErrorLog   [line 738]

boolean addErrorLog( Log &$log)

Add error logger for use by Errorstack.

Be aware that if you need add a log at the beginning of your code if you want it to be effective. A log will only be taken into account after it's added.

Sample usage:

  1.  $lu_object &LiveUser::singleton($conf);
  2.  $logger &Log::factory('mail''bug@example.com',
  3.       'myapp_debug_mail_log'array('from' => 'application_bug@example.com'));
  4.  $lu_object->addErrorLog($logger);

  • Return: true on success or false on failure
  • Access: public

Parameters:

Log   &$log   —  logger instance

[ Top ]

arrayMergeClobber   [line 624]

array|false arrayMergeClobber( array $a1, array $a2)

Clobbers two arrays together

taken from the user notes of array_merge_recursive used in LiveUser::_readConfig() may be called statically

  • Return: array on success and false on error
  • Author: kc@hireability.com
  • Access: public

Parameters:

array   $a1   —  array that should be clobbered
array   $a2   —  array that should be clobbered

[ Top ]

attachObserver   [line 1462]

bool attachObserver( object object &$object, [mixed $methods = array()])

Add an observer object to listen to multiple events

In contrast to LiveUser::attachObserver() this can be used to add an object providing observer methods for some or all events. If you don't set parameter $methods it tries to find matching methods for each registered event and adds them as observer callback. You can use the $methods parameter to set what method should act as an observer for what event.

  • Return: true on success, otherwise false
  • See: LiveUser::triggerEvent
  • Access: public

Parameters:

object object   &$object   —  with observer methods
mixed   $methods   —  optional used to change method names this way: array('event' => 'realMethodName', ...) or string

[ Top ]

authFactory   [line 552]

object|false &authFactory( array|file &$conf, $containerName, [ $classprefix = 'LiveUser_'])

Creates an instance of an auth object
  • Return: Returns an instance of an auth container class or false on error
  • Access: public

Parameters:

array|file   &$conf   —  Name of array containing the configuration.
   $containerName   — 
   $classprefix   — 

[ Top ]

checkGroup   [line 1356]

boolean checkGroup( array|int $groups)

Wrapper method for the permission object's own checkGroup method.
  • Return: true on success or false on failure
  • Access: public

Parameters:

array|int   $groups   —  A group id or an array of groups.

[ Top ]

checkRight   [line 1299]

int|false checkRight( array|int $rights)

Wrapper method for the permission object's own checkRight method.
  • Return: level if the user has the right/rights false if not
  • Access: public

Parameters:

array|int   $rights   —  A right id or an array of rights.

[ Top ]

checkRightLevel   [line 1336]

boolean checkRightLevel( array|int $rights, array|int $owner_user_id, array|int $owner_group_id)

Wrapper method for the permission object's own checkRightLevel method.
  • Return: true on success or false on failure
  • Access: public

Parameters:

array|int   $rights   —  A right id or an array of rights.
array|int   $owner_user_id   —  Id or array of Ids of the owner of the
array|int   $owner_group_id   —  Id or array of Ids of the group of the ressource for which the right is requested.

[ Top ]

CryptRC4Factory   [line 753]

object Returns &CryptRC4Factory( string $secret)

Creates an instance of the PEAR::Crypt_Rc4 class
  • Return: an instance of the Crypt_RC4 class
  • Access: public

Parameters:

string   $secret   —  token to use to encrypt data

[ Top ]

disconnect   [line 1061]

boolean disconnect( )

Properly disconnect resources in the active container
  • Return: true on success or false on failure
  • Access: public

[ Top ]

factory   [line 447]

LiveUser|false &factory( mixed $conf, [string $handle = ''], [string $passwd = ''], [boolean $logout = false], [boolean $remember = false], [mixed $confName = 'liveuserConfig'])

Returns an instance of the login manager class.

This array contains private options defined by the following associative keys:

  1.  array(
  2.   'autoInit' => false/true,
  3.   'session'  => array(
  4.       'name'    => 'liveuser session name',
  5.       'varname' => 'liveuser session var name'
  6.   ),
  7.  // The session_save_handler options are optional. If they are specified,
  8.  // session_set_save_handler() will be called with the parameters
  9.   'session_save_handler' => array(
  10.       'open'    => 'name of the open function/method',
  11.       'close'   => 'name of the close function/method',
  12.       'read'    => 'name of the read function/method',
  13.       'write'   => 'name of the write function/method',
  14.       'destroy' => 'name of the destroy function/method',
  15.       'gc'      => 'name of the gc function/method',
  16.   ),
  17.  // The session_cookie_params options are optional. If they are specified,
  18.  // session_set_cookie_params() will be called with the parameters
  19.   'session_cookie_params' => array(
  20.       'lifetime' => 'Cookie lifetime in days',
  21.       'path'     => 'Cookie path',
  22.       'domain'   => 'Cookie domain',
  23.       'secure'   => 'Cookie send only over secure connections',
  24.   ),
  25.   'login' => array(
  26.       'force'    => 'Should the user be forced to login'
  27.       'regenid'  => 'Should the session be regenerated on login'
  28.   ),
  29.   'logout' => array(
  30.       'destroy'  => 'Whether to destroy the session on logout' false or true
  31.   ),
  32.  // The cookie options are optional. If they are specified, the Remember Me
  33.  // feature is activated.
  34.   'cookie' => array(
  35.       'name'     => 'Name of Remember Me cookie',
  36.       'lifetime' => 'Cookie lifetime in days',
  37.       'path'     => 'Cookie path',
  38.       'domain'   => 'Cookie domain',
  39.       'secret'   => 'Secret key used for cookie value encryption',
  40.       'savedir'  => '/absolute/path/to/writeable/directory' // No / at the end !
  41.       'secure'   => 'Cookie send only over secure connections',
  42.   ),
  43.   'authContainers' => array(
  44.       'name' => array(
  45.             'type' => 'DB',
  46.             'connection'    => 'db connection object, use this or dsn',
  47.             'dsn'           => 'database dsn, use this or connection',
  48.             'loginTimeout'  => 0,
  49.             'expireTime'    => 3600,
  50.             'idleTime'      => 1800,
  51.             'allowDuplicateHandles' => 0,
  52.             'authTable'     => 'liveuser_users',
  53.             'authTableCols' => array(
  54.                 'required' => array(
  55.                     'auth_user_id' => array('type' => 'text''name' => 'user_id'),
  56.                     'handle'       => array('type' => 'text''name' => 'handle'),
  57.                     'passwd'       => array('type' => 'text''name' => 'passwd')
  58.                 ),
  59.                 'optional' => array(
  60.                     'owner_user_id'  => array('type' => 'integer''name' => 'owner_user_id'),
  61.                     'owner_group_id' => array('type' => 'integer''name' => 'owner_group_id')
  62.                     'lastlogin'    => array('type' => 'timestamp''name' => 'lastlogin'),
  63.                     'is_active'    => array('type' => 'boolean''name' => 'is_active')
  64.                 ),
  65.                 'custom'   => array(
  66.                     'myaliasforfield1' => array('type' => 'text''name' => 'myfield1')
  67.                 )
  68.            ),
  69.            'externalValues' => array(
  70.                   'values'      => &$_SERVER,
  71.                   'keysToCheck' => array('HTTP_USER_AGENT')
  72.            ),
  73.       ),
  74.   ),
  75.   'permContainer' => array(
  76.       'type'       => 'Complex',
  77.       'storage' => array(
  78.           'DB' => array(
  79.               'dsn' => $dsn,
  80.               'prefix'     => 'liveuser_'
  81.           ),
  82.       ),
  83.   ),

Other options in the configuration file relative to the Auth and Perm containers depend on what the containers expect. Refer to the Containers documentation. The examples for containers provided are just general do not reflect all the options for all containers.

  • Return: Returns an object of either LiveUser or false on error if so use LiveUser::getErrors() to get the errors
  • See: LiveUser::getErrors
  • Access: public

Parameters:

mixed   $conf   —  The config file or the config array to configure.
string   $handle   —  Handle of the user trying to authenticate
string   $passwd   —  Password of the user trying to authenticate
boolean   $logout   —  set to true if user wants to logout
boolean   $remember   —  set if remember me is set
mixed   $confName   —  Name of array containing the configuration.

[ Top ]

fileExists   [line 649]

boolean fileExists( string $file)

checks if a file exists in the include path
  • Return: true success and false on error
  • Access: public

Parameters:

string   $file   —  filename

[ Top ]

freeze   [line 1035]

boolean freeze( )

Store all properties in an array
  • Return: true on sucess or false on failure
  • Access: public

[ Top ]

getErrors   [line 514]

array getErrors( )

Wrapper method to get the Error Stack
  • Return: an array of the errors
  • Access: public

[ Top ]

getOption   [line 826]

mixed getOption( string $option)

Returns the value of an option
  • Return: the option value or false on failure
  • Access: public

Parameters:

string   $option   —  option name

[ Top ]

getProperty   [line 1419]

mixed getProperty( string $what, [string $container = 'auth'])

Wrapper method to access properties from the auth and permission containers.
  • Return: a value or an array.
  • Access: public

Parameters:

string   $what   —  Name of the property to be returned.
string   $container   —  'auth' or 'perm'

[ Top ]

getStatus   [line 1440]

integer getStatus( )

Get the current status.
  • Access: public

[ Top ]

init   [line 851]

boolean init( [string $handle = ''], [string $passwd = ''], [boolean $logout = false], [boolean $remember = false])

Tries to retrieve auth object from session.

If this fails, the class attempts a login based on cookie or form information (depends on class settings). Returns true if a auth object was successfully retrieved or created. Otherwise, false is returned.

  • Return: true if init process well, false if something went wrong.
  • Access: public

Parameters:

string   $handle   —  handle of the user trying to authenticate
string   $passwd   —  password of the user trying to authenticate
boolean   $logout   —  set to true if user wants to logout
boolean   $remember   —  set if remember me is set

[ Top ]

isInactive   [line 1405]

boolean isInactive( )

Function that determines if the user exists but hasn't yet been declared "active" by an administrator.

Use this to check if this was the reason why a user was not able to login. true == user account is NOT active false == user account is active

  • Return: true if the user account is *not* active false if the user account *is* active
  • Access: public

[ Top ]

isLoggedIn   [line 1383]

boolean isLoggedIn( )

Checks if a user is logged in.
  • Return: true if user is logged in, false if not
  • Access: public

[ Top ]

loadClass   [line 529]

boolean loadClass( string $classname)

Loads a PEAR class
  • Return: true success or false on failure
  • Access: public

Parameters:

string   $classname   —  classname

[ Top ]

loadPEARLog   [line 1580]

void loadPEARLog( )

This method lazy loads PEAR::Log
  • Access: protected

[ Top ]

logout   [line 1240]

void logout( [boolean $direct = true])

This destroys the session object.
  • Access: public

Parameters:

boolean   $direct   —  set to true if the logout was initiated directly

[ Top ]

permFactory   [line 573]

object|false &permFactory( mixed &$conf, [ $classprefix = 'LiveUser_'])

Creates an instance of an perm object
  • Return: Returns an instance of a perm container class or false on error
  • Access: public

Parameters:

mixed   &$conf   —  Name of array containing the configuration.
   $classprefix   — 

[ Top ]

setOption   [line 808]

boolean setOption( string $option, mixed $value)

Sets an option.
  • Return: true on success or false on failure
  • See: LiveUser::_options
  • Access: public

Parameters:

string   $option   —  option name
mixed   $value   —  value for the option

[ Top ]

singleton   [line 488]

LiveUser|false &singleton( array|file $conf, [string $handle = ''], [string $passwd = ''], [boolean $logout = false], [boolean $remember = false], [string $confName = 'liveuserConfig'])

Makes your instance global.

In PHP4 you MUST call this method with the $var = &LiveUser::singleton() syntax. Without the ampersand (&) in front of the method name, you will not get a reference, you will get a copy.

  • Return: Returns an object of either LiveUser or false on failure
  • See: LiveUser::factory
  • Access: public

Parameters:

array|file   $conf   —  The config file or the config array to configure.
string   $handle   —  Handle of the user trying to authenticate
string   $passwd   —  Password of the user trying to authenticate
boolean   $logout   —  set to true if user wants to logout
boolean   $remember   —  set if remember me is set
string   $confName   —  Name of array containing the configuration.

[ Top ]

statusMessage   [line 1547]

string statusMessage( int $value)

Return a textual status message for a LiveUser status code.
  • Return: error message
  • Access: public

Parameters:

int   $value   —  status code

[ Top ]

storageFactory   [line 590]

object|false &storageFactory( array &$confArray, [ $classprefix = 'LiveUser_'])

Returns an instance of a storage Container
  • Return: will return an instance of a Storage container or false upon error
  • Access: protected

Parameters:

array   &$confArray   —  configuration array to pass to the storage container
   $classprefix   — 

[ Top ]

triggerEvent   [line 1504]

bool triggerEvent( string $event, [array $params = array()])

Notify all attached observers about a certain event

LiveUser object ($this) and $params are set as first and second parameters for each observer notification. $event is always set as 'event' field in $params, so this can not be used as a parameter but is useful if you want to use one single observer callback function for multiple events.

  • Return: true on success, false otherwise
  • See: LiveUser::attachObserver(), LiveUser::attachObserverObj(), LiveUser::registerEvent()
  • Access: public

Parameters:

string   $event   —  event name
array   $params   —  optional params to send to observers

[ Top ]

__toString   [line 1535]

string __toString( )

make a string representation of the object
  • Access: public

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:00:07 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.