Skip to content

Commit

Permalink
Merge pull request LifeOnScreen#18 from Nathanw/master
Browse files Browse the repository at this point in the history
Fire login events correctly
  • Loading branch information
janicerar committed Aug 2, 2019
2 parents f6f8b1e + 651e54d commit df9f1cf
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions src/Google2fa.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,15 @@ public function boot()
{
}

/**
* @return bool
*/
protected function is2FAValid()
{
$secret = Request::get('secret');
if (empty($secret)) {
return false;
}

$google2fa = new G2fa();
$google2fa->setAllowInsecureCallToGoogleApis(true);

return $google2fa->verifyKey(auth()->user()->user2fa->google2fa_secret, $secret);
}

/**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
* @throws \PragmaRX\Google2FA\Exceptions\InsecureCallException
*/
public function confirm()
{
if ($this->is2FAValid()) {
if (app(Google2FAAuthenticator::class)->isAuthenticated()) {
auth()->user()->user2fa->google2fa_enable = 1;
auth()->user()->user2fa->save();
$authenticator = app(Google2FAAuthenticator::class);
$authenticator->login();

return response()->redirectTo(config('nova.path'));
}
Expand Down Expand Up @@ -133,12 +115,11 @@ public function authenticate()

return response(view('google2fa::recovery', $data));
}
if ($this->is2FAValid()) {
$authenticator = app(Google2FAAuthenticator::class);
$authenticator->login();

if (app(Google2FAAuthenticator::class)->isAuthenticated()) {
return response()->redirectTo(config('nova.path'));
}

$data['error'] = 'One time password is invalid.';

return view('google2fa::authenticate', $data);
Expand Down

0 comments on commit df9f1cf

Please sign in to comment.