Class \Prado\Security\TUserManager
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="Prado\Security\TUserManager" PasswordMode="Clear">
<user name="Joe" password="demo" />
<user name="John" password="demo" />
<user name="Jerry" password="demo" roles="Writer,Administrator" />
<role name="Administrator" users="John" />
<role name="Writer" users="Joe,John" />
</module>
PHP configuration style:
array(
'users' => array(
'class' => 'Prado\Security\TUserManager',
'properties' => array(
'PasswordMode' => 'Clear',
),
'users' => array(
array('name'=>'Joe','password'=>'demo'),
array('name'=>'John','password'=>'demo'),
array('name'=>'Jerry','password'=>'demo','roles'=>'Administrator,Writer'),
),
'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 \Prado\Security\setUserFile 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 \Prado\Security\setPasswordMode as Clear, SHA1 or MD5. The default name for a guest user is Guest. It may be changed by setting \Prado\Security\setGuestName property.
TUserManager may be used together with TAuthManager which manages how users are authenticated and authorized in a Prado application.
Class hierarchy
- \Prado\Security\TUserManager implements IUserManager
- \Prado\TModule implements IModule
- \Prado\TApplicationComponent
- \Prado\TComponent
Author: Carl Mathisen <carl@kamikazemedia.no>
Since: 3.0
public
|
|
public
|
|
public
|
getRoles() : array<string|int, mixed>
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. |
public
|
|
public
|
|
public
|
getUserFromCookie(THttpCookie $cookie) : TUser
Returns a user instance according to auth data stored in a cookie.
|
public
|
getUsers() : array<string|int, mixed>
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. |
public
|
init(mixed $config) : mixed
Initializes the module.
This method is required by IModule and is invoked by application. It loads user/role information from the module configuration. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
validateUser(string $username, string $password) : bool
Validates if the username and password are correct.
|
private
|
|
private
|
loadUserDataFromPhp(array<string|int, mixed> $config) : mixed
Loads user/role information from an php array.
|
private
|
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |