AuthManager
extends Manager
in package
Back-end authentication manager.
Tags
Table of Contents
- $ipAddress : string
- $callbacks : array<string|int, mixed>
- $groupModel : string
- $instance : mixed
- $permissionCache : array<string|int, mixed>
- $permissionDefaults : mixed
- $permissionRoles : array<string|int, mixed>
- $permissions : array<string|int, mixed>
- $requireActivation : bool
- $sessionKey : string
- $throttle : array<string|int, mixed>
- $throttleModel : string
- $user : User
- $userModel : string
- $useSession : bool
- $useThrottle : bool
- $viaRemember : bool
- __clone() : mixed
- __wakeup() : mixed
- attempt() : User
- Attempt to authenticate a user using the given credentials.
- authenticate() : mixed
- Attempts to authenticate the given user according to the passed credentials.
- check() : bool
- Check to see if the user is logged in and activated, and hasn't been banned or suspended.
- createThrottleModel() : Throttle
- Creates an instance of the throttle model
- createUserModel() : User
- Creates a new instance of the user model
- extendUserQuery() : void
- Extend the query used for finding the user.
- findThrottleByLogin() : Throttle
- Find a throttle record by login and ip address
- findThrottleByUserId() : Throttle
- Find a throttle record by user id and ip address
- findUserByCredentials() : User
- Finds a user by the given credentials.
- findUserById() : mixed
- Finds a user by the login value.
- findUserByLogin() : mixed
- Finds a user by the login value.
- forgetInstance() : mixed
- Forget this singleton's instance if it exists
- getImpersonator() : mixed
- Get the original user doing the impersonation
- getUser() : mixed
- Returns the current user, if any.
- guest() : bool
- Determine if the current user is a guest.
- hasPermissionsForRole() : mixed
- id() : int|null
- Get the ID for the currently authenticated user.
- impersonate() : mixed
- Impersonates the given user and sets properties in the session but not the cookie.
- instance() : mixed
- Create a new instance of this singleton.
- isImpersonator() : bool
- Check to see if the current session is being impersonated
- listPermissions() : array<string|int, mixed>
- Returns a list of the registered permissions items.
- listPermissionsForRole() : array<string|int, mixed>
- Returns an array of registered permissions belonging to a given role code
- listTabbedPermissions() : array<string|int, mixed>
- Returns an array of registered permissions, grouped by tabs.
- login() : void
- Logs in the given user and sets properties in the session.
- loginUsingId() : Authenticatable
- Log the given user ID into the application.
- logout() : void
- Logs the current user out.
- once() : bool
- Log a user into the application without sessions or cookies.
- onceUsingId() : Authenticatable|false
- Log the given user ID into the application without sessions or cookies.
- register() : User
- Registers a user with the provided credentials with optional flags for activating the newly created user and automatically logging them in
- registerCallback() : mixed
- Registers a callback function that defines authentication permissions.
- registerPermissions() : mixed
- Registers the back-end permission items.
- removePermission() : void
- Removes a single back-end permission
- setUser() : mixed
- Sets the user
- stopImpersonate() : mixed
- Stop the current session being impersonated and authenticate as the impersonator again
- user() : Authenticatable|null
- Get the currently authenticated user.
- validate() : bool
- Validate a user's credentials.
- viaRemember() : bool
- Determine if the user was authenticated via "remember me" cookie.
- __construct() : mixed
- Constructor.
- createUserModelQuery() : Builder
- Prepares a query derived from the user model.
- init() : mixed
- Initializes the singleton
- validateInternal() : User
- Validate a user's credentials, method used internally.
- validateUserModel() : bool
- Perform additional checks on the user model.
Properties
$ipAddress
public
string
$ipAddress
= '0.0.0.0'
The IP address of this request
$callbacks
protected
array<string|int, mixed>
$callbacks
= []
Cache of registration callbacks.
$groupModel
protected
string
$groupModel
= 'Backend\Models\UserGroup'
User Group Model Class
$instance
protected
static mixed
$instance
$permissionCache
protected
array<string|int, mixed>
$permissionCache
= false
Cache of registered permissions.
$permissionDefaults
protected
static mixed
$permissionDefaults
= ['code' => null, 'label' => null, 'comment' => null, 'roles' => null, 'order' => 500]
$permissionRoles
protected
array<string|int, mixed>
$permissionRoles
= false
List of registered permission roles.
$permissions
protected
array<string|int, mixed>
$permissions
= []
List of registered permissions.
$requireActivation
protected
bool
$requireActivation
= false
Flag to require users to be activated to login
$sessionKey
protected
string
$sessionKey
= 'admin_auth'
Key to store the auth session data in
$throttle
protected
array<string|int, mixed>
$throttle
= []
In memory throttle cache [md5($userId.$ipAddress) => $this->throttleModel]
$throttleModel
protected
string
$throttleModel
= 'Backend\Models\UserThrottle'
Throttle Model Class
$user
protected
User
$user
The currently logged in user
$userModel
protected
string
$userModel
= 'Backend\Models\User'
User Model Class
$useSession
protected
bool
$useSession
= true
Internal flag to toggle using the session for the current authentication request
$useThrottle
protected
bool
$useThrottle
= true
Flag to enable login throttling
$viaRemember
protected
bool
$viaRemember
= false
Indicates if the user was authenticated via a recaller cookie.
Methods
__clone()
public
__clone() : mixed
Return values
mixed —__wakeup()
public
__wakeup() : mixed
Return values
mixed —attempt()
Attempt to authenticate a user using the given credentials.
public
attempt([array<string|int, mixed> $credentials = [] ][, bool $remember = false ]) : User
Parameters
- $credentials : array<string|int, mixed> = []
-
The user login details
- $remember : bool = false
-
Store a non-expire cookie for the user
Tags
Return values
User —The successfully logged in user
authenticate()
Attempts to authenticate the given user according to the passed credentials.
public
authenticate(array<string|int, mixed> $credentials[, bool $remember = true ]) : mixed
Parameters
- $credentials : array<string|int, mixed>
-
The user login details
- $remember : bool = true
-
Store a non-expire cookie for the user
Return values
mixed —check()
Check to see if the user is logged in and activated, and hasn't been banned or suspended.
public
check() : bool
Return values
bool —createThrottleModel()
Creates an instance of the throttle model
public
createThrottleModel() : Throttle
Return values
Throttle —createUserModel()
Creates a new instance of the user model
public
createUserModel() : User
Return values
User —extendUserQuery()
Extend the query used for finding the user.
public
extendUserQuery(Builder $query) : void
Parameters
- $query : Builder
Return values
void —findThrottleByLogin()
Find a throttle record by login and ip address
public
findThrottleByLogin(string $loginName, string $ipAddress) : Throttle
Parameters
- $loginName : string
- $ipAddress : string
Return values
Throttle —findThrottleByUserId()
Find a throttle record by user id and ip address
public
findThrottleByUserId(int $userId[, string $ipAddress = null ]) : Throttle
Parameters
- $userId : int
- $ipAddress : string = null
Return values
Throttle —findUserByCredentials()
Finds a user by the given credentials.
public
findUserByCredentials(array<string|int, mixed> $credentials) : User
Parameters
- $credentials : array<string|int, mixed>
-
The credentials to find a user by
Tags
Return values
User —The requested user
findUserById()
Finds a user by the login value.
public
findUserById(string $id) : mixed
Parameters
- $id : string
Return values
mixed —(Models\User || null)
findUserByLogin()
Finds a user by the login value.
public
findUserByLogin(string $login) : mixed
Parameters
- $login : string
Return values
mixed —(Models\User || null)
forgetInstance()
Forget this singleton's instance if it exists
public
final static forgetInstance() : mixed
Return values
mixed —getImpersonator()
Get the original user doing the impersonation
public
getImpersonator() : mixed
Return values
mixed —Returns the User model for the impersonator if able, false if not
getUser()
Returns the current user, if any.
public
getUser() : mixed
Return values
mixed —(Models\User || null)
guest()
Determine if the current user is a guest.
public
guest() : bool
Return values
bool —hasPermissionsForRole()
public
hasPermissionsForRole(mixed $role) : mixed
Parameters
- $role : mixed
Return values
mixed —id()
Get the ID for the currently authenticated user.
public
id() : int|null
Return values
int|null —impersonate()
Impersonates the given user and sets properties in the session but not the cookie.
public
impersonate(mixed $user) : mixed
Parameters
- $user : mixed
Return values
mixed —instance()
Create a new instance of this singleton.
public
final static instance() : mixed
Return values
mixed —isImpersonator()
Check to see if the current session is being impersonated
public
isImpersonator() : bool
Return values
bool —listPermissions()
Returns a list of the registered permissions items.
public
listPermissions() : array<string|int, mixed>
Return values
array<string|int, mixed> —listPermissionsForRole()
Returns an array of registered permissions belonging to a given role code
public
listPermissionsForRole(string $role[, bool $includeOrphans = true ]) : array<string|int, mixed>
Parameters
- $role : string
- $includeOrphans : bool = true
Return values
array<string|int, mixed> —listTabbedPermissions()
Returns an array of registered permissions, grouped by tabs.
public
listTabbedPermissions() : array<string|int, mixed>
Return values
array<string|int, mixed> —login()
Logs in the given user and sets properties in the session.
public
login(Authenticatable $user[, mixed $remember = true ]) : void
Parameters
- $user : Authenticatable
- $remember : mixed = true
Tags
Return values
void —loginUsingId()
Log the given user ID into the application.
public
loginUsingId(mixed $id[, bool $remember = false ]) : Authenticatable
Parameters
- $id : mixed
- $remember : bool = false
Return values
Authenticatable —logout()
Logs the current user out.
public
logout() : void
Return values
void —once()
Log a user into the application without sessions or cookies.
public
once([array<string|int, mixed> $credentials = [] ]) : bool
Parameters
- $credentials : array<string|int, mixed> = []
Return values
bool —onceUsingId()
Log the given user ID into the application without sessions or cookies.
public
onceUsingId(mixed $id) : Authenticatable|false
Parameters
- $id : mixed
Return values
Authenticatable|false —register()
Registers a user with the provided credentials with optional flags for activating the newly created user and automatically logging them in
public
register(array<string|int, mixed> $credentials[, bool $activate = false ][, bool $autoLogin = true ]) : User
Parameters
- $credentials : array<string|int, mixed>
- $activate : bool = false
- $autoLogin : bool = true
Return values
User —registerCallback()
Registers a callback function that defines authentication permissions.
public
registerCallback(callable $callback) : mixed
The callback function should register permissions by calling the manager's registerPermissions() function. The manager instance is passed to the callback function as an argument. Usage:
BackendAuth::registerCallback(function ($manager) {
$manager->registerPermissions([...]);
});
Parameters
- $callback : callable
-
A callable function.
Return values
mixed —registerPermissions()
Registers the back-end permission items.
public
registerPermissions(string $owner, array<string|int, mixed> $definitions) : mixed
The argument is an array of the permissions. The array keys represent the permission codes, specific for the plugin/module. Each element in the array should be an associative array with the following keys:
- label - specifies the menu label localization string key, required.
- order - a position of the item in the menu, optional.
- comment - a brief comment that describes the permission, optional.
- tab - assign this permission to a tabbed group, optional.
Parameters
- $owner : string
-
Specifies the permissions' owner plugin or module in the format Author.Plugin
- $definitions : array<string|int, mixed>
-
An array of the menu item definitions.
Return values
mixed —removePermission()
Removes a single back-end permission
public
removePermission(string $owner, string $code) : void
Parameters
- $owner : string
-
Specifies the permissions' owner plugin or module in the format Author.Plugin
- $code : string
-
The code of the permission to remove
Return values
void —setUser()
Sets the user
public
setUser(Authenticatable $user) : mixed
Parameters
- $user : Authenticatable
Return values
mixed —stopImpersonate()
Stop the current session being impersonated and authenticate as the impersonator again
public
stopImpersonate() : mixed
Return values
mixed —user()
Get the currently authenticated user.
public
user() : Authenticatable|null
Return values
Authenticatable|null —validate()
Validate a user's credentials.
public
validate([array<string|int, mixed> $credentials = [] ]) : bool
Parameters
- $credentials : array<string|int, mixed> = []
Return values
bool —viaRemember()
Determine if the user was authenticated via "remember me" cookie.
public
viaRemember() : bool
Return values
bool —__construct()
Constructor.
protected
final __construct() : mixed
Return values
mixed —createUserModelQuery()
Prepares a query derived from the user model.
protected
createUserModelQuery() : Builder
Return values
Builder —$query
init()
Initializes the singleton
protected
init() : mixed
Return values
mixed —validateInternal()
Validate a user's credentials, method used internally.
protected
validateInternal([array<string|int, mixed> $credentials = [] ]) : User
Parameters
- $credentials : array<string|int, mixed> = []
Return values
User —validateUserModel()
Perform additional checks on the user model.
protected
validateUserModel(mixed $user) : bool
Parameters
- $user : mixed