PHP Class Prado\Security\TUserManager

TUserManager manages a static list of users {@link TUser}. The user information is specified via module configuration using the following XML syntax, PHP configuration style: array( 'users' => array( 'class' => 'System.Security.TUserManager', 'properties' => array( 'PasswordMode' => 'Clear', ), 'users' => array( array('name'=>'Joe','password'=>'demo'), array('name'=>'John','password'=>'demo'), ), '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 {@link setUserFile 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 {@link setPasswordMode PasswordMode} as Clear, SHA1 or MD5. The default name for a guest user is Guest. It may be changed by setting {@link setGuestName GuestName} property. TUserManager may be used together with {@link TAuthManager} which manages how users are authenticated and authorized in a Prado application.
Since: 3.0
Author: Qiang Xue ([email protected])
Author: Carl Mathisen ([email protected])
Inheritance: extends Prado\TModule, implements IUserManager
Exibir arquivo Open project: pradosoft/prado Class Usage Examples

Public Methods

Method Description
getGuestName ( ) : string
getPasswordMode ( ) : TUserManagerPasswordMode
getRoles ( ) : array Returns an array of user role information.
getUser ( $username = null ) : TUser Returns a user instance given the user name.
getUserFile ( ) : string
getUserFromCookie ( $cookie ) : TUser Returns a user instance according to auth data stored in a cookie.
getUsers ( ) : array Returns an array of all users.
init ( $config ) Initializes the module.
saveUserToCookie ( $cookie ) Saves user auth data into a cookie.
setGuestName ( $value )
setPasswordMode ( $value )
setUserFile ( $value )
switchToGuest ( $user ) Sets a user as a guest.
validateUser ( $username, $password ) : boolean Validates if the username and password are correct.

Private Methods

Method Description
loadUserData ( $config ) * Loads user/role information
loadUserDataFromPhp ( $config ) Loads user/role information from an php array.
loadUserDataFromXml ( $xmlNode ) Loads user/role information from an XML node.

Method Details

getGuestName() public method

public getGuestName ( ) : string
return string guest name, defaults to 'Guest'

getPasswordMode() public method

public getPasswordMode ( ) : TUserManagerPasswordMode
return TUserManagerPasswordMode how password is stored, clear text, or MD5 or SHA1 hashed. Default to TUserManagerPasswordMode::MD5.

getRoles() public method

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 getRoles ( ) : array
return array list of user role information

getUser() public method

Returns a user instance given the user name.
public getUser ( $username = null ) : TUser
return TUser the user instance, null if the specified username is not in the user database.

getUserFile() public method

public getUserFile ( ) : string
return string the full path to the file storing user/role information

getUserFromCookie() public method

Returns a user instance according to auth data stored in a cookie.
Since: 3.1.1
public getUserFromCookie ( $cookie ) : TUser
return TUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.

getUsers() public method

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 getUsers ( ) : array
return array list of users

init() public method

This method is required by IModule and is invoked by application. It loads user/role information from the module configuration.
public init ( $config )

saveUserToCookie() public method

Saves user auth data into a cookie.
Since: 3.1.1
public saveUserToCookie ( $cookie )

setGuestName() public method

public setGuestName ( $value )

setPasswordMode() public method

public setPasswordMode ( $value )

setUserFile() public method

public setUserFile ( $value )

switchToGuest() public method

User name is changed as guest name, and roles are emptied.
public switchToGuest ( $user )

validateUser() public method

Validates if the username and password are correct.
public validateUser ( $username, $password ) : boolean
return boolean true if validation is successful, false otherwise.