Class TDbUserManager
TDbUserManager class
TDbUserManager manages user accounts that are stored in a database. TDbUserManager is mainly designed to be used together with TAuthManager which manages how users are authenticated and authorized in a Prado application. To use TDbUserManager together with TAuthManager, configure them in the application configuration like following: - <module id="db"
- class="System.Data.TDataSourceConfig" ..../>
- <module id="users"
- class="System.Security.TDbUserManager"
- UserClass="Path.To.MyUserClass"
- ConnectionID="db" />
- <module id="auth"
- class="System.Security.TAuthManager"
- UserManager="users" LoginPage="Path.To.LoginPage" />
In the above, UserClass specifies what class will be used to create user instance. The class must extend from TDbUser. ConnectionID refers to the ID of a TDataSourceConfig module which specifies how to establish database connection to retrieve user information.
Method Summary |
protected
TDbConnection
|
Creates the DB connection.
|
string
|
|
TDbConnection
|
|
string
|
|
TUser
|
Returns a user instance given the user name.
|
string
|
|
TDbUser
|
Returns a user instance according to auth data stored in a cookie.
|
void
|
Initializes the module.
|
void
|
Saves user auth data into a cookie.
|
void
|
Sets the ID of a TDataSourceConfig module.
|
void
|
|
void
|
|
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()
|
Method Details |
createDbConnection
protected TDbConnection createDbConnection |
(string $connectionID ) |
Creates the DB connection.
Input |
string | $connectionID | the module ID for TDataSourceConfig |
Output |
TDbConnection
| the created DB connection |
Exception |
throws | TConfigurationException if module ID is invalid or empty |
|
getConnectionID
public string getConnectionID |
() |
Output |
string
| the ID of a TDataSourceConfig module. Defaults to empty string, meaning not set. |
Exception |
|
getDbConnection
Output |
TDbConnection
| the database connection that may be used to retrieve user data. |
Exception |
|
getGuestName
public string getGuestName |
() |
Output |
string
| guest name, defaults to 'Guest' |
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 |
|
getUserClass
public string getUserClass |
() |
Output |
string
| the user class name in namespace format. Defaults to empty string, meaning not set. |
Exception |
|
getUserFromCookie
Returns a user instance according to auth data stored in a cookie.
Input |
THttpCookie | $cookie | the cookie storing user authentication information |
Output |
TDbUser
| the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data. |
Exception |
|
init
Initializes the module.
This method is required by IModule and is invoked by application.
Input |
TXmlElement | $config | module configuration |
Output |
Exception |
|
saveUserToCookie
Saves user auth data into a cookie.
Input |
THttpCookie | $cookie | the cookie to receive the user auth data. |
Output |
Exception |
|
setConnectionID
public void setConnectionID |
(string $value ) |
Sets the ID of a TDataSourceConfig module.
The datasource module will be used to establish the DB connection that will be used by the user manager.
Input |
string | $value | module ID. |
Output |
Exception |
|
setGuestName
public void setGuestName |
(string $value ) |
Input |
string | $value | name to be used for guest users. |
Output |
Exception |
|
setUserClass
public void setUserClass |
(string $value ) |
Input |
string | $value | the user class name in namespace format. The user class must extend from TDbUser. |
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 |
|
|