public function verifyOTP(Request $request) { //get one time password from user input $otp = $request->input('otp'); //get user id password from user input $authyid = $request->input('userid'); //get user type from user input $userType = $request->input('userType'); //initial authentication API //$authy_api = new AuthyApi(config('services.authy.key')); $authy_api = new AuthyApi(config('services.authy.key'), 'http://sandbox-api.authy.com'); //sandbox for test //verify user token $verification = $authy_api->verifyToken($authyid, $otp); //for token test, change it when project goes alive if ($verification->ok()) { //redirect page depends on user type if ($userType == "client") { return redirect('personal-detail'); } if ($userType = "affiliate") { return redirect('faq'); } } else { return redirect()->back()->withInput()->with('message', $verification->message()); } }
public function verifyToken($token) { $authy_api = new AuthyApi(getenv('AUTHY_TOKEN')); $verification = $authy_api->verifyToken($this->authy_id, $token); if ($verification->ok()) { return true; } else { return false; } }
/** * This controller function handles the submission form * * @param Request $request Current User Request * @param Authenticatable $user Current User * @param AuthyApi $authyApi Authy Client * @return mixed Response view */ public function verify(Request $request, Authenticatable $user, AuthyApi $authyApi, Client $client) { $token = $request->input('token'); $verification = $authyApi->verifyToken($user->authy_id, $token); if ($verification->ok()) { $user->verified = true; $user->save(); $this->sendSmsNotification($client, $user); return redirect()->route('user-index'); } else { $errors = $this->getAuthyErrors($verification->errors()); return view('verifyUser', ['errors' => new MessageBag($errors)]); } }
public function store(Request $request) { $authy = new AuthyApi(env('AUTHY_KEY', null), env('AUTHY_URL')); $login = $request->user(); try { $user = $authy->registerUser($login->email, $login->phone, $login->country_code); } catch (\Exception $e) { return redirect('/two_authenticate'); } if (!$user->ok()) { return redirect('/two_authenticate'); } try { if ($authy->verifyToken($user->id(), $request->token)) { $login->two_authenticate_until = Carbon::now()->addDays(5); $login->save(); } return redirect('/'); } catch (\Exception $e) { } return redirect('/two_authenticate'); }
/** * Verifies the incoming token against the current user * * @return void **/ private function verify() { // Get factor_id and token and verify them $authy = new AuthyApi($this->params->get('key')); $factor_id = Factor::currentOrFailByDomain('authy')->factor_id; $verification = $authy->verifyToken($factor_id, Request::getVar('token')); // If they pass, update the session if ($verification->ok()) { App::get('session')->set('authfactors.status', true); } else { // Otherwise, set errors foreach ($verification->errors() as $field => $message) { Notify::error($message); } } // Refresh page to either try verification again or finish up login App::redirect(Request::current()); }