public function createAuthenticationManager(PostmanTransport $transport, PostmanOptions $options, PostmanOAuthToken $authorizationToken, PostmanConfigTextHelper $scribe = null) { $authenticationType = $options->getAuthenticationType(); $hostname = $options->getHostname(); $clientId = $options->getClientId(); $clientSecret = $options->getClientSecret(); $senderEmail = $options->getMessageSenderEmail(); if (!isset($scribe)) { $transport = PostmanTransportRegistry::getInstance()->getCurrentTransport(); $scribe = PostmanConfigTextHelperFactory::createScribe($hostname, $transport); } $redirectUrl = $scribe->getCallbackUrl(); if ($transport->isOAuthUsed($options->getAuthenticationType()) && $transport->isServiceProviderGoogle($hostname)) { $authenticationManager = new PostmanGoogleAuthenticationManager($clientId, $clientSecret, $authorizationToken, $redirectUrl, $senderEmail); } else { if ($transport->isOAuthUsed($options->getAuthenticationType()) && $transport->isServiceProviderMicrosoft($hostname)) { $authenticationManager = new PostmanMicrosoftAuthenticationManager($clientId, $clientSecret, $authorizationToken, $redirectUrl); } else { if ($transport->isOAuthUsed($options->getAuthenticationType()) && $transport->isServiceProviderYahoo($hostname)) { $authenticationManager = new PostmanYahooAuthenticationManager($clientId, $clientSecret, $authorizationToken, $redirectUrl); } else { $authenticationManager = new PostmanNonOAuthAuthenticationManager(); } } } $this->logger->debug('Created ' . get_class($authenticationManager)); return $authenticationManager; }
/** * This Ajax function retrieves the OAuth redirectUrl and help text for based on the SMTP hostname supplied */ function getWizardConfigurationViaAjax() { $this->logger->debug('in getWizardConfiguration'); $originalSmtpServer = $this->getRequestParameter('original_smtp_server'); $queryHostData = $this->getHostDataFromRequest(); $userPortOverride = $this->getUserPortOverride(); $userAuthOverride = $this->getUserAuthOverride(); // determine a configuration recommendation $winningRecommendation = $this->getWinningRecommendation($queryHostData, $userPortOverride, $userAuthOverride, $originalSmtpServer); $this->logger->trace('winning recommendation:'); $this->logger->trace($winningRecommendation); // create user override menu $overrideMenu = $this->createOverrideMenu($queryHostData, $winningRecommendation, $userPortOverride, $userAuthOverride); $this->logger->trace('override menu:'); $this->logger->trace($overrideMenu); // create the reponse $response = array(); $configuration = array(); $response['referer'] = 'wizard'; if (isset($userPortOverride) || isset($userAuthOverride)) { $configuration['user_override'] = true; } if (isset($winningRecommendation)) { // create an appropriate (theoretical) transport $transport = PostmanTransportRegistry::getInstance()->getTransport($winningRecommendation['transport']); $scribe = PostmanConfigTextHelperFactory::createScribe($winningRecommendation['hostname'], $transport); $this->populateResponseFromScribe($scribe, $configuration); $this->populateResponseFromTransport($winningRecommendation, $configuration); $response['override_menu'] = $overrideMenu; $response['configuration'] = $configuration; $this->logger->trace('configuration:'); $this->logger->trace($configuration); wp_send_json_success($response); } else { /* translators: where %s is the URL to the Connectivity Test page */ $configuration['message'] = sprintf(__('Postman can\'t find any way to send mail on your system. Run a <a href="%s">connectivity test</a>.', 'postman-smtp'), PostmanViewController::getPageUrl(PostmanViewController::PORT_TEST_SLUG)); $response['configuration'] = $configuration; $this->logger->trace('configuration:'); $this->logger->trace($configuration); wp_send_json_error($response); } }
/** * Check for configuration errors and displays messages to the user */ public function check_for_configuration_errors() { $options = PostmanOptions::getInstance(); $authToken = PostmanOAuthToken::getInstance(); // did Postman fail binding to wp_mail()? if ($this->wpMailBinder->isUnboundDueToException()) { // this message gets printed on ANY WordPress admin page, as it's a pretty fatal error that // may occur just by activating a new plugin if (PostmanUtils::isAdmin() && is_admin()) { // I noticed the wpMandrill and SendGrid plugins have the exact same error message here // I've adopted their error message as well, for shits and giggles .... :D $this->messageHandler->addError(__('Postman: wp_mail has been declared by another plugin or theme, so you won\'t be able to use Postman until the conflict is resolved.', 'postman-smtp')); // $this->messageHandler->addError ( __ ( 'Error: Postman is properly configured, but the current theme or another plugin is preventing service.', 'postman-smtp' ) ); } } else { if (!$this->wpMailBinder->isBound()) { $transport = PostmanTransportRegistry::getInstance()->getCurrentTransport(); $scribe = PostmanConfigTextHelperFactory::createScribe($options->getHostname(), $transport); $readyToSend = PostmanTransportRegistry::getInstance()->isPostmanReadyToSendEmail($options, $authToken); $virgin = $options->isNew(); if (!$readyToSend && !$virgin) { // if the configuration is broken, and the user has started to configure the plugin // show this error message $message = PostmanTransportRegistry::getInstance()->getCurrentTransport()->getMisconfigurationMessage($scribe, $options, $authToken); if ($message) { // output the warning message $this->logger->warn('Transport has a configuration problem: ' . $message); // on pages that are Postman admin pages only, show this error message if (PostmanUtils::isAdmin() && PostmanUtils::isCurrentPagePostmanAdmin()) { $this->messageHandler->addError($message); } } } // on pages that are NOT Postman admin pages only, show this error message if (!PostmanUtils::isCurrentPagePostmanAdmin() && !$readyToSend) { // on pages that are *NOT* Postman admin pages only.... // if the configuration is broken // show this error message add_action('admin_notices', array($this, 'display_configuration_required_warning')); } } } }
/** */ public function registerHooks() { // only administrators should be able to trigger this if (PostmanUtils::isAdmin()) { // $transport = PostmanTransportRegistry::getInstance()->getCurrentTransport(); $this->oauthScribe = PostmanConfigTextHelperFactory::createScribe($this->options->getHostname(), $transport); // register Ajax handlers new PostmanManageConfigurationAjaxHandler(); new PostmanGetHostnameByEmailAjaxController(); new PostmanGetPortsToTestViaAjax(); new PostmanPortTestAjaxController($this->options); new PostmanImportConfigurationAjaxController($this->options); new PostmanGetDiagnosticsViaAjax($this->options, $this->authorizationToken); new PostmanSendTestEmailAjaxController(); // register content handlers $viewController = new PostmanViewController($this->rootPluginFilenameAndPath, $this->options, $this->authorizationToken, $this->oauthScribe, $this); // register action handlers $this->registerAdminPostAction(self::PURGE_DATA_SLUG, 'handlePurgeDataAction'); $this->registerAdminPostAction(PostmanUtils::REQUEST_OAUTH2_GRANT_SLUG, 'handleOAuthPermissionRequestAction'); if (PostmanUtils::isCurrentPagePostmanAdmin()) { $this->checkPreRequisites(); } } }