2018-09-11 07:51:35 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
|
|
use App\Models\UserPref;
|
|
|
|
|
use Closure;
|
2020-04-17 17:37:56 -05:00
|
|
|
use Illuminate\Support\Str;
|
2018-09-11 07:51:35 -05:00
|
|
|
use LibreNMS\Config;
|
|
|
|
|
|
|
|
|
|
class VerifyTwoFactor
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Handle an incoming request.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @param \Closure $next
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
|
{
|
|
|
|
|
// check twofactor
|
|
|
|
|
if (Config::get('twofactor') === true) {
|
|
|
|
|
// don't apply on 2fa checking routes
|
2020-04-17 17:37:56 -05:00
|
|
|
if (Str::startsWith($request->route()->getName(), '2fa.')) {
|
2018-09-11 07:51:35 -05:00
|
|
|
return $next($request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$twofactor = $request->session()->get('twofactoradd', UserPref::getPref($request->user(), 'twofactor'));
|
|
|
|
|
|
|
|
|
|
if (!empty($twofactor)) {
|
|
|
|
|
// user has 2fa enabled
|
|
|
|
|
if (!$request->session()->get('twofactor')) {
|
|
|
|
|
// verification is needed
|
|
|
|
|
return redirect('/2fa');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
|
}
|
|
|
|
|
}
|