Fix usage of Google2FA Facade (#6864)

This commit is contained in:
Martin Meredith 2019-03-28 05:01:38 +00:00 committed by snipe
parent 83257af267
commit b779e274cc

View file

@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use App\Models\Setting; use App\Models\Setting;
use App\Models\User; use App\Models\User;
use App\Services\LdapAd; use App\Services\LdapAd;
use Com\Tecnick\Barcode\Barcode;
use Google2FA; use Google2FA;
use Illuminate\Foundation\Auth\ThrottlesLogins; use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -214,19 +215,27 @@ class LoginController extends Controller
return redirect()->route('two-factor')->with('error', trans('auth/message.two_factor.already_enrolled')); return redirect()->route('two-factor')->with('error', trans('auth/message.two_factor.already_enrolled'));
} }
$google2fa = new Google2FA(); $secret = Google2FA::generateSecretKey();
$secret = $google2fa->generateSecretKey();
$user->two_factor_secret = $secret; $user->two_factor_secret = $secret;
$user->save(); $user->save();
$google2fa_url = $google2fa->getQRCodeGoogleUrl( $barcode = new Barcode();
urlencode(Setting::getSettings()->site_name), $barcode_obj =
urlencode($user->username), $barcode->getBarcodeObj(
$user->two_factor_secret 'QRCODE',
); sprintf(
'otpauth://totp/%s:%s?secret=%s&issuer=Snipe-IT&period=30',
return view('auth.two_factor_enroll')->with('google2fa_url', $google2fa_url); urlencode($settings->site_name),
urlencode($user->username),
urlencode($secret)
),
300,
300,
'black',
[-2, -2, -2, -2]
);
return view('auth.two_factor_enroll')->with('barcode_obj', $barcode_obj);
} }
@ -277,10 +286,9 @@ class LoginController extends Controller
} }
$user = Auth::user(); $user = Auth::user();
$google2fa = new Google2FA();
$secret = $request->input('two_factor_secret'); $secret = $request->input('two_factor_secret');
if ($google2fa->verifyKey($user->two_factor_secret, $secret)) { if (Google2FA::verifyKey($user->two_factor_secret, $secret)) {
$user->two_factor_enrolled = 1; $user->two_factor_enrolled = 1;
$user->save(); $user->save();
$request->session()->put('2fa_authed', 'true'); $request->session()->put('2fa_authed', 'true');