Personal tools

User

From Utopia MVC

Jump to: navigation, search

User Session Management class, handles login/logout, provides tools to register new users, and manages the user data during the session.

In future it might implement autologin using cookies.

All public methods are static (with the exception of the __get magic method), and the class is supposed to be used as singleton.

Contents

Attributes

m_pInstance

[toc]

private static User $m_pInstance

Holds statically the current User object allowing this class to be used as singleton.

groups

[toc]

public array $groups

The list of groups (strings) the User belongs to.

isGuest

[toc]

public boolean $isGuest=true

Flag identifying non-logged users.

isTemp

[toc]

public boolean $isTemp=false

Flag identifying users logged with temporary passwords.

username

[toc]

public string $username

The Username of the logged user.

ID

[toc]

public int $ID

The numeric ID of the logged user.

moreData

[toc]

private array $moreData

Array used to store all the values retrieved from the user database table and possibly other sources, the values are retrieved through the magic method __get, accessing User::someRandomValue will return User::moreData['someRandomValue'] instead.

salt

[toc]

private string $salt

Used for salting the passwords, to obtain a hashed password use the hashPassword method.

tableName

[toc]

private string $tableName

usernameColumn

[toc]

private string $usernameColumn

passwordColumn

[toc]

private string $passwordColumn

tempPasswordColumn

[toc]

private string $tempPasswordColumn

tableStructure

[toc]

private array $tableStructure

Along with the previous attributes describe the database storage structure.

Methods

getInstance

Factory method

[toc]Description
public static User getInstance (void)

Creates the singleton instance if it didn't exist yet and returns it.

Return Values

Returns the singleton User instance.

__construct

Default constructor, using User::getInstance is recommended.

[toc]Description
public User __construct (void)

Inizialization of the class, attempts to logout if $_GET['action']=='logout' or starts the session if not, also loads configuration values for the class from configurations/User.class.xml.

__get

Magic method retrieving generic values.

[toc]Description
public &__get (string $name)

When loading the User data from the database all the fields are stored in both the specific attributes and the $moreData array, this method returns those values by transforming User::someRandomValue into User::moreData['someRandomValue'].

Parameters
name
the name of the attribute requested.
Return Values

The content of the attribute requested.