Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
use Illuminate\Contracts\Auth\Authenticatable; | ||
|
||
if (! function_exists('can_impersonate')) { | ||
|
||
/** | ||
* Check whether the current user is authorized to impersonate. | ||
* | ||
* @param null $guard | ||
* @return bool | ||
*/ | ||
function can_impersonate(string $guard = null): bool | ||
{ | ||
$guard = $guard ?? app('impersonate')->getCurrentAuthGuardName(); | ||
|
||
return app('auth')->guard($guard)->check() && app('auth')->guard($guard)->canImpersonate(); | ||
} | ||
} | ||
|
||
if (! function_exists('can_be_impersonated')) { | ||
|
||
/** | ||
* Check whether the specified user can be impersonated. | ||
* | ||
* @param Authenticatable $user | ||
* @param string|null $guard | ||
* @return bool | ||
*/ | ||
function can_be_impersonated(Authenticatable $user, string $guard = null): bool | ||
{ | ||
$guard = $guard ?? app('impersonate')->getCurrentAuthGuardName(); | ||
|
||
return app('auth')->guard($guard)->check() | ||
&& app('auth')->guard($guard)->user()->id != $user->id | ||
&& $user->canBeImpersonated(); | ||
} | ||
} | ||
|
||
if (! function_exists('is_impersonating')) { | ||
|
||
/** | ||
* Check whether the current user is being impersonated. | ||
* | ||
* @param string|null $guard | ||
* @return bool | ||
*/ | ||
function is_impersonating(string $guard = null): bool | ||
{ | ||
$guard = $guard ?? app('impersonate')->getCurrentAuthGuardName(); | ||
|
||
return app('auth')->guard($guard)->check() && app('auth')->guard($guard)->user()->isImpersonated(); | ||
} | ||
} |