| @@ 5-20 (lines=16) @@ | ||
| 2 | ||
| 3 | use Illuminate\Contracts\Auth\Authenticatable; |
|
| 4 | ||
| 5 | if (! function_exists('can_impersonate')) { |
|
| 6 | ||
| 7 | /** |
|
| 8 | * Check whether the current user is authorized to impersonate. |
|
| 9 | * |
|
| 10 | * @param null $guard |
|
| 11 | * @return bool |
|
| 12 | */ |
|
| 13 | function can_impersonate(string $guard = null): bool |
|
| 14 | { |
|
| 15 | $guard = $guard ?? app('impersonate')->getCurrentAuthGuardName(); |
|
| 16 | ||
| 17 | return app('auth')->guard($guard)->check() |
|
| 18 | && app('auth')->guard($guard)->user()->canImpersonate(); |
|
| 19 | } |
|
| 20 | } |
|
| 21 | ||
| 22 | if (! function_exists('can_be_impersonated')) { |
|
| 23 | ||
| @@ 22-38 (lines=17) @@ | ||
| 19 | } |
|
| 20 | } |
|
| 21 | ||
| 22 | if (! function_exists('can_be_impersonated')) { |
|
| 23 | ||
| 24 | /** |
|
| 25 | * Check whether the specified user can be impersonated. |
|
| 26 | * |
|
| 27 | * @param Authenticatable $user |
|
| 28 | * @param string|null $guard |
|
| 29 | * @return bool |
|
| 30 | */ |
|
| 31 | function can_be_impersonated(Authenticatable $user, string $guard = null): bool |
|
| 32 | { |
|
| 33 | $guard = $guard ?? app('impersonate')->getCurrentAuthGuardName(); |
|
| 34 | return app('auth')->guard($guard)->check() |
|
| 35 | && app('auth')->guard($guard)->user()->isNot($user) |
|
| 36 | && $user->canBeImpersonated(); |
|
| 37 | } |
|
| 38 | } |
|
| 39 | ||
| 40 | if (! function_exists('is_impersonating')) { |
|
| 41 | ||
| @@ 40-55 (lines=16) @@ | ||
| 37 | } |
|
| 38 | } |
|
| 39 | ||
| 40 | if (! function_exists('is_impersonating')) { |
|
| 41 | ||
| 42 | /** |
|
| 43 | * Check whether the current user is being impersonated. |
|
| 44 | * |
|
| 45 | * @param string|null $guard |
|
| 46 | * @return bool |
|
| 47 | */ |
|
| 48 | function is_impersonating(string $guard = null): bool |
|
| 49 | { |
|
| 50 | $guard = $guard ?? app('impersonate')->getCurrentAuthGuardName(); |
|
| 51 | ||
| 52 | return app('auth')->guard($guard)->check() |
|
| 53 | && app('auth')->guard($guard)->user()->isImpersonated(); |
|
| 54 | } |
|
| 55 | } |
|
| 56 | ||