Packages:
default
System
System.Caching
System.Collections
System.Data
System.Data.ActiveRecord
System.Data.ActiveRecord.Relations
System.Data.ActiveRecord.Scaffold
System.Data.ActiveReecord.Scaffold.InputBuilder
System.Data.Commom.Sqlite
System.Data.Common
System.Data.Common.Mssql
System.Data.Common.Mysql
System.Data.Common.Oracle
System.Data.Common.Pgsql
System.Data.Common.Sqlite
System.Data.DataGateway
System.Data.SqlMap
System.Data.SqlMap.Configuration
System.Data.SqlMap.Statements
System.Exceptions
System.I18N
System.IO
System.Security
System.Util
System.Web
System.Web.Services
System.Web.UI
System.Web.UI.ActiveControls
System.Web.UI.WebControls
System.Web.UI.WebControls.assets
System.Xml


Classes:
Keyword

Class TUserManager

TComponent
   |
   --TApplicationComponent
      |
      --TModule
         |
         --TUserManager

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>

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.

Since: 3.0
Author: Qiang Xue <qiang.xue@gmail.com>

Method Summary
string
TUserManagerPasswordMode
array
Returns an array of user role information.
TUser
getUser ( string $username)
Returns a user instance given the user name.
string
TUser
Returns a user instance according to auth data stored in a cookie.
array
Returns an array of all users.
void
init ( TXmlElement $config)
Initializes the module.
protected  void
Loads user/role information from an XML node.
void
Saves user auth data into a cookie.
void
setGuestName ( string $value)
void
void
setUserFile ( string $value)
void
switchToGuest ( TUser $user)
Sets a user as a guest.
boolean
validateUser ( string $username, string $password)
Validates if the username and password are correct.
Methods Inherited From TModule
TModule::getID(), TModule::init(), TModule::setID()
Methods Inherited From TApplicationComponent
TApplicationComponent::getApplication(), TApplicationComponent::getRequest(), TApplicationComponent::getResponse(), TApplicationComponent::getService(), TApplicationComponent::getSession(), TApplicationComponent::getUser(), TApplicationComponent::publishAsset(), TApplicationComponent::publishFilePath()
Methods 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::__get(), TComponent::__set()

Constant Summary
string USER_FILE_EXT extension name to the user file

Method Details

getGuestName

public string getGuestName ()

Output
string guest name, defaults to 'Guest'
Exception

getPasswordMode

public TUserManagerPasswordMode getPasswordMode ()

Output
TUserManagerPasswordMode how password is stored, clear text, or MD5 or SHA1 hashed. Default to TUserManagerPasswordMode::MD5.
Exception

getRoles

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.

Output
array list of user role information
Exception

getUser

public TUser getUser (string $username )

Returns a user instance given the user name.

Input
string$usernameuser name, null if it is a guest.
Output
TUser the user instance, null if the specified username is not in the user database.
Exception

getUserFile

public string getUserFile ()

Output
string the full path to the file storing user/role information
Exception

getUserFromCookie

public TUser getUserFromCookie (THttpCookie $cookie )

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

Input
THttpCookie$cookiethe cookie storing user authentication information
Output
TUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
Exception

getUsers

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.

Output
array list of users
Exception

init

public void init (TXmlElement $config )

Initializes the module.

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

Input
TXmlElement$configmodule configuration
Output
Exception

loadUserData

protected void loadUserData (TXmlElement $xmlNode )

Loads user/role information from an XML node.

Input
TXmlElement$xmlNodethe XML node containing the user information
Output
Exception

saveUserToCookie

public void saveUserToCookie (THttpCookie $cookie )

Saves user auth data into a cookie.

Input
THttpCookie$cookiethe cookie to receive the user auth data.
Output
Exception

setGuestName

public void setGuestName (string $value )

Input
string$valuename to be used for guest users.
Output
Exception

setPasswordMode

public void setPasswordMode (TUserManagerPasswordMode $value )

Input
TUserManagerPasswordMode$valuehow password is stored, clear text, or MD5 or SHA1 hashed.
Output
Exception

setUserFile

public void setUserFile (string $value )

Input
string$valueuser/role data file path (in namespace form). The file format is XML whose content is similar to that user/role block in application configuration.
Output
Exception
throwsTInvalidOperationException if the module is already initialized
throwsTConfigurationException if the file is not in proper namespace format

switchToGuest

public void switchToGuest (TUser $user )

Sets a user as a guest.

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

Input
TUser$userthe user to be changed to a guest.
Output
Exception

validateUser

public boolean validateUser (string $username , string $password )

Validates if the username and password are correct.

Input
string$usernameuser name
string$passwordpassword
Output
boolean true if validation is successful, false otherwise.
Exception


Constant Details

USER_FILE_EXT

extension name to the user file

Type:

string

Value:

'.xml'