PHP Класс Elgg\PersistentLoginService

If a user selects a persistent login, a long, random token is generated and stored in the cookie called "elggperm", and a hash of the token is stored in the DB. If the user's PHP session expires, the session boot sequence will try to log the user in via the token in the cookie. Before Elgg 1.9, the token hashes were stored as "code" in the users_entity table. In Elgg 1.9, the token hashes are stored as "code" in the users_remember_me_cookies table, allowing multiple browsers to maintain persistent logins.
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$_callable_elgg_set_cookie DO NOT USE. For unit test mocking
$_callable_get_user DO NOT USE. For unit test mocking
$_callable_sleep DO NOT USE. For unit test mocking

Защищенные свойства (Protected)

Свойство Тип Описание
$cookie_config array
$cookie_token string
$crypto ElggCrypto
$db Database
$session ElggSession
$table string
$time integer

Открытые методы

Метод Описание
__construct ( Database $db, ElggSession $session, ElggCrypto $crypto, array $cookie_config, string $cookie_token, integer $time = null ) Constructor
bootSession ( ) : ElggUser | null Boot the persistent login session, possibly returning the user who should be silently logged in.
getUserFromHash ( string $hash ) : ElggUser | null Find a user with the given hash
handlePasswordChange ( ElggUser $subject, ElggUser $modifier = null ) : void Handle a password change
makeLoginPersistent ( ElggUser $user ) : void Make the user's login persistent
removePersistentLogin ( ) : void Remove the persisted login token from client and server
replaceLegacyToken ( ElggUser $logged_in_user ) : void Replace the user's token if it's a legacy hexadecimal token

Защищенные методы

Метод Описание
generateToken ( ) : string Generate a random token (base 64 URL)
handleDbException ( DatabaseException $exception, string $default = null ) : mixed Swallow a schema not upgraded exception, otherwise rethrow it
hashToken ( string $token ) : string Create a hash from the token
isLegacyToken ( string $token ) : boolean Is the given token a legacy MD5 hash?
removeAllHashes ( ElggUser $user ) : void Remove all the hashes associated with a user
removeHash ( string $hash ) : void Remove a hash from the DB
setCookie ( string $token ) : void Store the token in the client cookie (or remove the cookie)
setSession ( string $token ) : void Store the token in the session (or remove it from the session)
storeHash ( ElggUser $user, string $hash ) : void Store a hash in the DB

Описание методов

__construct() публичный Метод

Constructor
public __construct ( Database $db, ElggSession $session, ElggCrypto $crypto, array $cookie_config, string $cookie_token, integer $time = null )
$db Database The DB service
$session ElggSession The Elgg session
$crypto ElggCrypto The cryptography service
$cookie_config array The persistent login cookie settings
$cookie_token string The token from the request cookie
$time integer The current time

bootSession() публичный Метод

Boot the persistent login session, possibly returning the user who should be silently logged in.
public bootSession ( ) : ElggUser | null
Результат ElggUser | null

generateToken() защищенный Метод

The first char is always "z" to indicate the value has more entropy than the previously generated ones.
protected generateToken ( ) : string
Результат string

getUserFromHash() публичный Метод

Find a user with the given hash
public getUserFromHash ( string $hash ) : ElggUser | null
$hash string The hashed token
Результат ElggUser | null

handleDbException() защищенный Метод

Swallow a schema not upgraded exception, otherwise rethrow it
protected handleDbException ( DatabaseException $exception, string $default = null ) : mixed
$exception DatabaseException The exception to handle
$default string The value to return if the table doesn't exist yet
Результат mixed

handlePasswordChange() публичный Метод

Handle a password change
public handlePasswordChange ( ElggUser $subject, ElggUser $modifier = null ) : void
$subject ElggUser The user whose password changed
$modifier ElggUser The user who changed the password
Результат void

hashToken() защищенный Метод

Create a hash from the token
protected hashToken ( string $token ) : string
$token string The token to hash
Результат string

isLegacyToken() защищенный Метод

Is the given token a legacy MD5 hash?
protected isLegacyToken ( string $token ) : boolean
$token string The token to analyze
Результат boolean

makeLoginPersistent() публичный Метод

Make the user's login persistent
public makeLoginPersistent ( ElggUser $user ) : void
$user ElggUser The user who logged in
Результат void

removeAllHashes() защищенный Метод

Remove all the hashes associated with a user
protected removeAllHashes ( ElggUser $user ) : void
$user ElggUser The user for whom we're removing hashes
Результат void

removeHash() защищенный Метод

Remove a hash from the DB
protected removeHash ( string $hash ) : void
$hash string The hashed token to remove (unused before 1.9)
Результат void

removePersistentLogin() публичный Метод

Remove the persisted login token from client and server
public removePersistentLogin ( ) : void
Результат void

replaceLegacyToken() публичный Метод

Replace the user's token if it's a legacy hexadecimal token
public replaceLegacyToken ( ElggUser $logged_in_user ) : void
$logged_in_user ElggUser The logged in user
Результат void

setCookie() защищенный Метод

Store the token in the client cookie (or remove the cookie)
protected setCookie ( string $token ) : void
$token string Empty string to remove cookie
Результат void

setSession() защищенный Метод

Store the token in the session (or remove it from the session)
protected setSession ( string $token ) : void
$token string The token to store in session. Empty string to remove.
Результат void

storeHash() защищенный Метод

Store a hash in the DB
protected storeHash ( ElggUser $user, string $hash ) : void
$user ElggUser The user for whom we're storing the hash
$hash string The hashed token
Результат void

Описание свойств

$_callable_get_user публичное свойство

DO NOT USE. For unit test mocking
public $_callable_get_user

$_callable_sleep публичное свойство

DO NOT USE. For unit test mocking
public $_callable_sleep

$crypto защищенное свойство

protected ElggCrypto $crypto
Результат ElggCrypto

$db защищенное свойство

protected Database,elgg $db
Результат Database

$session защищенное свойство

protected ElggSession $session
Результат ElggSession

$table защищенное свойство

protected string $table
Результат string

$time защищенное свойство

protected int $time
Результат integer