public function post2FALogin(Request $request) {

        $userId = $request->session()->get('user_id');

        // Did the user take too much time to fill out the form?
       if ($this->twoFactorAuthHelper->isTwoFactorAuthFormTimeout($userId)) {
           return view('usermanagement::frontend.'.$this->frontend_template_name.'.login.login', [
               'title' => 'Login',
               ])
               ->withErrors([
                   'Two Factor Authorization' => 'Your two factor authorization code expired. Please re-login.'
               ]);
       }

        // Is the code correct?
        // If not, go back to the 2FA form with an error message
        if (!$this->twoFactorAuthHelper->isInputtedTwoFactorAuthCodeCorrect($userId)) {
            return view('usermanagement::frontend.'.$this->frontend_template_name.'.login.two_factor_auth', [
                'title' => 'Login Enter 2FA Code',
            ])
                ->withErrors([
                    'Two Factor Authorization' => 'Your entered an incorrect two factor authorization code. Please try again.'
                ]);
        }

        // 2FA successful!

        // Clear the user's 2FA code
        $this->twoFactorAuthHelper->clearUserTwoFactorAuthFields($userId);

        // Update the user's last_login fields
        $this->twoFactorAuthHelper->updateUserRecordWithLastlogin($userId);

        // Manually login user
        Auth::loginUsingId($request->session()->get('user_id'));

        // Clear the 'user_id' session variable
        $this->twoFactorAuthHelper->clearUserIdSessionVar();


        // Set the cookie, and onward and forward to the frontend!

        // Ah ah ah! Instantiating a new response view and returning it is causing a message to display
        // before the actual view is rendered. This message looks like cookie information, but it displays
        // whether or not a cookie is created. So... I'm going to see if we need a cookie, and if not,
        // return the view as usual.

        if ((!$this->twoFactorAuthHelper->isCookieExists()) && (config('lasallecmsusermanagement.auth_2fa_cookie_enable'))) {

            // Create the cookie...
            $view = redirect()->intended($this->twoFactorAuthHelper->redirectPathUponSuccessfulFrontendLogin());
            $response = new \Illuminate\Http\Response($view);
            $response = $this->twoFactorAuthHelper->setCookie($response);
            return $response;
        }

        // Oh, no cookie writing at all...
        return redirect()->intended($this->twoFactorAuthHelper->redirectPathUponSuccessfulFrontendLogin());
     }
public function post2FALogin(Request $request) {

        $userId = $request->session()->get('user_id');

        // Did the user take too much time to fill out the form?
       if ($this->twoFactorAuthHelper->isTwoFactorAuthFormTimeout($userId)) {
           return view('usermanagement::frontend.'.$this->frontend_template_name.'.login.login', [
               'title' => 'Login',
               ])
               ->withErrors([
                   'Two Factor Authorization' => 'Your two factor authorization code expired. Please re-login.'
               ]);
       }

        // Is the code correct?
        // If not, go back to the 2FA form with an error message
        if (!$this->twoFactorAuthHelper->isInputtedTwoFactorAuthCodeCorrect($userId)) {
            return view('usermanagement::frontend.'.$this->frontend_template_name.'.login.two_factor_auth', [
                'title' => 'Login Enter 2FA Code',
            ])
                ->withErrors([
                    'Two Factor Authorization' => 'Your entered an incorrect two factor authorization code. Please try again.'
                ]);
        }

        // 2FA successful!

        // Clear the user's 2FA code
        $this->twoFactorAuthHelper->clearUserTwoFactorAuthFields($userId);

        // Update the user's last_login fields
        $this->twoFactorAuthHelper->updateUserRecordWithLastlogin($userId);

        // Manually login user
        Auth::loginUsingId($request->session()->get('user_id'));

        // Clear the 'user_id' session variable
        $this->twoFactorAuthHelper->clearUserIdSessionVar();


        // Set the cookie, and onward and forward to the frontend!

        // Ah ah ah! Instantiating a new response view and returning it is causing a message to display
        // before the actual view is rendered. This message looks like cookie information, but it displays
        // whether or not a cookie is created. So... I'm going to see if we need a cookie, and if not,
        // return the view as usual.

        if ((!$this->twoFactorAuthHelper->isCookieExists()) && (config('lasallecmsusermanagement.auth_2fa_cookie_enable'))) {

            // Create the cookie...
            $view = redirect()->intended($this->twoFactorAuthHelper->redirectPathUponSuccessfulFrontendLogin());
            $response = new \Illuminate\Http\Response($view);
            $response = $this->twoFactorAuthHelper->setCookie($response);
            return $response;
        }

        // Oh, no cookie writing at all...
        return redirect()->intended($this->twoFactorAuthHelper->redirectPathUponSuccessfulFrontendLogin());
     }
public function post2FALogin ( Request $ request ) { $ userId = $ request -> session ( ) -> get ( 'user_id' ) ; // Did the user take too much time to fill out the form? if ( $ this -> twoFactorAuthHelper -> isTwoFactorAuthFormTimeout ( $ userId ) ) { return view ( 'usermanagement::frontend.' . $ this -> frontend_template_name . '.login.login' , [ 'title' => 'Login' , ] ) -> withErrors ( [ 'Two Factor Authorization' => 'Your two factor authorization code expired. Please re-login.' ] ) ; } // Is the code correct? // If not, go back to the 2FA form with an error message if ( ! $ this -> twoFactorAuthHelper -> isInputtedTwoFactorAuthCodeCorrect ( $ userId ) ) { return view ( 'usermanagement::frontend.' . $ this -> frontend_template_name . '.login.two_factor_auth' , [ 'title' => 'Login Enter 2FA Code' , ] ) -> withErrors ( [ 'Two Factor Authorization' => 'Your entered an incorrect two factor authorization code. Please try again.' ] ) ; } // 2FA successful! // Clear the user's 2FA code $ this -> twoFactorAuthHelper -> clearUserTwoFactorAuthFields ( $ userId ) ; // Update the user's last_login fields $ this -> twoFactorAuthHelper -> updateUserRecordWithLastlogin ( $ userId ) ; // Manually login user Auth :: loginUsingId ( $ request -> session ( ) -> get ( 'user_id' ) ) ; // Clear the 'user_id' session variable $ this -> twoFactorAuthHelper -> clearUserIdSessionVar ( ) ; // Set the cookie, and onward and forward to the frontend! // Ah ah ah! Instantiating a new response view and returning it is causing a message to display // before the actual view is rendered. This message looks like cookie information, but it displays // whether or not a cookie is created. So... I'm going to see if we need a cookie, and if not, // return the view as usual. if ( ( ! $ this -> twoFactorAuthHelper -> isCookieExists ( ) ) && ( config ( 'lasallecmsusermanagement.auth_2fa_cookie_enable' ) ) ) { // Create the cookie... $ view = redirect ( ) -> intended ( $ this -> twoFactorAuthHelper -> redirectPathUponSuccessfulFrontendLogin ( ) ) ; $ response = new \ Illuminate \ Http \ Response ( $ view ) ; $ response = $ this -> twoFactorAuthHelper -> setCookie ( $ response ) ; return $ response ; } // Oh, no cookie writing at all... return redirect ( ) -> intended ( $ this -> twoFactorAuthHelper -> redirectPathUponSuccessfulFrontendLogin ( ) ) ; }
Handle the front-end Two Factor Authorization login

@param  \Illuminate\Http\Request  $request
@return \Illuminate\Http\Response
Handle the front - end Two Factor Authorization login