src/Http/Controllers/Frontarea/PhoneVerificationController.php
public function process(PhoneVerificationProcessRequest $request)
    {
        // Guest trying to authenticate through TwoFactor
        if (($attemptUser = $request->attemptUser($this->getGuard())) && $this->attemptTwoFactor($attemptUser, $request->get('token'))) {
            auth()->guard($this->getGuard())->login($attemptUser, $request->session()->get('cortex.auth.twofactor.remember'));
            $request->session()->forget('cortex.auth.twofactor'); // @TODO: Do we need to forget session, or it's already gone after login?

            return intend([
                'intended' => route('frontarea.home'),
                'with' => ['success' => trans('cortex/auth::messages.auth.login')],
            ]);
        }

        // Logged in user OR A GUEST trying to verify phone
        if (($user = $request->user($this->getGuard()) ?? app('cortex.auth.member')->whereNotNull('phone')->where('phone', $request->get('phone'))->first()) && $this->isValidTwoFactorPhone($user, $request->get('token'))) {
            // Profile update
            $user->fill([
                'phone_verified_at' => now(),
            ])->forceSave();

            return intend([
                'url' => route('frontarea.account.settings'),
                'with' => ['success' => trans('cortex/auth::messages.verification.phone.verified')],
            ]);
        }

        return intend([
            'back' => true,
            'withErrors' => ['token' => trans('cortex/auth::messages.verification.twofactor.invalid_token')],
        ]);
    }
public function process(PhoneVerificationProcessRequest $request)
    {
        // Guest trying to authenticate through TwoFactor
        if (($attemptUser = $request->attemptUser($this->getGuard())) && $this->attemptTwoFactor($attemptUser, $request->get('token'))) {
            auth()->guard($this->getGuard())->login($attemptUser, $request->session()->get('cortex.auth.twofactor.remember'));
            $request->session()->forget('cortex.auth.twofactor'); // @TODO: Do we need to forget session, or it's already gone after login?

            return intend([
                'intended' => route('frontarea.home'),
                'with' => ['success' => trans('cortex/auth::messages.auth.login')],
            ]);
        }

        // Logged in user OR A GUEST trying to verify phone
        if (($user = $request->user($this->getGuard()) ?? app('cortex.auth.member')->whereNotNull('phone')->where('phone', $request->get('phone'))->first()) && $this->isValidTwoFactorPhone($user, $request->get('token'))) {
            // Profile update
            $user->fill([
                'phone_verified_at' => now(),
            ])->forceSave();

            return intend([
                'url' => route('frontarea.account.settings'),
                'with' => ['success' => trans('cortex/auth::messages.verification.phone.verified')],
            ]);
        }

        return intend([
            'back' => true,
            'withErrors' => ['token' => trans('cortex/auth::messages.verification.twofactor.invalid_token')],
        ]);
    }
public function process ( PhoneVerificationProcessRequest $ request ) { // Guest trying to authenticate through TwoFactor if ( ( $ attemptUser = $ request -> attemptUser ( $ this -> getGuard ( ) ) ) && $ this -> attemptTwoFactor ( $ attemptUser , $ request -> get ( 'token' ) ) ) { auth ( ) -> guard ( $ this -> getGuard ( ) ) -> login ( $ attemptUser , $ request -> session ( ) -> get ( 'cortex.auth.twofactor.remember' ) ) ; $ request -> session ( ) -> forget ( 'cortex.auth.twofactor' ) ; // @TODO: Do we need to forget session, or it's already gone after login? return intend ( [ 'intended' => route ( 'frontarea.home' ) , 'with' => [ 'success' => trans ( 'cortex/auth::messages.auth.login' ) ] , ] ) ; } // Logged in user OR A GUEST trying to verify phone if ( ( $ user = $ request -> user ( $ this -> getGuard ( ) ) ?? app ( 'cortex.auth.member' ) -> whereNotNull ( 'phone' ) -> where ( 'phone' , $ request -> get ( 'phone' ) ) -> first ( ) ) && $ this -> isValidTwoFactorPhone ( $ user , $ request -> get ( 'token' ) ) ) { // Profile update $ user -> fill ( [ 'phone_verified_at' => now ( ) , ] ) -> forceSave ( ) ; return intend ( [ 'url' => route ( 'frontarea.account.settings' ) , 'with' => [ 'success' => trans ( 'cortex/auth::messages.verification.phone.verified' ) ] , ] ) ; } return intend ( [ 'back' => true , 'withErrors' => [ 'token' => trans ( 'cortex/auth::messages.verification.twofactor.invalid_token' ) ] , ] ) ; }
Process the phone verification form.

@param \Cortex\Auth\B2B2C2\Http\Requests\Frontarea\PhoneVerificationProcessRequest $request

@return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
Process the phone verification form .