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

Class: LiveUser

Source Location: /LiveUser-0.16.14/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-2006 Markus Wolff

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 191]
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.

An example would be to 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 it in your company's LDAP server. It means you don't have to create several user accounts for your employees so that they can access closed sections of your website - everyone can use one 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 330]

Stores the event dispatcher which handles notifications.
  • Access: protected

Type:   Event_Dispatcher


[ Top ]

$log =  null

[line 299]

PEAR::Log object used for error logging by ErrorStack.
  • Access: public

Type:   Log


[ Top ]



Method Detail

LiveUser (Constructor)   [line 343]

void LiveUser( &$debug, bool|object $debug)

Constructor. Use the factory or singleton methods.
  • See: LiveUser::singleton
  • See: LiveUser::factory
  • Access: protected

Parameters:

bool|object    $debug   —  Boolean that indicates if a log instance should be created or an instance of a class that implements the PEAR:Log interface.
   &$debug   — 

[ Top ]

arrayMergeClobber   [line 669]

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

Clobbers two arrays together.

Function taken from the user notes of array_merge_recursive function used in LiveUser::readConfig() and 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 572]

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

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

Parameters:

array   &$conf   —  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 1611]

bool 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 1553]

int|false checkRight( array|int $rights)

Wrapper method for the permission object's own checkRight method.

Use this method to determine if a user has a given right or set of rights.

  • 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 1593]

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

Wrapper method for the permission object's own checkRight and checkLevel methods
  • 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 ]

classExists   [line 720]

bool classExists( string $classname)

Checks if a class exists without triggering __autoload
  • Return: true success and false on error
  • Access: public

Parameters:

string   $classname   —  classname

[ Top ]

cryptRC4   [line 934]

string cryptRC4( string $data, string $secret, [bool $crypt = true])

Crypts data using mcrypt or userland if not available.
  • Return: (de-)crypted data
  • Access: public

Parameters:

string   $data   —  data
string   $secret   —  secret key
bool   $crypt   —  true if it should be crypted, false if it should be decrypted

[ Top ]

cryptRC4Factory   [line 914]

Crypt_RC4 &cryptRC4Factory( string $secret)

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

Parameters:

string   $secret   —  token to use to encrypt data

[ Top ]

decryptPW   [line 843]

string decryptPW( string $encryptedPW, string $passwordEncryptionMode, $secret)

Decrypts a password so that it can be compared with the user input.

Uses the algorithm defined in the passwordEncryptionMode parameter.

  • Return: The decrypted password

Parameters:

string   $encryptedPW   —  the encrypted password
string   $passwordEncryptionMode   —  the encryption mode
   $secret   — 

[ Top ]

deleteRememberCookie   [line 1472]

bool deleteRememberCookie( )

Deletes the rememberMe cookie.
  • Return: true on success or false on failure
  • Access: public

[ Top ]

disconnect   [line 1296]

bool disconnect( )

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

[ Top ]

encryptPW   [line 873]

string encryptPW( string $plainPW, string $passwordEncryptionMode, string $secret)

Encrypts a password for storage in a backend container.

Uses the algorithm defined in the passwordEncryptionMode parameter.

  • Return: The encrypted password

Parameters:

string   $plainPW   —  password to encrypt
string   $passwordEncryptionMode   —  the encryption mode
string   $secret   —  token to use to encrypt data

[ Top ]

factory   [line 463]

LiveUser &factory( array &$conf)

Returns an instance of the LiveUser class.

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

  1.  array(
  2.   'debug' => false/true or an instance of a class that implements the PEAR::Log interface
  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.       'httponly' => 'HHTP only cookie, PHP 5.2.0+ only',
  25.   ),
  26.  'cache_perm' => if the permission data should be cached inside the session
  27.   'login' => array(
  28.       'force'    => 'Should the user be forced to login'
  29.       'regenid'  => 'Should the session be regenerated on login'
  30.   ),
  31.   'logout' => array(
  32.       'destroy'  => 'Whether to destroy the session on logout' false or true
  33.   ),
  34.  // The cookie options are optional. If they are specified, the Remember Me
  35.  // feature is activated.
  36.   'cookie' => array(
  37.       'name'     => 'Name of Remember Me cookie',
  38.       'lifetime' => 'Cookie lifetime in days',
  39.       'path'     => 'Cookie path',
  40.       'domain'   => 'Cookie domain',
  41.       'secret'   => 'Secret key used for cookie value encryption',
  42.       'savedir'  => '/absolute/path/to/writeable/directory' // No trailing slash (/) !
  43.       'secure'   => 'Cookie send only over secure connections',
  44.       'httponly' => 'HHTP only cookie, PHP 5.2.0+ only',
  45.   ),
  46.   'authContainers' => array(
  47.       'name' => array(
  48.             'type'            => 'auth container name',
  49.             'expireTime'      => 'maximum lifetime of a session in seconds',
  50.             'idleTime'        => 'maximum amount of time between two request',
  51.             'passwordEncryptionMode'=> 'what encryption method to use',
  52.             'secret'                => 'secret to use in password encryption',
  53.             'storage' => array(
  54.                 'dbc' => 'db connection object, use this or dsn',
  55.                 'dsn' => 'database dsn, use this or connection',
  56.                 'handles' => 'array of handle fields to find a user on login, a user
  57.                   can login with his username, email or any field you set here;
  58.                   works with DB, MDB, MDB2 and PDO containers',
  59.            ),
  60.            'externalValues' => array(
  61.                   'values'      => 'reference to an array',
  62.                   'keysToCheck' => 'array of keys to check in the array passed'
  63.            ),
  64.       ),
  65.   ),
  66.   'permContainer' => array(
  67.       'type'     => 'perm container name',
  68.       'storage'  => array(
  69.           'storage container name' => array(
  70.               'dbc' => 'db connection object, use this or dsn',
  71.               'dsn'        => 'database dsn, use this or connection',
  72.               'prefix'    => 'table prefix'
  73.               'tables'    => 'array containing additional tables or fields in existing tables',
  74.               'fields'    => 'array containing any additional or non-default field types',
  75.               'alias'     => 'array containing any additional or non-default field alias',
  76.               'force_seq' => 'if the use of (emulated) sequences should forced instead of using autoincrement where applicable',
  77.           ),
  78.       ),
  79.   ),

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:

