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>
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.
Method Summary |
string
|
|
TUserManagerPasswordMode
|
|
array
|
Returns an array of user role information.
|
TUser
|
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
|
Initializes the module.
|
protected
void
|
Loads user/role information from an XML node.
|
void
|
Saves user auth data into a cookie.
|
void
|
|
void
|
|
void
|
|
void
|
Sets a user as a guest.
|
boolean
|
Validates if the username and password are correct.
|
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
Output |
TUserManagerPasswordMode
| how password is stored, clear text, or MD5 or SHA1 hashed. Default to TUserManagerPasswordMode::MD5. |
Exception |
|
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
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
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
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
Loads user/role information from an XML node.
Input |
TXmlElement | $xmlNode | the XML node containing the user information |
Output |
Exception |
|
saveUserToCookie
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
|
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'
|
|