src/Http/Controllers/Adminarea/AccountTwoFactorController.php
public function updateTotp(AccountTwoFactorTotpProcessRequest $request, Google2FA $totpProvider)
    {
        $currentUser = $request->user($this->getGuard());
        $twoFactor = $currentUser->getTwoFactor();
        $secret = array_get($twoFactor, 'totp.secret');
        $backup = array_get($twoFactor, 'totp.backup');
        $backupAt = array_get($twoFactor, 'totp.backup_at');

        if ($totpProvider->verifyKey($secret, $request->get('token'))) {
            $twoFactor['totp'] = [
                'enabled' => true,
                'secret' => $secret,
                'backup' => $backup ?? $this->generateTotpBackups(),
                'backup_at' => $backupAt ?? now()->toDateTimeString(),
            ];

            // Update TwoFactor settings
            $currentUser->fill(['two_factor' => $twoFactor])->forceSave();

            return intend([
                'back' => true,
                'with' => ['success' => trans('cortex/auth::messages.verification.twofactor.totp.enabled')],
            ]);
        }

        return intend([
            'back' => true,
            'withErrors' => ['token' => trans('cortex/auth::messages.verification.twofactor.totp.invalid_token')],
        ]);
    }
public function updateTotp(AccountTwoFactorTotpProcessRequest $request, Google2FA $totpProvider)
    {
        $currentUser = $request->user($this->getGuard());
        $twoFactor = $currentUser->getTwoFactor();
        $secret = array_get($twoFactor, 'totp.secret');
        $backup = array_get($twoFactor, 'totp.backup');
        $backupAt = array_get($twoFactor, 'totp.backup_at');

        if ($totpProvider->verifyKey($secret, $request->get('token'))) {
            $twoFactor['totp'] = [
                'enabled' => true,
                'secret' => $secret,
                'backup' => $backup ?? $this->generateTotpBackups(),
                'backup_at' => $backupAt ?? now()->toDateTimeString(),
            ];

            // Update TwoFactor settings
            $currentUser->fill(['two_factor' => $twoFactor])->forceSave();

            return intend([
                'back' => true,
                'with' => ['success' => trans('cortex/auth::messages.verification.twofactor.totp.enabled')],
            ]);
        }

        return intend([
            'back' => true,
            'withErrors' => ['token' => trans('cortex/auth::messages.verification.twofactor.totp.invalid_token')],
        ]);
    }
public function updateTotp ( AccountTwoFactorTotpProcessRequest $ request , Google2FA $ totpProvider ) { $ currentUser = $ request -> user ( $ this -> getGuard ( ) ) ; $ twoFactor = $ currentUser -> getTwoFactor ( ) ; $ secret = array_get ( $ twoFactor , 'totp.secret' ) ; $ backup = array_get ( $ twoFactor , 'totp.backup' ) ; $ backupAt = array_get ( $ twoFactor , 'totp.backup_at' ) ; if ( $ totpProvider -> verifyKey ( $ secret , $ request -> get ( 'token' ) ) ) { $ twoFactor [ 'totp' ] = [ 'enabled' => true , 'secret' => $ secret , 'backup' => $ backup ?? $ this -> generateTotpBackups ( ) , 'backup_at' => $ backupAt ?? now ( ) -> toDateTimeString ( ) , ] ; // Update TwoFactor settings $ currentUser -> fill ( [ 'two_factor' => $ twoFactor ] ) -> forceSave ( ) ; return intend ( [ 'back' => true , 'with' => [ 'success' => trans ( 'cortex/auth::messages.verification.twofactor.totp.enabled' ) ] , ] ) ; } return intend ( [ 'back' => true , 'withErrors' => [ 'token' => trans ( 'cortex/auth::messages.verification.twofactor.totp.invalid_token' ) ] , ] ) ; }
Process the TwoFactor TOTP enable form.

@param \Cortex\Auth\Http\Requests\Adminarea\AccountTwoFactorTotpProcessRequest $request
@param \PragmaRX\Google2FA\Google2FA                                           $totpProvider

@return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
Process the TwoFactor TOTP enable form .