diff options
author | Antonio Carlos Ribeiro <acr@antoniocarlosribeiro.com> | 2016-07-17 23:26:59 -0300 |
---|---|---|
committer | Antonio Carlos Ribeiro <acr@antoniocarlosribeiro.com> | 2016-07-17 23:26:59 -0300 |
commit | 92f2a60d3fc3548a60e72397577a2240c2877fc1 (patch) | |
tree | 9395935c5099ecf24f7350d03465b60ccf145e9e /app/Http | |
parent | 2f22e1b6f2f7af49d2bd7c5fae5dbc4520606df2 (diff) | |
download | google2fa-example-92f2a60d3fc3548a60e72397577a2240c2877fc1.zip google2fa-example-92f2a60d3fc3548a60e72397577a2240c2877fc1.tar.gz google2fa-example-92f2a60d3fc3548a60e72397577a2240c2877fc1.tar.bz2 |
Refactor
Diffstat (limited to 'app/Http')
-rw-r--r-- | app/Http/Controllers/Home.php | 56 | ||||
-rw-r--r-- | app/Http/routes.php | 3 |
2 files changed, 37 insertions, 22 deletions
diff --git a/app/Http/Controllers/Home.php b/app/Http/Controllers/Home.php index 72ea2f6..31f6a15 100644 --- a/app/Http/Controllers/Home.php +++ b/app/Http/Controllers/Home.php @@ -23,6 +23,32 @@ class Home extends Controller return $this->index($isValid); } + /** + * @param $key + * @return mixed + */ + private function getGoogleUrl($key) + { + return Google2FA::getQRCodeGoogleUrl( + $this->name, + $this->email, + $key + ); + } + + /** + * @param $key + * @return mixed + */ + private function getInlineUrl($key) + { + return Google2FA::getQRCodeInline( + $this->name, + $this->email, + $key + ); + } + private function getSecretKey() { if (! $key = $this->getStoredKey()) @@ -54,21 +80,13 @@ class Home extends Controller return Storage::get($this->fileName); } - public function index($valid = false) + public function index() { - $key = $this->getSecretKey(); + $valid = $this->validateInput($key = $this->getSecretKey()); - $googleUrl = Google2FA::getQRCodeGoogleUrl( - $this->name, - $this->email, - $key - ); + $googleUrl = $this->getGoogleUrl($key); - $inlineUrl = Google2FA::getQRCodeInline( - $this->name, - $this->email, - $key - ); + $inlineUrl = $this->getInlineUrl($key); return view('welcome')->with(compact('key', 'googleUrl', 'inlineUrl', 'valid')); } @@ -84,17 +102,15 @@ class Home extends Controller /** * @return mixed */ - private function validateInput() + private function validateInput($key) { // Get the code from input - $code = request()->get('code'); - - // Get our secret key - $key = $this->getSecretKey(); + if (! $code = request()->get('code')) + { + return false; + } // Verify the code - $isValid = Google2FA::verifyKey($key, $code); - - return $isValid; + return Google2FA::verifyKey($key, $code); } } diff --git a/app/Http/routes.php b/app/Http/routes.php index 6f640fa..1be2c92 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -1,4 +1,3 @@ <?php -Route::get('/', ['uses' => 'Home@index']); -Route::post('check2fa', ['uses' => 'Home@check2fa']); +Route::any('/', ['uses' => 'Home@index']); |