EmailAuthenticator
in package
implements
TranslatorAwareInterface
Uses
TranslatorAwareTrait
Class for managing email-based authentication.
This class provides functionality for authentication based on a known-valid email address.
Tags
Interfaces, Classes, Traits and Enums
- 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
- $authHashService : AuthHashServiceInterface
- $config : Config
- $csrf : CsrfInterface
- $loginRequestValidTime : int
- How long a login request is considered to be valid (seconds)
- $mailer : Mailer
- $remoteAddress : RemoteAddress
- $sessionManager : SessionManager
- $translator : TranslatorInterface
- Translator
- $viewRenderer : PhpRenderer
- __construct() : mixed
- Constructor
- authenticate() : array<string|int, mixed>
- Authenticate using a hash
- getTranslator() : TranslatorInterface
- Get translator object.
- getTranslatorLocale() : string
- Get the locale from the translator.
- isValidLoginRequest() : bool
- Check if the given request is a valid login request
- sendAuthenticationLink() : void
- Send an email authentication link to the specified email address.
- setTranslator() : TranslatorAwareInterface
- Set a translator
- 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.
- 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.
- getDebugTranslation() : string
- Build a debug-mode translation
- sanitizeTranslationKey() : string
- Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.
- translateString() : string
- Get translation for a string
Properties
$authHashService
protected
AuthHashServiceInterface
$authHashService
$config
protected
Config
$config
$csrf
protected
CsrfInterface
$csrf
$loginRequestValidTime
How long a login request is considered to be valid (seconds)
protected
int
$loginRequestValidTime
= 600
$mailer
protected
Mailer
$mailer
$remoteAddress
protected
RemoteAddress
$remoteAddress
$sessionManager
protected
SessionManager
$sessionManager
$translator
Translator
protected
TranslatorInterface
$translator
= null
$viewRenderer
protected
PhpRenderer
$viewRenderer
Methods
__construct()
Constructor
public
__construct(SessionManager $sessionManager, CsrfInterface $csrf, Mailer $mailer, PhpRenderer $viewRenderer, RemoteAddress $remoteAddress, Config $config, AuthHashServiceInterface $authHashService) : mixed
Parameters
- $sessionManager : SessionManager
-
Session Manager
- $csrf : CsrfInterface
-
CSRF Validator
- $mailer : Mailer
-
Mailer
- $viewRenderer : PhpRenderer
-
View Renderer
- $remoteAddress : RemoteAddress
-
Remote address
- $config : Config
-
Configuration
- $authHashService : AuthHashServiceInterface
-
AuthHash database service
Return values
mixed —authenticate()
Authenticate using a hash
public
authenticate(string $hash) : array<string|int, mixed>
Parameters
- $hash : string
-
Hash
Tags
Return values
array<string|int, mixed> —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 —isValidLoginRequest()
Check if the given request is a valid login request
public
isValidLoginRequest(Request $request) : bool
Parameters
- $request : Request
-
Request object.
Return values
bool —sendAuthenticationLink()
Send an email authentication link to the specified email address.
public
sendAuthenticationLink(string $email, array<string|int, mixed> $data, array<string|int, mixed> $urlParams[, string $linkRoute = 'myresearch-home' ][, array<string|int, mixed> $routeParams = [] ][, string $subject = 'email_login_subject' ][, string $template = 'Email/login-link.phtml' ]) : void
Stores the required information in the session.
Parameters
- $email : string
-
Email address to send the link to
- $data : array<string|int, mixed>
-
Information from the authentication request (such as user details)
- $urlParams : array<string|int, mixed>
-
Default parameters for the generated URL
- $linkRoute : string = 'myresearch-home'
-
The route to use as the base url for the login link
- $routeParams : array<string|int, mixed> = []
-
Route parameters
- $subject : string = 'email_login_subject'
-
Email subject
- $template : string = 'Email/login-link.phtml'
-
Email message template
Return values
void —setTranslator()
Set a translator
public
setTranslator(TranslatorInterface $translator) : TranslatorAwareInterface
Parameters
- $translator : TranslatorInterface
-
Translator
Return values
TranslatorAwareInterface —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 —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> —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 —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
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?