Class TUserManager

Description

Implements interfaces:

TUserManager class

TUserManager manages a static list of users TUser. The user information is specified via module configuration using the following XML syntax,

  1.  <module id="users" class="System.Security.TUserManager" PasswordMode="Clear">
  2.    <user name="Joe" password="demo" />
  3.    <user name="John" password="demo" />
  4.    <role name="Administrator" users="John" />
  5.    <role name="Writer" users="Joe,John" />
  6.  </module>

PHP configuration style:

  1.  array(
  2.    'users' => array(
  3.       'class' => 'System.Security.TUserManager',
  4.       'properties' => array(
  5.          'PasswordMode' => 'Clear',
  6.        ),
  7.        'users' => array(
  8.           array('name'=>'Joe','password'=>'demo'),
  9.           array('name'=>'John','password'=>'demo'),
  10.        ),
  11.        'roles' => array(
  12.           array('name'=>'Administrator','users'=>'John'),
  13.           array('name'=>'Writer','users'=>'Joe,John'),
  14.        ),
  15.     ),
  16.  )

In addition, user information can also be loaded from an external file specified by UserFile property. Note, the property only accepts a file path in namespace format. The user file format is similar to the above sample.

The user passwords may be specified as clear text, SH1 or MD5 hashed by setting PasswordMode as Clear, SHA1 or MD5. The default name for a guest user is Guest. It may be changed by setting GuestName property.

TUserManager may be used together with TAuthManager which manages how users are authenticated and authorized in a Prado application.

Located in /Security/TUserManager.php (line 71)

TComponent
   |
   --TApplicationComponent
      |
      --TModule
         |
         --TUserManager
Class Constant Summary
 USER_FILE_EXT = '.xml'
Method Summary
string getGuestName ()
array getRoles ()
TUser getUser ([string $username = null])
string getUserFile ()
array getUsers ()
void init (mixed $config)
void saveUserToCookie (THttpCookie $cookie)
void setGuestName (string $value)
void setUserFile (string $value)
void switchToGuest (TUser $user)
boolean validateUser (string $username, string $password)
Methods
getGuestName (line 258)
  • return: guest name, defaults to 'Guest'
  • access: public
string getGuestName ()

Implementation of:
IUserManager::getGuestName()
getPasswordMode (line 274)
  • return: how password is stored, clear text, or MD5 or SHA1 hashed. Default to TUserManagerPasswordMode::MD5.
  • access: public
TUserManagerPasswordMode getPasswordMode ()
getRoles (line 228)

Returns an array of user role information.

Each array element represents the roles for a single user. The array key is the username in lower case, and the array value is the roles (represented as an array) that the user is in.

  • return: list of user role information
  • access: public
array getRoles ()
getUser (line 308)

Returns a user instance given the user name.

  • return: the user instance, null if the specified username is not in the user database.
  • access: public
TUser getUser ([string $username = null])
  • string $username: user name, null if it is a guest.

Redefinition of:
TApplicationComponent::getUser()

Implementation of:
IUserManager::getUser()
Returns a user instance given the user name.
getUserFile (line 236)
  • return: the full path to the file storing user/role information
  • access: public
string getUserFile ()
getUserFromCookie (line 339)

Returns a user instance according to auth data stored in a cookie.

  • return: the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
  • since: 3.1.1
  • access: public
TUser getUserFromCookie (THttpCookie $cookie)
  • THttpCookie $cookie: the cookie storing user authentication information

Implementation of:
IUserManager::getUserFromCookie()
Returns a user instance according to auth data stored in a cookie.
getUsers (line 216)

Returns an array of all users.

Each array element represents a single user. The array key is the username in lower case, and the array value is the corresponding user password.

  • return: list of users
  • access: public
array getUsers ()
init (line 109)

Initializes the module.

This method is required by IModule and is invoked by application. It loads user/role information from the module configuration.

  • access: public
void init (mixed $config)
  • mixed $config: module configuration

Redefinition of:
TModule::init()
Initializes the module.
saveUserToCookie (line 359)

Saves user auth data into a cookie.

  • since: 3.1.1
  • access: public
void saveUserToCookie (THttpCookie $cookie)
  • THttpCookie $cookie: the cookie to receive the user auth data.

Implementation of:
IUserManager::saveUserToCookie()
Saves user auth data into a cookie.
setGuestName (line 266)
  • access: public
void setGuestName (string $value)
  • string $value: name to be used for guest users.
setPasswordMode (line 282)
  • access: public
void setPasswordMode (TUserManagerPasswordMode $value)
setUserFile (line 247)
  • throws: TConfigurationException if the file is not in proper namespace format
  • throws: TInvalidOperationException if the module is already initialized
  • access: public
void setUserFile (string $value)
  • string $value: user/role data file path (in namespace form). The file format is XML whose content is similar to that user/role block in application configuration.
switchToGuest (line 375)

Sets a user as a guest.

User name is changed as guest name, and roles are emptied.

  • access: public
void switchToGuest (TUser $user)
  • TUser $user: the user to be changed to a guest.
validateUser (line 293)

Validates if the username and password are correct.

  • return: true if validation is successful, false otherwise.
  • access: public
boolean validateUser (string $username, string $password)
  • string $username: user name
  • string $password: password

Implementation of:
IUserManager::validateUser()
Validates if the username and password are correct.

Inherited Methods

Inherited From TModule

TModule::getID()
TModule::init()
TModule::setID()

Inherited From TApplicationComponent

TApplicationComponent::getApplication()
TApplicationComponent::getRequest()
TApplicationComponent::getResponse()
TApplicationComponent::getService()
TApplicationComponent::getSession()
TApplicationComponent::getUser()
TApplicationComponent::publishAsset()
TApplicationComponent::publishFilePath()

Inherited From TComponent

TComponent::addParsedObject()
TComponent::attachEventHandler()
TComponent::canGetProperty()
TComponent::canSetProperty()
TComponent::createdOnTemplate()
TComponent::detachEventHandler()
TComponent::evaluateExpression()
TComponent::evaluateStatements()
TComponent::getEventHandlers()
TComponent::getSubProperty()
TComponent::hasEvent()
TComponent::hasEventHandler()
TComponent::hasProperty()
TComponent::raiseEvent()
TComponent::setSubProperty()
TComponent::__call()
TComponent::__get()
TComponent::__set()
TComponent::__sleep()
TComponent::__wakeup()
Class Constants
USER_FILE_EXT = '.xml' (line 76)

extension name to the user file

Documentation generated on Mon, 25 Jun 2012 14:39:33 +0200 by phpDocumentor 1.4.3