Skip to content

Instantly share code, notes, and snippets.

@deleugpn
Created October 10, 2017 19:02
Show Gist options
  • Select an option

  • Save deleugpn/847617e702f8adeb7597e0c9680b6d2d to your computer and use it in GitHub Desktop.

Select an option

Save deleugpn/847617e702f8adeb7597e0c9680b6d2d to your computer and use it in GitHub Desktop.
<?php
/**
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function update(Request $request)
{
if (is_null($request->get('token'))) {
return $this->disableToken();
}
$secretKey = $request->get('secret');
$token = $request->get('token');
if (Google2FA::verifyKey($secretKey, $token)) {
auth()->user()->update(['google_token' => $secretKey]);
return redirect('/profile/token')->with('success', 'Google Token successfully enabled!');
}
return redirect('/profile/token')->withErrors(['error' => 'The provided token does not match.']);
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
private function disableToken()
{
auth()->user()->update(['google_token' => null]);
return redirect('/profile/token')->with('success', 'Google Token successfully removed!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment