RdbAdmin Module

SessionsTrait

User login sessions trait.

Tags
since
0.1

Table of Contents

Properties

$totalLoggedInSessions  : int
$userSessionCookieData  : array<string|int, mixed>

Methods

isUserLoggedIn()  : bool
Check if user is logged in.
sessionTraitLogoutAll()  : mixed
Logout all succeeded login sessions, lock user account, send login link to user's email.
sessionsTraitCheckIsLoggedInFromContainer()  : array<string|int, mixed>
Check is logged in from container if exists.
sessionTraitLogoutPreviousSessions()  : mixed
Logout all sessions before latest succeeded login. (logout only succeeded login).

Properties

$totalLoggedInSessions

protected int $totalLoggedInSessions = 0

The number of sessions that found this user logged in. This property is able to access after called to isUserLoggedIn() method.

$userSessionCookieData

protected array<string|int, mixed> $userSessionCookieData = []

The cookie data of logged in user. This property is able to access after called to isUserLoggedIn() method.

Methods

isUserLoggedIn()

Check if user is logged in.

protected isUserLoggedIn([int $user_id = null ][, string $userlogin_session_key = '' ]) : bool

After called this method and it was true then you can access total sessions via totalLoggedInSessions property.
After called this method and cookie is valid then you can access cookie data via userSessionCookieData property.
If there is simultaneous login and user's setting is something that is not allowed (such as logout previous, logout all), it will be process here.

Parameters
$user_id : int = null

The user ID. Set to null (default) to auto detect from cookie.

$userlogin_session_key : string = ''

The logged in session key. Set to empty string (default) to auto detect from cookie.

Return values
bool

Return true if logged in, false for not.

sessionTraitLogoutAll()

Logout all succeeded login sessions, lock user account, send login link to user's email.

protected sessionTraitLogoutAll(int $user_id, UserLoginsDb $UserLoginsDb, UserFieldsDb $UserFieldsDb) : mixed

This method also set cache that email was sent recently.
This method was called from isUserLoggedIn().
This method was called from LoginController->doLogin().

Parameters
$user_id : int
$UserLoginsDb : UserLoginsDb
$UserFieldsDb : UserFieldsDb

sessionsTraitCheckIsLoggedInFromContainer()

Check is logged in from container if exists.

private sessionsTraitCheckIsLoggedInFromContainer() : array<string|int, mixed>

The check data in container must not older than N seconds.

Tags
since
1.2.9
Return values
array<string|int, mixed>

Return indexed array where first index is UsersSessionsTrait object in the container if exists. This value can be null.
Second index is result of "is logged in". This value can be null.

sessionTraitLogoutPreviousSessions()

Logout all sessions before latest succeeded login. (logout only succeeded login).

private sessionTraitLogoutPreviousSessions(int $user_id, UserLoginsDb $UserLoginsDb) : mixed

This method was called from isUserLoggedIn().

Parameters
$user_id : int
$UserLoginsDb : UserLoginsDb

        
On this page

Search results