Authenticator
Handles authentication tasks.
Tags
Table of Contents
$classMapper | ClassMapper | |
---|---|---|
$session | Session | |
$config | Repository | |
$cache | Repository | |
$db | Manager | |
$loggedOut | bool | |
$rememberMeStorage | PDOStorage | |
$rememberMe | Authenticator | |
$user | UserInterface | |
$viaRemember | Indicates if the user was authenticated via a rememberMe cookie. | bool |
__construct() | Create a new Authenticator object. | mixed |
attempt() | Attempts to authenticate a user based on a supplied identity and password. | UserInterface |
check() | Determine if the current user is authenticated. | bool |
guest() | Determine if the current user is a guest (unauthenticated). | bool |
login() | Process an account login request. | mixed |
logout() | Processes an account logout request. | mixed |
user() | Try to get the currently authenticated user, returning a guest user if none was found. | UserInterface|null |
viaRemember() | Determine whether the current user was authenticated using a remember me cookie. | bool |
loginRememberedUser() | Attempt to log in the client from their rememberMe token (in their cookie). | UserInterface|bool |
loginSessionUser() | Attempt to log in the client from the session. | UserInterface|null |
validateRememberMeCookie() | Determine if the cookie contains a valid rememberMe token. | bool |
validateUserAccount() | Tries to load the specified user by id from the database. | UserInterface|null |
flushSessionCache() | Flush the cache associated with a session id. | bool |
Properties
$classMapper
protected
ClassMapper
$classMapper
$session
protected
Session
$session
$config
protected
Repository
$config
$cache
protected
Repository
$cache
$db
protected
Manager
$db
$loggedOut
protected
bool
$loggedOut
= false
$rememberMeStorage
protected
PDOStorage
$rememberMeStorage
$rememberMe
protected
Authenticator
$rememberMe
$user
protected
UserInterface
$user
$viaRemember
Indicates if the user was authenticated via a rememberMe cookie.
protected
bool
$viaRemember
= false
Methods
__construct()
Create a new Authenticator object.
public
__construct(
$classMapper :
ClassMapper
, $session :
Session
, $config :
Repository
, $cache :
Repository
, $db :
Manager
)
: mixed
Parameters
- $classMapper : ClassMapper
Maps generic class identifiers to specific class names.
- $session : Session
The session wrapper object that will store the user's id.
- $config : Repository
Config object that contains authentication settings.
- $cache : Repository
Cache service instance
- $db : Manager
Database service instance
Return values
mixedattempt()
Attempts to authenticate a user based on a supplied identity and password.
public
attempt(
$identityColumn :
string
, $identityValue :
string
, $password :
string
[, $rememberMe :
bool
= false ]
)
: UserInterface
If successful, the user's id is stored in session.
Parameters
- $identityColumn : string
- $identityValue : string
- $password : string
- $rememberMe : bool = false
Tags
Return values
UserInterfacecheck()
Determine if the current user is authenticated.
public
check(
)
: bool
Return values
boolguest()
Determine if the current user is a guest (unauthenticated).
public
guest(
)
: bool
Return values
boollogin()
Process an account login request.
public
login(
$user :
UserInterface
[, $rememberMe :
bool
= false ]
)
: mixed
This method logs in the specified user, allowing the client to assume the user's identity for the duration of the session.
Parameters
- $user : UserInterface
The user to log in.
- $rememberMe : bool = false
Set to true to make this a "persistent session", i.e. one that will re-login even after the session expires.
Tags
Return values
mixedlogout()
Processes an account logout request.
public
logout(
[ $complete :
bool
= false ]
)
: mixed
Logs the currently authenticated user out, destroying the PHP session and clearing the persistent session. This can optionally remove persistent sessions across all browsers/devices, since there can be a "RememberMe" cookie and corresponding database entries in multiple browsers/devices. See http://jaspan.com/improved_persistent_login_cookie_best_practice.
Parameters
- $complete : bool = false
If set to true, will ensure that the user is logged out from all browsers on all devices.
Return values
mixeduser()
Try to get the currently authenticated user, returning a guest user if none was found.
public
user(
)
: UserInterface|null
Tries to re-establish a session for "remember-me" users who have been logged out due to an expired session.
Tags
Return values
UserInterface|nullviaRemember()
Determine whether the current user was authenticated using a remember me cookie.
public
viaRemember(
)
: bool
This function is useful when users are performing sensitive operations, and you may want to force them to re-authenticate.
Return values
boolloginRememberedUser()
Attempt to log in the client from their rememberMe token (in their cookie).
protected
loginRememberedUser(
)
: UserInterface|bool
Tags
Return values
UserInterface|bool —If successful, the User object of the remembered user. Otherwise, return false.
loginSessionUser()
Attempt to log in the client from the session.
protected
loginSessionUser(
)
: UserInterface|null
Tags
Return values
UserInterface|null —If successful, the User object of the user in session. Otherwise, return null.
validateRememberMeCookie()
Determine if the cookie contains a valid rememberMe token.
protected
validateRememberMeCookie(
)
: bool
Return values
boolvalidateUserAccount()
Tries to load the specified user by id from the database.
protected
validateUserAccount(
$userId :
int
)
: UserInterface|null
Checks that the account is valid and enabled, throwing an exception if not.
Parameters
- $userId : int
Tags
Return values
UserInterface|nullflushSessionCache()
Flush the cache associated with a session id.
public
flushSessionCache(
$id :
string
)
: bool
Parameters
- $id : string
The session id