Last active
October 12, 2017 03:21
-
-
Save deleugpn/227bedb0fc668bbd218964ec8bf0aa0e to your computer and use it in GitHub Desktop.
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
<?php | |
namespace App\Http\Controllers\Auth; | |
use App\Http\Controllers\Controller; | |
use App\Models\Main\Admin; | |
use Facades\PragmaRX\Google2FA\Google2FA; | |
use Illuminate\Http\Request; | |
class TokenController extends Controller | |
{ | |
public function index() | |
{ | |
return view('auth.token'); | |
} | |
public function authenticate(Request $request) | |
{ | |
$user = Admin::findOrFail($request->session()->get('user-id')); | |
$token = $request->get('token'); | |
if (Google2FA::verifyKey($user->google_token, $token)) { | |
$request->session()->remove('user-id'); | |
auth()->loginUsingId($user->id); | |
return redirect('/home'); | |
} | |
return redirect('/token')->withErrors(['error' => __('Invalid Token')]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment