public function postTwoFactor()
    {
        // Check that we have a session.
        if ($userId = Session::pull('2fa_id')) {
            $code = str_replace(' ', '', Binput::get('code'));

            // Maybe a temp login here.
            Auth::loginUsingId($userId);

            $user = Auth::user();

            $valid = Google2FA::verifyKey($user->google_2fa_secret, $code);

            if ($valid) {
                event(new UserPassedTwoAuthEvent($user));

                event(new UserLoggedInEvent($user));

                return Redirect::intended('dashboard');
            } else {
                event(new UserFailedTwoAuthEvent($user));

                // Failed login, log back out.
                Auth::logout();

                return cachet_redirect('auth.login')->withError(trans('forms.login.invalid-token'));
            }
        }

        return cachet_redirect('auth.login')->withError(trans('forms.login.invalid-token'));
    }
public function postTwoFactor()
    {
        // Check that we have a session.
        if ($userId = Session::pull('2fa_id')) {
            $code = str_replace(' ', '', Binput::get('code'));

            // Maybe a temp login here.
            Auth::loginUsingId($userId);

            $user = Auth::user();

            $valid = Google2FA::verifyKey($user->google_2fa_secret, $code);

            if ($valid) {
                event(new UserPassedTwoAuthEvent($user));

                event(new UserLoggedInEvent($user));

                return Redirect::intended('dashboard');
            } else {
                event(new UserFailedTwoAuthEvent($user));

                // Failed login, log back out.
                Auth::logout();

                return cachet_redirect('auth.login')->withError(trans('forms.login.invalid-token'));
            }
        }

        return cachet_redirect('auth.login')->withError(trans('forms.login.invalid-token'));
    }
public function postTwoFactor ( ) { // Check that we have a session. if ( $ userId = Session :: pull ( '2fa_id' ) ) { $ code = str_replace ( ' ' , '' , Binput :: get ( 'code' ) ) ; // Maybe a temp login here. Auth :: loginUsingId ( $ userId ) ; $ user = Auth :: user ( ) ; $ valid = Google2FA :: verifyKey ( $ user -> google_2fa_secret , $ code ) ; if ( $ valid ) { event ( new UserPassedTwoAuthEvent ( $ user ) ) ; event ( new UserLoggedInEvent ( $ user ) ) ; return Redirect :: intended ( 'dashboard' ) ; } else { event ( new UserFailedTwoAuthEvent ( $ user ) ) ; // Failed login, log back out. Auth :: logout ( ) ; return cachet_redirect ( 'auth.login' ) -> withError ( trans ( 'forms.login.invalid-token' ) ) ; } } return cachet_redirect ( 'auth.login' ) -> withError ( trans ( 'forms.login.invalid-token' ) ) ; }
Validates the Two Factor token.

This feels very hacky, but we have to juggle authentication and codes.

@return \Illuminate\Http\RedirectResponse
Validates the Two Factor token .