AuthManager
Back-end authentication manager.
class Backend\Classes\AuthManager
extends Winter\Storm\Auth\Manager
implements
Illuminate\Contracts\Auth\StatefulGuard
Traits
Trait | Description |
---|---|
Singleton
|
Singleton trait. |
Properties
protected
$aliases
:
array
= []
List of owner aliases. ['Aliased.Owner' => 'Real.Owner']
protected
$callbacks
:
array
= []
Cache of registration callbacks.
protected
$groupModel
:
mixed
= "Backend\\Models\\UserGroup"
protected static $instance : mixed
protected
$permissionCache
:
array
= false
Cache of registered permissions.
protected
static
$permissionDefaults
:
mixed
= {"code":null,"label":null,"comment":null,"roles":null,"order":500}
protected
$permissionRoles
:
array
= false
List of registered permission roles.
protected
$permissions
:
array
= []
List of registered permissions.
protected
$requireActivation
:
mixed
= false
protected
$sessionKey
:
mixed
= "admin_auth"
protected
$throttleModel
:
mixed
= "Backend\\Models\\UserThrottle"
protected
$userModel
:
mixed
= "Backend\\Models\\User"
public
$ipAddress
:
string
= "0.0.0.0"
The IP address of this request
protected $impersonator : Models\User | null
The user that is impersonating the currently logged in user when applicable
protected $sessionManager : Illuminate\Session\SessionManager
Session manager instance.
protected
$throttle
:
array
= []
In memory throttle cache [md5($userId.$ipAddress) => $this->throttleModel]
protected
$useSession
:
bool
= true
Internal flag to toggle using the session for the current authentication request
protected
$useThrottle
:
bool
= true
Flag to enable login throttling
protected $user : Models\User | null
The currently logged in user
protected
$viaRemember
:
bool
= false
Indicates if the user was authenticated via a recaller cookie.
Methods
public hasPermissionsForRole ($role)
Property | Type | Description |
---|---|---|
$role | mixed |
mixed
|
public listPermissions () : array
Returns a list of the registered permissions items.
public
listPermissionsForRole (string $role, boolean $includeOrphans = true
)
: array
Returns an array of registered permissions belonging to a given role code
Property | Type | Description |
---|---|---|
$role | string |
string
|
$includeOrphans | boolean |
boolean
Include any permissons that do not have a default role specified |
public listTabbedPermissions () : array
Returns an array of registered permissions, grouped by tabs.
public registerCallback (callable $callback)
Registers a callback function that defines authentication permissions.
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([...]);
});
Property | Type | Description |
---|---|---|
$callback | callable |
callable
A callable function. |
public registerPermissionOwnerAlias (string $owner, string $alias) : void
Register a permission owner alias
Property | Type | Description |
---|---|---|
$owner | string |
string
The owner to register an alias for. Example: Real.Owner |
$alias | string |
string
The alias to register. Example: Aliased.Owner |
public registerPermissions (string $owner, array $definitions)
Registers the back-end permission items.
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.
Property | Type | Description |
---|---|---|
$owner | string |
string
Specifies the permissions' owner plugin or module in the format Author.Plugin |
$definitions | array |
array
An array of the menu item definitions. |
public removePermission (string $owner, string $code) : void
Removes a single back-end permission
Property | Type | Description |
---|---|---|
$owner | string |
string
Specifies the permissions' owner plugin or module in the format Author.Plugin |
$code | string |
string
The code of the permission to remove |
protected createUserModelQuery ()
{@inheritdoc}
protected init ()
protected validateUserModel ($user)
{@inheritdoc}
Property | Type | Description |
---|---|---|
$user | mixed |
mixed
|
public __clone ()
public __wakeup ()
public
attempt (array $credentials = []
, boolean $remember = false
)
: bool
Attempt to authenticate a user using the given credentials.
Property | Type | Description |
---|---|---|
$credentials | array |
array
The user login details |
$remember | boolean |
boolean
Store a non-expire cookie for the user |
If authentication was successful
public
authenticate (array $credentials, boolean $remember = true
)
Attempts to authenticate the given user according to the passed credentials.
Property | Type | Description |
---|---|---|
$credentials | array |
array
The user login details |
$remember | boolean |
boolean
Store a non-expire cookie for the user |
public check () : bool
Check to see if the user is logged in and activated, and hasn't been banned or suspended.
public createThrottleModel () : Models\Throttle
Creates an instance of the throttle model
public createUserModel () : Models\User
Creates a new instance of the user model
public extendUserQuery (Winter\Storm\Database\Builder $query) : void
Extend the query used for finding the user.
Property | Type | Description |
---|---|---|
$query | Winter\Storm\Database\Builder |
public findThrottleByLogin (string $loginName, string $ipAddress) : Models\Throttle
Find a throttle record by login and ip address
Property | Type | Description |
---|---|---|
$loginName | string |
string
|
$ipAddress | string |
string
|
public
findThrottleByUserId (int $userId, string $ipAddress = null
)
: Models\Throttle
Find a throttle record by user id and ip address
Property | Type | Description |
---|---|---|
$userId | int |
int
|
$ipAddress | string |
string
|
public findUserByCredentials (array $credentials) : Models\User
Finds a user by the given credentials.
Property | Type | Description |
---|---|---|
$credentials | array |
array
The credentials to find a user by |
The requested user
public findUserById (string $id) : mixed
Finds a user by the login value.
Property | Type | Description |
---|---|---|
$id | string |
string
|
(Models\User || null)
public findUserByLogin (string $login) : mixed
Finds a user by the login value.
Property | Type | Description |
---|---|---|
$login | string |
string
|
(Models\User || null)
public
static
final
forgetInstance ($container = null
)
: void
Forget this singleton's instance if it exists
Property | Type | Description |
---|---|---|
$container | mixed |
mixed
|
public getImpersonator () : Models\User | false
Get the original user doing the impersonation
Returns the User model for the impersonator if able, false
if not
public getRealUser () : mixed
Gets the user for the request, taking into account impersonation
(Models\User || null)
public getUser () : mixed
Returns the current user, if any.
(Models\User || null)
public guest () : bool
Determine if the current user is a guest.
public hasUser () : bool
Determine if the guard has a user instance.
public id () : int | null
Get the ID for the currently authenticated user.
public impersonate (Models\User $impersonatee) : void
Impersonates the given user and sets properties in the session but not the cookie.
Property | Type | Description |
---|---|---|
$impersonatee | Models\User |
Models\User
|
public
static
final
instance ($container = null
)
: static
Create a new instance of this singleton.
Property | Type | Description |
---|---|---|
$container | mixed |
mixed
|
public isImpersonator () : bool
Check to see if the current session is being impersonated
public
login (Illuminate\Contracts\Auth\Authenticatable $user, boolean $remember = true
)
Logs in the given user and sets properties in the session.
Property | Type | Description |
---|---|---|
$user | Illuminate\Contracts\Auth\Authenticatable |
Illuminate\Contracts\Auth\Authenticatable
|
$remember | boolean |
boolean
|
public
loginUsingId (mixed $id, boolean $remember = false
)
: Illuminate\Contracts\Auth\Authenticatable | false
Log the given user ID into the application.
Property | Type | Description |
---|---|---|
$id | mixed |
mixed
|
$remember | boolean |
boolean
|
public logout ()
Logs the current user out.
public
once (array $credentials = []
)
: bool
Log a user into the application without sessions or cookies.
Property | Type | Description |
---|---|---|
$credentials | array |
array
|
public onceUsingId (mixed $id) : Illuminate\Contracts\Auth\Authenticatable | false
Log the given user ID into the application without sessions or cookies.
Property | Type | Description |
---|---|---|
$id | mixed |
mixed
|
public
register (array $credentials, boolean $activate = false
, boolean $autoLogin = true
)
: Models\User
Registers a user with the provided credentials with optional flags for activating the newly created user and automatically logging them in
Property | Type | Description |
---|---|---|
$credentials | array |
array
|
$activate | boolean |
boolean
|
$autoLogin | boolean |
boolean
|
public setUser (Illuminate\Contracts\Auth\Authenticatable $user)
Sets the user
Property | Type | Description |
---|---|---|
$user | Illuminate\Contracts\Auth\Authenticatable |
Illuminate\Contracts\Auth\Authenticatable
|
public stopImpersonate ()
Stop the current session being impersonated and authenticate as the impersonator again
public user () : Illuminate\Contracts\Auth\Authenticatable | null
Get the currently authenticated user.
public
validate (array $credentials = []
)
: bool
Validate a user's credentials.
Property | Type | Description |
---|---|---|
$credentials | array |
array
|
public viaRemember () : bool
Determine if the user was authenticated via "remember me" cookie.
protected final __construct ()
Constructor.
protected
getPersistCodeFromSession (boolean $logRemember = false
)
: array | null
Returns the user ID and peristence code from the session or remember cookie
Property | Type | Description |
---|---|---|
$logRemember | boolean |
boolean
Flag to set $this->viaRemember if the persist code was pulled from the cookie |
[user_id, persist_code]
protected
setPersistCodeInSession (Models\User $user, boolean $remember = true
)
: void
Stores the user persistence information in the session (and cookie when $remember = true)
Property | Type | Description |
---|---|---|
$user | Models\User |
Models\User
|
$remember | boolean |
boolean
|
protected
validateInternal (array $credentials = []
)
: Models\User | null
Validate a user's credentials, method used internally.
Property | Type | Description |
---|---|---|
$credentials | array |
array
|