PHP Class Contao\User

The class supports user authentication, login and logout, persisting the session data and initializing the user object from a database row. It functions as abstract parent class for the "BackendUser" and "FrontendUser" classes of the core. Usage: $user = BackendUser::getInstance(); if ($user->findBy('username', 'leo')) { echo $user->name; }
Inheritance: extends System
Exibir arquivo Open project: contao/core-bundle Class Usage Examples

Protected Properties

Property Type Description
$arrData array Data
$intId integer User ID
$objInstance User Object instance (Singleton)
$strCookie string Cookie name
$strHash string Authentication hash
$strIp string IP address
$strTable string Table

Public Methods

Method Description
__clone ( ) Prevent cloning of the object (Singleton)
__get ( string $strKey ) : mixed Return an object property
__isset ( string $strKey ) : boolean Check whether a property is set
__set ( string $strKey, mixed $varValue ) Set an object property
__toString ( ) : string Get a string representation of the user
authenticate ( ) : boolean Authenticate a user
findBy ( string $strColumn, mixed $varValue ) : boolean Find a user in the database
getData ( ) : array Return the current record as associative array
getInstance ( ) : static Instantiate a new user object (Factory)
getTable ( ) : string Return the table name
isMemberOf ( integer $id ) : boolean Return true if the user is member of a particular group
login ( ) : boolean Try to login the current user
logout ( ) : boolean Remove the authentication cookie and destroy the current session
save ( ) Update the current record

Protected Methods

Method Description
__construct ( ) Import the database object
checkAccountStatus ( ) : boolean Check the account status and return true if it is active
generateSession ( ) Generate a session
regenerateSessionId ( ) Regenerate the session ID
setUserFromDb ( ) Set all user properties from a database record

Method Details

__clone() final public method

Prevent cloning of the object (Singleton)
final public __clone ( )

__construct() protected method

Import the database object
protected __construct ( )

__get() public method

Return an object property
public __get ( string $strKey ) : mixed
$strKey string The property name
return mixed The property value

__isset() public method

Check whether a property is set
public __isset ( string $strKey ) : boolean
$strKey string The property name
return boolean True if the property is set

__set() public method

Set an object property
public __set ( string $strKey, mixed $varValue )
$strKey string The property name
$varValue mixed The property value

__toString() public method

Get a string representation of the user
public __toString ( ) : string
return string The string representation

authenticate() public method

Authenticate a user
public authenticate ( ) : boolean
return boolean True if the user could be authenticated

checkAccountStatus() protected method

Check the account status and return true if it is active
protected checkAccountStatus ( ) : boolean
return boolean True if the account is active

findBy() public method

Find a user in the database
public findBy ( string $strColumn, mixed $varValue ) : boolean
$strColumn string The field name
$varValue mixed The field value
return boolean True if the user was found

generateSession() protected method

Generate a session
protected generateSession ( )

getData() public method

Return the current record as associative array
public getData ( ) : array
return array

getInstance() public static method

Instantiate a new user object (Factory)
public static getInstance ( ) : static
return static The object instance

getTable() public method

Return the table name
public getTable ( ) : string
return string

isMemberOf() public method

Return true if the user is member of a particular group
public isMemberOf ( integer $id ) : boolean
$id integer The group ID
return boolean True if the user is a member of the group

login() public method

Try to login the current user
public login ( ) : boolean
return boolean True if the user could be logged in

logout() public method

Remove the authentication cookie and destroy the current session
public logout ( ) : boolean
return boolean True if the user could be logged out

regenerateSessionId() protected method

Regenerate the session ID
protected regenerateSessionId ( )

save() public method

Update the current record
public save ( )

setUserFromDb() abstract protected method

Set all user properties from a database record
abstract protected setUserFromDb ( )

Property Details

$arrData protected_oe property

Data
protected array $arrData
return array

$intId protected_oe property

User ID
protected int $intId
return integer

$objInstance protected_oe static_oe property

Object instance (Singleton)
protected static User,contao $objInstance
return User

$strCookie protected_oe property

Cookie name
protected string $strCookie
return string

$strHash protected_oe property

Authentication hash
protected string $strHash
return string

$strIp protected_oe property

IP address
protected string $strIp
return string

$strTable protected_oe property

Table
protected string $strTable
return string