public function getErrors(Config $cfg) { $i18n = Localization::getTranslator(); $walletSettings = []; $emailSettings = []; $providerClass = ''; try { $provider = $cfg->getWalletProvider(); $providerClass = get_class($provider); $provider->verifyOwnership(); } catch (Exception $e) { if (strpos($providerClass, 'CoinbaseWallet') !== false) { $walletSettings[] = ['id' => '#wallet-coinbaseApiKey-error', 'error' => $e->getMessage()]; } else { $walletSettings[] = ['id' => '#wallet-id-error', 'error' => $e->getMessage()]; } } try { $t = new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl'); $t->setUsername($cfg->getEmailUsername())->setPassword($cfg->getEmailPassword())->start(); } catch (Exception $e) { $emailSettings[] = ['id' => '#email-username-error', 'error' => $e->getMessage()]; } $errors = []; if (!empty($pricingSettings)) { $errors['#pricing-settings'] = self::getPricingErrorsFromConfig($cfg); } if (!empty($walletSettings)) { $errors['#wallet-settings'] = $walletSettings; } if (!empty($emailSettings)) { $errors['#email-settings'] = $emailSettings; } return $errors; }
public function send($lastOverride = false) { $i18n = Localization::getTranslator(); $lastFn = '/home/pi/phplog/last-tx-sent'; $last = 0; if (file_exists($lastFn)) { $last = intval(trim(file_get_contents($lastFn))); } if ($lastOverride !== false) { $last = $lastOverride; } $csvMaker = Container::dispense('TransactionCSV'); $config = Admin::volatileLoad()->getConfig(); $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername($config->getEmailUsername())->setPassword($config->getEmailPassword()); $msg = Swift_Message::newInstance()->setSubject($config->getMachineName() . $i18n->_(': Transaction Log'))->setFrom([$config->getEmailUsername() => $config->getMachineName()])->setTo(array($config->getEmailUsername()))->setBody($i18n->_('See attached for transaction log.')); $file = $csvMaker->save($last); if (!$file) { throw new Exception('Unable to save CSV'); } $msg->attach(Swift_Attachment::fromPath($file)); file_put_contents($lastFn, $csvMaker->getLastID()); $mailer = Swift_Mailer::newInstance($transport); if (!$mailer->send($msg)) { throw new Exception('Unable to send: unkown cause'); } }
/** * Imports symbol table into template file's execution context, rendering * as the file dictates * * @param array $symbols to import * @return void */ public function render(array $symbols = array()) { extract($symbols); unset($symbols); $html = new HTML(); $i18n = Localization::getTranslator(); include $this->getPage(); }
public function send() { $i18n = Localization::getTranslator(); $config = Admin::volatileLoad()->getConfig(); $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername($config->getEmailUsername())->setPassword($config->getEmailPassword()); $msg = Swift_Message::newInstance()->setSubject($config->getMachineName() . $i18n->_(': Transaction Log'))->setFrom([$config->getEmailUsername() => $config->getMachineName()])->setTo(array($config->getEmailUsername()))->setBody($i18n->_('There have been no transactions since the last email.')); $mailer = Swift_Mailer::newInstance($transport); if (!$mailer->send($msg)) { throw new Exception('Unable to send: unkown cause'); } }
public function getErrors(Post $post) { $i18n = Localization::getTranslator(); //TODO: implement range checking on modifier values, and static pricing $walletSettings = []; if (empty($post['wallet']['id'])) { $walletSettings[] = ['id' => '#wallet-id-error', 'error' => $i18n->_('A valid Blockchain.info wallet id is required.')]; } if (empty($post['wallet']['mainPass'])) { $walletSettings[] = ['id' => '#wallet-mainPass-error', 'error' => $i18n->_('Your respective Blockchain.info password is required.')]; } if (empty($post['wallet']['fromAddress'])) { $walletSettings[] = ['id' => '#wallet-fromAddress-error', 'error' => $i18n->_('An address controlled by your Blockchain.info wallet is required to send from.')]; } elseif (!AddressUtility::checkAddress($post['wallet']['fromAddress'])) { $walletSettings[] = ['id' => '#wallet-fromAddress-error', 'error' => $i18n->_('A valid Bitcoin address is required.')]; } $emailUser = @$post['email']['username']; $emailSettings = []; if (empty($emailUser)) { $emailSettings[] = ['id' => '#email-username-error', 'error' => $i18n->_('A valid email address is required.')]; } elseif (filter_var($emailUser, FILTER_VALIDATE_EMAIL) !== $emailUser) { $emailSettings[] = ['id' => '#email-username-error', 'error' => $i18n->_('Email address entered is not valid.')]; } if (empty($post['email']['password'])) { $emailSettings[] = ['id' => '#email-password-error', 'error' => $i18n->_('Email password is required.')]; } $passwordSettings = []; if (strlen(@$post['admin_password']) < 5) { $passwordSettings[] = ['id' => '#password-error', 'error' => $i18n->_('Minimum password length is 5 characters.')]; } if (@$post['admin_password'] !== @$post['confirm_admin_password']) { $passwordSettings[] = ['id' => '#password-error', 'error' => $i18n->_('Admin passwords must match')]; } $transactionSettings = []; if (isset($post['transactions']['maximum'])) { if (!preg_match('#^[0-9]+$#', $post['transactions']['maximum'])) { $transactionSettings[] = ['id' => '#maximum-errors', 'error' => $i18n->_('Maximum transaction value must be a positive integer.')]; } } $localeSettings = []; if (isset($post['locale'])) { if (!Localization::localePresent($post['locale'])) { $transactionSettings[] = ['id' => '#locale-errors', 'error' => $i18n->_('Unkown Locale.')]; } } $errors = []; if (!empty($transactionSettings)) { $errors['#locale-settings'] = $localeSettings; } if (!empty($transactionSettings)) { $errors['#transaction-settings'] = $transactionSettings; } if (!empty($passwordSettings)) { $errors['#password-settings'] = $passwordSettings; } if (!empty($pricingSettings)) { $errors['#pricing-settings'] = self::getPricingErrors($post); } if (!empty($walletSettings)) { $errors['#wallet-settings'] = $walletSettings; } if (!empty($emailSettings)) { $errors['#email-settings'] = $emailSettings; } return $errors; }