array   &$conf   —  Config array to configure.

[ Top ]

fileExists   [line 692]

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

getErrors   [line 525]

array|bool getErrors( )

Wrapper method to get errors from the Error Stack.
  • Return: an array of the errors or false if there are no errors
  • Access: public

[ Top ]

getOption   [line 997]

mixed getOption( string $option)

Returns the value of an option from the configuration array.
  • Return: the option value or false on failure
  • Access: public

Parameters:

string   $option   —  option name

[ Top ]

getProperty   [line 1678]

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

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

Parameters:

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

[ Top ]

getStatus   [line 1737]

int getStatus( )

Get the current status.
  • Return: a LIVEUSER_STATUS_* constant
  • See: LIVEUSER_STATUS_* constants
  • Access: public

[ Top ]

init   [line 1058]

bool init( )

Tries to retrieve the auth object from session and checks possible timeouts.
  • Return: true if init process well, false if something went wrong.
  • Access: public

[ Top ]

isInactive   [line 1663]

bool 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 1640]

bool isLoggedIn( )

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

[ Top ]

loadClass   [line 542]

bool loadClass( string $classname, [bool $supress_error = false])

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

Parameters:

string   $classname   —  classname to load
bool   $supress_error   —  if errors should be supressed from the stack

[ Top ]

login   [line 1115]

bool login( [string $handle = ''], [string $passwd = ''], [bool $remember = false], [bool|int $auth_user_id = false])

Tries to log the user in by trying all the Auth containers defined in the configuration file until there is a success or a failure.
  • Return: true on success or false on failure
  • Access: public

Parameters:

string   $handle   —  handle of the user trying to authenticate
string   $passwd   —  password of the user trying to authenticate
bool   $remember   —  set if remember me is set, requires cookie otion
bool|int   $auth_user_id   —  if the user data should be read using the auth user id

[ Top ]

logout   [line 1511]

bool logout( [bool $direct = true])

This logs the user out and destroys the session object if the configuration option is set.
  • Return: true on success or false on failure
  • Access: public

Parameters:

bool   $direct   —  set to false if no events should be fired b yhte logout

[ Top ]

PEARLogFactory   [line 793]

log &PEARLogFactory( bool|Log &$log)

Determines if loading of PEAR::Log is necessary.

If an object is passed it is returned, otherwise Log is loaded and instantiated.

  • Return: instance of the given log class
  • Access: protected

Parameters:

bool|Log   &$log   —  Boolean that indicates if a log instance should be created or an instance of a class that implements the PEAR:Log interface.

[ Top ]

permFactory   [line 595]

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

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

Parameters:

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

[ Top ]

readConfig   [line 738]

bool readConfig( array|file $conf, string 1)

Reads the configuration array.
  • Return: true on success or false on failure
  • See: LiveUser::factory
  • Access: public

Parameters:

string   1   —  Name of array containing the configuration
array|file   $conf   —  Conf array or file path to configuration

[ Top ]

readRememberCookie   [line 1404]

bool readRememberCookie( )

Handles the retrieval of the login data from the rememberMe cookie.
  • Return: true on success or false on failure
  • Access: public

[ Top ]

setOption   [line 978]

bool setOption( string $option, mixed $value)

Sets an option after the configuration array has been loaded.

You can override a specific option calling this method.

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

setRememberCookie   [line 1326]

bool setRememberCookie( string $handle, string $passwd)

If cookies are allowed, this method checks if the user wanted a cookie to be set so he doesn't have to enter handle and password for his next login. If true, it will set the cookie.
  • Return: true if the cookie can be set, false otherwise
  • Access: public

Parameters:

string   $handle   —  handle of the user trying to authenticate
string   $passwd   —  password of the user trying to authenticate

[ Top ]

singleton   [line 496]

LiveUser &singleton( array &$conf, [string $signature = null])

This uses the singleton pattern, making sure you have one and only instance of the class.

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::getErrors
  • See: LiveUser::factory
  • Access: public

Parameters:

array   &$conf   —  Config array to configure.
string   $signature   —  Signature by which the given instance can be referenced later

[ Top ]

statusMessage   [line 1764]

string statusMessage( [int|array $value = null])

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

Parameters:

int|array   $value   —  integer status code,

[ Top ]

storageFactory   [line 619]

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

Returns an instance of a storage Container class.
  • 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
string   $classprefix   —  Prefix of the class that will be used.

[ Top ]

updateProperty   [line 1702]

bool updateProperty( bool $auth, [bool $perm = null])

Updates the properties of the containers from the original source.
  • Return: true on success and false on failure
  • Access: public

Parameters:

bool   $auth   —  if the auth container should be updated
bool   $perm   —  if the perm container should be updated

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:40:13 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.