-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathTwoFactorAuthenticationStatus.php
39 lines (33 loc) · 1.17 KB
/
TwoFactorAuthenticationStatus.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace App\Domains\Auth\Http\Middleware;
use Closure;
/**
* Class TwoFactorAuthenticationStatus.
*/
class TwoFactorAuthenticationStatus
{
/**
* @param $request
* @param Closure $next
* @param string $status
* @return mixed
*/
public function handle($request, Closure $next, $status = 'enabled')
{
if (! in_array($status, ['enabled', 'disabled'])) {
abort(404);
}
// If the backend does not require 2FA than continue
if ($status === 'enabled' && $request->is('admin*') && ! config('boilerplate.access.user.admin_requires_2fa')) {
return $next($request);
}
// Page requires 2fa, but user is not enabled or page does not require 2fa, but it is enabled
if (
($status === 'enabled' && ! $request->user()->hasTwoFactorEnabled()) ||
($status === 'disabled' && $request->user()->hasTwoFactorEnabled())
) {
return redirect()->route('frontend.auth.account.2fa.create')->withFlashDanger(__('Two-factor Authentication must be :status to view this page.', ['status' => $status]));
}
return $next($request);
}
}