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

Class: LiveUser

Source Location: /LiveUser-0.13.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.119 2004/09/14 19:37:53 arnaud Exp $

Methods


Inherited Variables

Inherited Methods


Class Details

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


Method Detail

LiveUser (Constructor)   [line 290]

void LiveUser( )

Constructor
  • Access: protected

[ Top ]

addErrorLog   [line 665]

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

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

object|false &authFactory( array|file $conf)

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.

[ Top ]

checkRight   [line 1434]

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

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

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

boolean disconnect( )

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

[ Top ]

factory   [line 410]

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.   'login' => array(
  8.       'method'   => 'request, get or post',
  9.       'username' => 'Form input containing user handle',
  10.       'password' => 'Form input containing password',
  11.       'remember' => '(optional) Form checkbox containing <Remember Me> info',
  12.       'function' => '(optional) Function to be called when accessing a page without logging in first',
  13.       'force'    => 'Should the user be forced to login'
  14.       'regenid'  => 'Should the session be regenerated on login'
  15.   ),
  16.   'logout' => array(
  17.       'method'   => 'request, get or post',
  18.       'trigger'  => 'REQUEST, GET or POST var that triggers the logout process',
  19.       'redirect' => 'Page path to be redirected to after logout',
  20.       'function' => '(optional) Function to be called when accessing a page without logging in first',
  21.       'destroy'  => 'Whether to destroy the session on logout' false or true
  22.   ),
  23.  // The cookie options are optional. If they are specified, the Remember Me
  24.  // feature is activated.
  25.   'cookie' => array(
  26.       'name'     => 'Name of Remember Me cookie',
  27.       'lifetime' => 'Cookie lifetime in days',
  28.       'path'     => 'Cookie path',
  29.       'domain'   => 'Cookie domain',
  30.       'secret'   => 'Secret key used for cookie value encryption',
  31.       'savedir'  => '/absolute/path/to/writeable/directory' // No / at the end !
  32.   ),
  33.   'authContainers' => array(
  34.       'name' => array(
  35.             'type' => 'DB',
  36.             'connection'    => 'db connection object, use this or dsn',
  37.             'dsn'           => 'database dsn, use this or connection',
  38.             'loginTimeout'  => 0,
  39.             'expireTime'    => 3600,
  40.             'idleTime'      => 1800,
  41.             'allowDuplicateHandles' => 0,
  42.             'authTable'     => 'liveuser_users',
  43.             'authTableCols' => array(
  44.                 'required' => array(
  45.                     'auth_user_id' => array('type' => 'text''name' => 'user_id'),
  46.                     'handle'       => array('type' => 'text''name' => 'handle'),
  47.                     'passwd'       => array('type' => 'text''name' => 'passwd')
  48.                 ),
  49.                 'optional' => array(
  50.                     'owner_user_id'  => array('type' => 'integer''name' => 'owner_user_id'),
  51.                     'owner_group_id' => array('type' => 'integer''name' => 'owner_group_id')
  52.                     'lastlogin'    => array('type' => 'timestamp''name' => 'lastlogin'),
  53.                     'is_active'    => array('type' => 'boolean''name' => 'is_active')
  54.                 ),
  55.                 'custom'   => array(
  56.                     'myaliasforfield1' => array('type' => 'text''name' => 'myfield1')
  57.                 )
  58.            )
  59.       )
  60.   ),
  61.   'permContainer' => array(
  62.       'type'       => 'DB_Complex',
  63.       'connection' => 'db connection object, use this or dsn',
  64.       'dsn'        => 'database dsn, use this or connection',
  65.       'prefix'     => 'liveuser_',
  66.       'groupTableCols' => array(
  67.           'required' => array(
  68.               'group_id' => array('type' => 'integer''name' => 'group_id')
  69.               'group_define_name' => array('type' => 'text''name' => 'group_define_name')
  70.           ),
  71.           'optional' => array(
  72.               'group_type'    => array('type' => 'integer''name' => 'group_type')
  73.               'is_active'    => array('type' => 'boolean''name' => 'is_active')
  74.               'owner_user_id'  => array('type' => 'integer''name' => 'owner_user_id'),
  75.               'owner_group_id' => array('type' => 'integer''name' => 'owner_group_id')
  76.           ),
  77.           'custom'   => array(
  78.               'myaliasforfield1' => array('type' => 'text''name' => 'myfield1')
  79.           )
  80.   )

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

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

boolean freeze( )

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

[ Top ]

getAuthContainer   [line 764]

mixed &getAuthContainer( )

Get the Auth Container class instance of it exists
  • Return: object or PEAR Error
  • Access: public

[ Top ]

getOption   [line 749]

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 ]

getPermContainer   [line 778]

mixed &getPermContainer( )

Get the Perm Container class instance if it exists
  • Return: object or false on failure
  • Access: public

[ Top ]

getProperty   [line 1583]

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

integer getStatus( )

Get the current status.
  • Access: public

[ Top ]

init   [line 802]

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 ]

isError   [line 1612]

bool isError( mixed $value)

Tell whether a result from a LiveUser method is an error.
  • Return: whether value is an error
  • Access: public

Parameters:

mixed   $value   —  result code

[ Top ]

isInactive   [line 1519]

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

boolean isLoggedIn( )

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

[ Top ]

loadClass   [line 492]

boolean loadClass( string $classname)

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

Parameters:

string   $classname   —  classname

[ Top ]

logout   [line 1362]

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

object|false &permFactory( mixed $conf)

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.

[ Top ]

setLoginFunction   [line 1537]

boolean setLoginFunction( string $functionName)

Sets a callback login function.

The user can set a function that will be called if the user tries to access a page wihout logging in first. It will receive the liveuser object. If an empty string or a non-existent function is passed it deactivates the call.

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

Parameters:

string   $functionName   —  The name of the function to be called.

[ Top ]

setLogoutFunction   [line 1563]

boolean setLogoutFunction( string $functionName)

Sets a callback logout function.

The user can set a function that will be called if the user wants to logout (by providing the appropriate GET-parameter). If an empty string or a non-existent function is passed it deactivates the call. Attention: Don't use a die() or exit() statement in your logout function. Otherwise the user can't be logged out properly.

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

Parameters:

string   $functionName   —  The name of the function to be called.

[ Top ]

setOption   [line 732]

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

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

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 ]

__toString   [line 1624]

string __toString( )

make a string representation of the object
  • Access: public

[ Top ]


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