PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class TUserManager

TUserManager class

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

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

PHP configuration style:

array(
  'users' => array(
     'class' => 'System.Security.TUserManager',
     'properties' => array(
        'PasswordMode' => 'Clear',
      ),
      'users' => array(
         array('name'=>'Joe','password'=>'demo'),
         array('name'=>'John','password'=>'demo'),
      ),
      'roles' => array(
         array('name'=>'Administrator','users'=>'John'),
         array('name'=>'Writer','users'=>'Joe,John'),
      ),
   ),
)

In addition, user information can also be loaded from an external file specified by setUserFile 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 setPasswordMode PasswordMode as Clear, SHA1 or MD5. The default name for a guest user is Guest. It may be changed by setting setGuestName GuestName property.

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

TComponent
Extended by TApplicationComponent
Extended by TModule implements IModule
Extended by TUserManager implements IUserManager
Package: System\Security
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Author: Carl Mathisen <carl@kamikazemedia.no>
Since: 3.0
Located at Security/TUserManager.php
Methods summary
public
# init( mixed $config )

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

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

Parameters

$config
mixed
module configuration

Overrides

TModule::init()
public array
# getUsers( )

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.

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.

Returns

array
list of users
public array
# getRoles( )

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.

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.

Returns

array
list of user role information
public string
# getUserFile( )

Returns

string
the full path to the file storing user/role information
public
# setUserFile( string $value )

Parameters

$value
string
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.

Throws

TInvalidOperationException
if the module is already initialized
TConfigurationException
if the file is not in proper namespace format
public string
# getGuestName( )

Returns

string
guest name, defaults to 'Guest'

Implementation of

IUserManager::getGuestName()
public
# setGuestName( string $value )

Parameters

$value
string
name to be used for guest users.
public TUserManagerPasswordMode
# getPasswordMode( )

Returns

TUserManagerPasswordMode
how password is stored, clear text, or MD5 or SHA1 hashed. Default to TUserManagerPasswordMode::MD5.
public
# setPasswordMode( TUserManagerPasswordMode $value )

Parameters

$value
TUserManagerPasswordMode
how password is stored, clear text, or MD5 or SHA1 hashed.
public boolean
# validateUser( string $username, string $password )

Validates if the username and password are correct.

Validates if the username and password are correct.

Parameters

$username
string
user name
$password
string
password

Returns

boolean
true if validation is successful, false otherwise.

Implementation of

IUserManager::validateUser()
public TUser
# getUser( string $username = null )

Returns a user instance given the user name.

Returns a user instance given the user name.

Parameters

$username
string
user name, null if it is a guest.

Returns

TUser
the user instance, null if the specified username is not in the user database.

Overrides

TApplicationComponent::getUser()

Implementation of

IUserManager::getUser()
public TUser
# getUserFromCookie( THttpCookie $cookie )

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

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

Parameters

$cookie
THttpCookie
the cookie storing user authentication information

Returns

TUser
the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.

Since

3.1.1

Implementation of

IUserManager::getUserFromCookie()
public
# saveUserToCookie( THttpCookie $cookie )

Saves user auth data into a cookie.

Saves user auth data into a cookie.

Parameters

$cookie
THttpCookie
the cookie to receive the user auth data.

Since

3.1.1

Implementation of

IUserManager::saveUserToCookie()
public
# switchToGuest( TUser $user )

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

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

Parameters

$user
TUser
the user to be changed to a guest.
Methods inherited from TModule
getID(), setID()
Methods inherited from TApplicationComponent
getApplication(), getRequest(), getResponse(), getService(), getSession(), publishAsset(), publishFilePath()
Methods inherited from TComponent
__call(), __construct(), __destruct(), __get(), __isset(), __set(), __sleep(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants summary
string USER_FILE_EXT '.xml'
#

extension name to the user file

extension name to the user file

Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO