/** * @param TabTable $tab * @param UserTable $user * @param int $ui * @param array $postdata */ public function getCBpluginComponent( /** @noinspection PhpUnusedParameterInspection */ $tab, /** @noinspection PhpUnusedParameterInspection */ $user, /** @noinspection PhpUnusedParameterInspection */ $ui, /** @noinspection PhpUnusedParameterInspection */ $postdata ) { $returnUrl = $this->input( 'return', null, GetterInterface::BASE64 ); if ( $returnUrl ) { $returnUrl = base64_decode( $returnUrl ); } try { $hybrid = new cbconnectHybrid(); } catch ( Exception $e ) { cbRedirect( ( $returnUrl ? $returnUrl : 'index.php' ), $e->getMessage(), 'error' ); return; } $provider = $this->input( 'provider', null, GetterInterface::STRING ); $providerId = null; if ( ! $provider ) { $providerId = $this->input( 'hauth_start', null, GetterInterface::STRING ); if ( ! $providerId ) { $providerId = $this->input( 'hauth_done', null, GetterInterface::STRING ); } $provider = $hybrid->getProviderFromId( $providerId ); } else { $providerId = $hybrid->getIdFromProvider( $provider ); } $action = $this->input( 'action', null, GetterInterface::STRING ); $hybridAuth = null; $error = null; try { $hybridAuth = $hybrid->getHybridAuth(); /** @var Hybrid_Storage $storage */ $storage = $hybridAuth->storage(); if ( $storage ) { if ( ! $returnUrl ) { $redirectUrl = $storage->get( 'redirect_url' ); if ( $redirectUrl ) { $returnUrl = base64_decode( $redirectUrl ); } } else { $storage->set( 'redirect_url', base64_encode( $returnUrl ) ); } } } catch ( Exception $e ) { $error = $e->getMessage(); } if ( ! $returnUrl ) { $returnUrl = 'index.php'; } if ( ( ! $hybridAuth ) || ( ! $this->params->get( $provider . '_enabled', false, GetterInterface::BOOLEAN ) ) ) { if ( ! $error ) { $error = CBTxt::T( 'PROVIDER_NOT_AVAILABLE', '[provider] is not available.', array( '[provider]' => $providerId ) ); } cbRedirect( $this->_returnUrl, $error, 'error' ); return; } $this->_hybrid = $hybrid; $this->_hybridAuth = $hybridAuth; $this->_provider = $provider; $this->_providerId = $providerId; $this->_providerField = $hybrid->getProviderField( $provider ); $this->_providerName = $hybrid->getProviderName( $provider ); $this->_returnUrl = $returnUrl; switch ( $action ) { case 'authenticate': $this->authenticate(); break; case 'endpoint': $this->endpoint(); break; } }
/** * Mutator: * Prepares field data for saving to database (safe transfer from $postdata to $user) * Override * * @param FieldTable $field * @param UserTable $user RETURNED populated: touch only variables related to saving this field (also when not validating for showing re-edit) * @param array $postdata Typically $_POST (but not necessarily), filtering required. * @param string $reason 'edit' for save user edit, 'register' for save registration */ public function prepareFieldDataSave( &$field, &$user, &$postdata, $reason ) { $hybrid = new cbconnectHybrid(); $fieldName = $field->get( 'name' ); $provider = $hybrid->getProviderFromField( $fieldName ); $providerId = $hybrid->getIdFromProvider( $provider ); $currentValue = $user->get( $fieldName ); $value = cbGetParam( $postdata, $fieldName ); if ( $currentValue && ( $user->get( 'id' ) == Application::MyUser()->get( 'id' ) ) ) { if ( is_array( $value ) ) { if ( isset( $value[0] ) && ( $value[0] == 1 ) ) { $postdata[$fieldName] = ''; } } $value = cbGetParam( $postdata, $fieldName ); if ( $value === '' ) { try { $adapter = $hybrid->getAdapter( $providerId ); if ( $adapter ) { switch( $provider ) { case 'facebook': /** @noinspection PhpUndefinedMethodInspection */ $adapter->api()->api( '/me/permissions', 'DELETE' ); break; } $adapter->logout(); } } catch ( Exception $e ) {} } } if ( ( ! Application::Cms()->getClientId() ) && $user->get( 'id' ) && $currentValue && ( $value !== '' ) ) { $postdata[$fieldName] = $currentValue; } parent::prepareFieldDataSave( $field, $user, $postdata, $reason ); }