LoginTokenManager
in package
implements
LoggerAwareInterface, TranslatorAwareInterface
Uses
LoggerAwareTrait, TranslatorAwareTrait
Class LoginTokenManager
Tags
Interfaces, Classes, Traits and Enums
- LoggerAwareInterface
- TranslatorAwareInterface
- Lightweight translator aware marker interface (used as an alternative to \Laminas\I18n\Translator\TranslatorAwareInterface, which requires an excessive number of methods to be implemented).
Table of Contents
- $browscap : BrowscapInterface
- Browscap
- $browscapCallback : callable
- Callback for creating Browscap so that we can defer the cache access to when it's actually needed.
- $config : Config
- $cookieManager : CookieManager
- $loginTokenService : LoginTokenServiceInterface
- $mailer : Mailer
- $sessionManager : SessionManager
- $themeInitialized : bool
- Has the theme been initialized yet?
- $tokenToUpdate : array<string|int, mixed>|null
- Token data for deferred token update
- $translator : TranslatorInterface
- Translator
- $userService : UserServiceInterface
- $userToWarn : UserEntityInterface|null
- User that needs to receive a warning (or null for no warning needed)
- $viewRenderer : RendererInterface
- __construct() : mixed
- LoginToken constructor.
- createToken() : void
- Create a new login token series
- deleteActiveToken() : void
- Delete a login token from cookies and database
- deleteTokenSeries() : void
- Delete a login token by series. Also destroys sessions associated with the login token.
- deleteUserLoginTokens() : void
- Delete all login tokens for a user. Also destroys sessions associated with the tokens.
- getCookieLifetime() : int
- Get login token cookie lifetime (days)
- getCookieName() : string
- Get login token cookie name
- getTranslator() : TranslatorInterface
- Get translator object.
- getTranslatorLocale() : string
- Get the locale from the translator.
- requestIsFinished() : void
- Event hook -- called after the request has been processed.
- setTranslator() : TranslatorAwareInterface
- Set a translator
- themeIsReady() : void
- Event hook -- called after the theme has initialized.
- tokenLogin() : UserEntityInterface|null
- Authenticate user using a login token cookie
- translate() : string
- Translate a string (or string-castable object)
- translateWithPrefix() : string
- Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.
- createOrRotateToken() : void
- Create a new login token series or rotate login token in given series
- debug() : void
- Log a debug message.
- extractTextDomain() : array<string|int, mixed>
- Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.
- getBrowscap() : BrowscapInterface
- Get Browscap
- getDebugTranslation() : string
- Build a debug-mode translation
- getLoginTokenCookie() : array<string|int, mixed>
- Get login token cookie in array format
- log() : void
- Send a message to the logger.
- logError() : void
- Log an error message.
- logWarning() : void
- Log a warning message.
- sanitizeTranslationKey() : string
- Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.
- sendLoginTokenWarningEmail() : void
- Send email warning to user
- setLoginTokenCookie() : void
- Set login token cookie
- translateString() : string
- Get translation for a string
Properties
$browscap
Browscap
protected
BrowscapInterface
$browscap
= null
$browscapCallback
Callback for creating Browscap so that we can defer the cache access to when it's actually needed.
protected
callable
$browscapCallback
$config
protected
Config
$config
$cookieManager
protected
CookieManager
$cookieManager
$loginTokenService
protected
LoginTokenServiceInterface
$loginTokenService
$mailer
protected
Mailer
$mailer
$sessionManager
protected
SessionManager
$sessionManager
$themeInitialized
Has the theme been initialized yet?
protected
bool
$themeInitialized
= false
$tokenToUpdate
Token data for deferred token update
protected
array<string|int, mixed>|null
$tokenToUpdate
= null
$translator
Translator
protected
TranslatorInterface
$translator
= null
$userService
protected
UserServiceInterface
$userService
$userToWarn
User that needs to receive a warning (or null for no warning needed)
protected
UserEntityInterface|null
$userToWarn
= null
$viewRenderer
protected
RendererInterface
$viewRenderer
Methods
__construct()
LoginToken constructor.
public
__construct(Config $config, UserServiceInterface $userService, LoginTokenServiceInterface $loginTokenService, CookieManager $cookieManager, SessionManager $sessionManager, Mailer $mailer, RendererInterface $viewRenderer, callable $browscapCB) : mixed
Parameters
- $config : Config
-
Configuration
- $userService : UserServiceInterface
-
User database service
- $loginTokenService : LoginTokenServiceInterface
-
Login Token database service
- $cookieManager : CookieManager
-
Cookie manager
- $sessionManager : SessionManager
-
Session manager
- $mailer : Mailer
-
Mailer
- $viewRenderer : RendererInterface
-
View Renderer
- $browscapCB : callable
-
Callback for creating Browscap
Return values
mixed —createToken()
Create a new login token series
public
createToken(UserEntityInterface $user[, string $sessionId = '' ]) : void
Parameters
- $user : UserEntityInterface
-
User
- $sessionId : string = ''
-
Session identifier
Tags
Return values
void —deleteActiveToken()
Delete a login token from cookies and database
public
deleteActiveToken() : void
Return values
void —deleteTokenSeries()
Delete a login token by series. Also destroys sessions associated with the login token.
public
deleteTokenSeries(string $series) : void
Parameters
- $series : string
-
Series to identify the token
Return values
void —deleteUserLoginTokens()
Delete all login tokens for a user. Also destroys sessions associated with the tokens.
public
deleteUserLoginTokens(int $userId) : void
Parameters
- $userId : int
-
User identifier
Return values
void —getCookieLifetime()
Get login token cookie lifetime (days)
public
getCookieLifetime() : int
Return values
int —getCookieName()
Get login token cookie name
public
getCookieName() : string
Return values
string —getTranslator()
Get translator object.
public
getTranslator() : TranslatorInterface
Return values
TranslatorInterface —getTranslatorLocale()
Get the locale from the translator.
public
getTranslatorLocale([string $default = 'en' ]) : string
Parameters
- $default : string = 'en'
-
Default to use if translator absent.
Return values
string —requestIsFinished()
Event hook -- called after the request has been processed.
public
requestIsFinished() : void
Return values
void —setTranslator()
Set a translator
public
setTranslator(TranslatorInterface $translator) : TranslatorAwareInterface
Parameters
- $translator : TranslatorInterface
-
Translator
Return values
TranslatorAwareInterface —themeIsReady()
Event hook -- called after the theme has initialized.
public
themeIsReady() : void
Return values
void —tokenLogin()
Authenticate user using a login token cookie
public
tokenLogin(string $sessionId) : UserEntityInterface|null
Parameters
- $sessionId : string
-
Session identifier
Return values
UserEntityInterface|null —Object representing logged-in user.
translate()
Translate a string (or string-castable object)
public
translate(string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
- $target : string|object|array<string|int, mixed>
-
String to translate or an array of text domain and string to translate
- $tokens : array<string|int, mixed> = []
-
Tokens to inject into the translated string
- $default : string = null
-
Default value to use if no translation is found (null for no default).
- $useIcuFormatter : bool = false
-
Should we use an ICU message formatter instead of the default behavior?
- $fallbackDomains : array<string|int, string> = []
-
Text domains to check if no match is found in the domain specified in $target
Return values
string —translateWithPrefix()
Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.
public
translateWithPrefix(string $prefix, string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
- $prefix : string
-
Translation key prefix
- $target : string|object|array<string|int, mixed>
-
String to translate or an array of text domain and string to translate
- $tokens : array<string|int, mixed> = []
-
Tokens to inject into the translated string
- $default : string = null
-
Default value to use if no translation is found (null for no default).
- $useIcuFormatter : bool = false
-
Should we use an ICU message formatter instead of the default behavior?
- $fallbackDomains : array<string|int, string> = []
-
Text domains to check if no match is found in the domain specified in $target
Return values
string —createOrRotateToken()
Create a new login token series or rotate login token in given series
protected
createOrRotateToken(UserEntityInterface $user[, string $sessionId = '' ][, string $series = '' ][, int|null $expires = null ][, int|null $currentTokenId = null ]) : void
Parameters
- $user : UserEntityInterface
-
User
- $sessionId : string = ''
-
Session identifier
- $series : string = ''
-
Login token series
- $expires : int|null = null
-
Token expiration timestamp or null for default
- $currentTokenId : int|null = null
-
ID of current token to keep intact
Tags
Return values
void —debug()
Log a debug message.
protected
debug(string $msg[, array<string|int, mixed> $context = [] ][, bool $prependClass = true ]) : void
Parameters
- $msg : string
-
Log message
- $context : array<string|int, mixed> = []
-
Log context
- $prependClass : bool = true
-
Prepend class name to message?
Return values
void —extractTextDomain()
Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.
protected
extractTextDomain(string|object|array<string|int, mixed> $target) : array<string|int, mixed>
Parameters
- $target : string|object|array<string|int, mixed>
-
String to translate or an array of text domain and string to translate
Return values
array<string|int, mixed> —getBrowscap()
Get Browscap
protected
getBrowscap() : BrowscapInterface
Return values
BrowscapInterface —getDebugTranslation()
Build a debug-mode translation
protected
getDebugTranslation(string $domain, string $str, array<string|int, mixed> $tokens) : string
Parameters
- $domain : string
-
Text domain
- $str : string
-
String to translate
- $tokens : array<string|int, mixed>
-
Tokens to inject into the translated string
Return values
string —getLoginTokenCookie()
Get login token cookie in array format
protected
getLoginTokenCookie() : array<string|int, mixed>
Return values
array<string|int, mixed> —log()
Send a message to the logger.
protected
log(string $level, string $message[, array<string|int, mixed> $context = [] ][, bool $prependClass = false ]) : void
Parameters
- $level : string
-
Log level
- $message : string
-
Log message
- $context : array<string|int, mixed> = []
-
Log context
- $prependClass : bool = false
-
Prepend class name to message?
Return values
void —logError()
Log an error message.
protected
logError(string $msg[, array<string|int, mixed> $context = [] ][, bool $prependClass = true ]) : void
Parameters
- $msg : string
-
Log message
- $context : array<string|int, mixed> = []
-
Log context
- $prependClass : bool = true
-
Prepend class name to message?
Return values
void —logWarning()
Log a warning message.
protected
logWarning(string $msg[, array<string|int, mixed> $context = [] ][, bool $prependClass = true ]) : void
Parameters
- $msg : string
-
Log message
- $context : array<string|int, mixed> = []
-
Log context
- $prependClass : bool = true
-
Prepend class name to message?
Return values
void —sanitizeTranslationKey()
Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.
protected
sanitizeTranslationKey(string $key) : string
Parameters
- $key : string
-
Key to sanitize
Return values
string —Sanitized key
sendLoginTokenWarningEmail()
Send email warning to user
protected
sendLoginTokenWarningEmail(UserEntityInterface $user) : void
Parameters
- $user : UserEntityInterface
-
User
Return values
void —setLoginTokenCookie()
Set login token cookie
protected
setLoginTokenCookie(string $token, string $series, int $expires) : void
Parameters
- $token : string
-
Login token
- $series : string
-
Series the token belongs to
- $expires : int
-
Token expiration timestamp
Return values
void —translateString()
Get translation for a string
protected
translateString(string $rawStr[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, string $domain = 'default' ][, bool $useIcuFormatter = false ]) : string
Parameters
- $rawStr : string
-
String to translate
- $tokens : array<string|int, mixed> = []
-
Tokens to inject into the translated string
- $default : string = null
-
Default value to use if no translation is found (null for no default).
- $domain : string = 'default'
-
Text domain (omit for default)
- $useIcuFormatter : bool = false
-
Should we use an ICU message formatter instead of the default behavior?