user(); // to make sure the validator in the next step gets the secret, we push it in session $secretPreference = Preferences::get('twoFactorAuthSecret', null); $secret = is_null($secretPreference) ? null : $secretPreference->data; $title = strval(trans('firefly.two_factor_title')); // make sure the user has two factor configured: $has2FA = Preferences::get('twoFactorAuthEnabled', false)->data; if (is_null($has2FA) || $has2FA === false) { return redirect(route('index')); } if (strlen(strval($secret)) === 0) { throw new FireflyException('Your two factor authentication secret is empty, which it cannot be at this point. Please check the log files.'); } $request->session()->flash('two-factor-secret', $secret); return view('auth.two-factor', compact('user', 'title')); } /** * @return mixed * @throws FireflyException */ public function lostTwoFactor() { $user = auth()->user(); $siteOwner = env('SITE_OWNER', ''); $title = strval(trans('firefly.two_factor_forgot_title')); Log::info( 'To reset the two factor authentication for user #' . $user->id . ' (' . $user->email . '), simply open the "preferences" table and delete the entries with the names "twoFactorAuthEnabled" and' . ' "twoFactorAuthSecret" for user_id ' . $user->id . '. That will take care of it.' ); return view('auth.lost-two-factor', compact('user', 'siteOwner', 'title')); } /** * @param TokenFormRequest $request * @param CookieJar $cookieJar * * @return mixed * @SuppressWarnings(PHPMD.UnusedFormalParameter) // it's unused but the class does some validation. * */ public function postIndex(TokenFormRequest $request, CookieJar $cookieJar) { // set cookie! $cookie = $cookieJar->forever('twoFactorAuthenticated', 'true'); return redirect(route('home'))->withCookie($cookie); } }