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

Class: LiveUser

Source Location: /LiveUser-0.15.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:

  • Release: @package_version@

Copyright:

  • 2002-2005 Markus Wolff

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 182]
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

$dispatcher =  null

[line 319]

Stores the event dispatcher which handles notifications
  • Access: protected

Type:   array


[ Top ]



Method Detail

LiveUser (Constructor)   [line 327]

void LiveUser( )

Constructor
  • Access: protected

[ Top ]

addErrorLog   [line 775]

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 644]

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 ]

authFactory   [line 566]

object|false &authFactory( array|file &$conf, string $containerName, [string $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.
string   $containerName   —  Name of the container we'll be using.
string   $classprefix   —  Prefix of the class that will be used.

[ Top ]

checkGroup   [line 1451]

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 1392]

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 1430]

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 791]

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 1131]

boolean disconnect( )

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

[ Top ]

factory   [line 462]

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.             'updateLastLogin' => true,
  52.             'allowDuplicateHandles' => false,
  53.             'allowEmptyPasswords' => false,
  54.             'authTable'     => 'liveuser_users',
  55.             'authTableCols' => array(
  56.                 'required' => array(
  57.                     'auth_user_id' => array('type' => 'text''name' => 'user_id'),
  58.                     'handle'       => array('type' => 'text''name' => 'handle'),
  59.                     'passwd'       => array('type' => 'text''name' => 'passwd')
  60.                 ),
  61.                 'optional' => array(
  62.                     'owner_user_id'  => array('type' => 'integer''name' => 'owner_user_id'),
  63.                     'owner_group_id' => array('type' => 'integer''name' => 'owner_group_id')
  64.                     'lastlogin'    => array('type' => 'timestamp''name' => 'lastlogin'),
  65.                     'is_active'    => array('type' => 'boolean''name' => 'is_active')
  66.                 ),
  67.                 'custom'   => array(
  68.                     'myaliasforfield1' => array('type' => 'text''name' => 'myfield1')
  69.                 )
  70.            ),
  71.            'externalValues' => array(
  72.                   'values'      => &$_SERVER,
  73.                   'keysToCheck' => array('HTTP_USER_AGENT')
  74.            ),
  75.       ),
  76.   ),
  77.   'permContainer' => array(
  78.       'type'       => 'Complex',
  79.       'storage' => array(
  80.           'MDB2' => array(
  81.               'dsn' => $dsn,
  82.               'prefix'     => 'liveuser_'
  83.               'tables' => array(),
  84.               'fields' => array(),
  85.               'alias' => array(),
  86.               'force_seq' => true,
  87.           ),
  88.       ),
  89.   ),

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 670]

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 1104]

boolean freeze( )

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

[ Top ]

getErrors   [line 524]

array getErrors( )

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

[ Top ]

getOption   [line 872]

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 1518]

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 1540]

integer getStatus( )

Get the current status.
  • Access: public

[ Top ]

init   [line 898]

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 1503]

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 1480]

boolean isLoggedIn( )

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

[ Top ]

loadClass   [line 540]

boolean loadClass( string $classname)

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

Parameters:

string   $classname   —  classname

[ Top ]

loadPEARLog   [line 747]

void loadPEARLog( )

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

[ Top ]

logout   [line 1333]

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 589]

object|false &permFactory( array|file &$conf, [string $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:

string   $classprefix   —  Prefix of the class that will be used.
array|file   &$conf   —  Name of array containing the configuration.

[ Top ]

setOption   [line 853]

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 498]

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 1565]

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 612]

object|false &storageFactory( array &$confArray, [string $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:

string   $classprefix   —  Prefix of the class that will be used.
array   &$confArray   —  configuration array to pass to the storage container

[ Top ]

__toString   [line 1552]

string __toString( )

make a string representation of the object
  • Access: public

[ Top ]


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