2020-02-26 13:59:58 +00:00
|
|
|
<?php
|
|
|
|
|
2020-02-26 23:42:36 +00:00
|
|
|
namespace App\Http\Controllers\Profile;
|
2020-02-26 13:59:58 +00:00
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Session;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Jenssegers\Agent\Agent;
|
|
|
|
|
|
|
|
class SecurityController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware(['mobile', 'auth', 'verified', '2fa']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the application dashboard.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @param int $page
|
2020-02-26 23:42:36 +00:00
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
2020-02-26 13:59:58 +00:00
|
|
|
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
|
|
|
|
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
|
|
|
|
*/
|
|
|
|
public function index(Request $request, $page = 1)
|
|
|
|
{
|
|
|
|
$google2fa = new \PragmaRX\Google2FALaravel\Google2FA($request);
|
|
|
|
$tfa = $google2fa->isActivated();
|
|
|
|
$pages = Session::where('user_id', Auth::id())->count();
|
|
|
|
$pages = (int) ceil($pages/10);
|
|
|
|
if($page > $pages)
|
2020-02-26 23:42:36 +00:00
|
|
|
return redirect()->route('profile.security', ['page' => $pages]);
|
2020-02-26 13:59:58 +00:00
|
|
|
|
|
|
|
$sessions = Session::where('user_id', Auth::id())->where('id', '!=', session()->getId())->skip(($page - 1)*10)->take(($page != 1 ? 10 : 9))->orderBy('last_activity', 'desc')->get();
|
|
|
|
$array = ['TFA' => $tfa, 'pages' => $pages, 'page' => $page, 'sessions' => $sessions, 'agent' => new Agent()];
|
|
|
|
|
|
|
|
if(!$tfa) {
|
|
|
|
if(!session()->has('redirected')) {
|
|
|
|
$secret = $google2fa->generateSecretKey();
|
|
|
|
session()->flash('google_secret', $secret);
|
|
|
|
} else {
|
|
|
|
$secret = session()->get('google_secret');
|
|
|
|
session()->keep(['google_secret']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$google2fa = new \PragmaRX\Google2FAQRCode\Google2FA();
|
|
|
|
$QR = $google2fa->getQRCodeInline(
|
|
|
|
config('app.name'),
|
|
|
|
Auth::user()->email,
|
|
|
|
$secret
|
|
|
|
);
|
|
|
|
|
|
|
|
$array['QRCode'] = $QR;
|
2020-02-26 23:42:36 +00:00
|
|
|
return view('profile.security')->with($array);
|
2020-02-26 13:59:58 +00:00
|
|
|
}
|
|
|
|
|
2020-02-26 23:42:36 +00:00
|
|
|
return view('profile.security')->with($array);
|
2020-02-26 13:59:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function session($id)
|
|
|
|
{
|
|
|
|
if(session()->getId() === $id)
|
2020-02-26 23:42:36 +00:00
|
|
|
return redirect()->route('profile.security');
|
2020-02-26 13:59:58 +00:00
|
|
|
|
|
|
|
Session::where(['id' => $id, 'user_id' => Auth::id()])->forceDelete();
|
2020-02-26 23:42:36 +00:00
|
|
|
return redirect()->route('profile.security');
|
2020-02-26 13:59:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|