- Home
- About
- Testimonials
- Demos
- Download
- Documentation
- Blogs
- Forum
- Support

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: IUserManager TAuthManager TAuthorizationRule TAuthorizationRuleCollection TDbUser TDbUserManager TSecurityManager TSecurityManagerValidationMode TUser TUserManager TUserManagerPasswordMode |
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,

     <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>
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 | getGuestName ()
TUserManagerPasswordMode | getPasswordMode ()
array | getRoles () Returns an array of user role information.
TUser | getUser ( string $username) Returns a user instance given the user name.
string | getUserFile ()
TUser | getUserFromCookie ( THttpCookie $cookie) Returns a user instance according to auth data stored in a cookie.
array | getUsers () Returns an array of all users.
void | init ( TXmlElement $config) Initializes the module.
protected void | loadUserData ( TXmlElement $xmlNode) Loads user/role information from an XML node.
void | saveUserToCookie ( THttpCookie $cookie) Saves user auth data into a cookie.
void | setGuestName ( string $value)
void | setPasswordMode ( TUserManagerPasswordMode $value)
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 | $username | user 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 | $cookie | the 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 | $config | module configuration
Output
Exception
## loadUserData
protected void loadUserData | (TXmlElement $xmlNode )
Loads user/role information from an XML node.
Input
TXmlElement | $xmlNode | the XML node containing the user information
Output
Exception
## saveUserToCookie
public void saveUserToCookie | (THttpCookie $cookie )
Saves user auth data into a cookie.
Input
THttpCookie | $cookie | the cookie to receive the user auth data.
Output
Exception
## setGuestName
public void setGuestName | (string $value )
Input
string | $value | name to be used for guest users.
Output
Exception
## setPasswordMode
public void setPasswordMode | (TUserManagerPasswordMode $value )
Input
TUserManagerPasswordMode | $value | how password is stored, clear text, or MD5 or SHA1 hashed.
Output
Exception
## setUserFile
public void setUserFile | (string $value )
Input
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.
Output
Exception
throws | TInvalidOperationException if the module is already initialized
throws | TConfigurationException 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 | $user | the 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 | $username | user name
string | $password | password
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'