/** * Sends an email * * @param int $template The template to use * @param array $data * * @return bool * @throws \Exception */ public function send($template, $data = []) { // If we came in through a service call, make sure type is specified... if (!MailTemplates::contains($template)) { throw new \InvalidArgumentException('Invalid template "' . $template . '" specified.'); } $_settings = config('services.smtp-mail', []); $_service = array_get($_settings, 'smtp-service', 'localhost'); if (null === ($_mailTemplate = IfSet::getDeep($_settings, 'templates', $template))) { throw new \InvalidArgumentException('There was no associated template for type #' . $template); } if ('localhost' != $_service) { if (!isset($_settings['access-key']) || !isset($_settings['secret-key'])) { throw new \InvalidArgumentException('You must set both the "access-key" and "secret-key" in order to use this service.'); } } // Use template subject first, then local if (!isset($data['subject'])) { $data['subject'] = array_get($_mailTemplate, 'subject'); } $_templateFile = base_path() . '/config/templates/' . $_mailTemplate['template']; if (!file_exists($_templateFile)) { throw new \InvalidArgumentException('Template "' . $_templateFile . '" cannot be found.'); } // Build the message $data['__smtp-mail.settings__'] = $_settings; $_message = $this->_createMessage($_templateFile, $data); try { switch ($_service) { case 'localhost': $_transport = new \Swift_MailTransport(); break; default: if (null === ($_settings = IfSet::getDeep($_settings, 'services', $_service))) { throw new \RuntimeException('Service "' . $_service . '" is not properly configured.'); } // Create the transport $_transport = \Swift_SmtpTransport::newInstance($_settings['server-name'], $_settings['server-port'])->setUsername($_settings['access-key'])->setPassword($_settings['secret-key']); break; } // And the mailer... $_mailer = new \Swift_Mailer($_transport); $_recipients = $_mailer->send($_message, $_bogus); if (!empty($_bogus)) { $this->logger->error('Failed recipients: ' . implode(', ', $_bogus)); } if (empty($_recipients)) { $this->logger->error('Sending email to "' . $_message->getTo() . '" failed.'); } return $_recipients; } catch (\Exception $_ex) { // Something went awry $this->logger->error('Mail delivery exception: ' . $_ex->getMessage()); throw $_ex; } }
/** * Handle the command * * @return mixed */ public function fire() { parent::fire(); $_command = new RegisterJob($this->argument('owner-id'), strtolower($this->argument('owner-type'))); \Queue::push($_command); $_result = $_command->getResult(); if (empty($_result) || null === ($_id = IfSet::getDeep($_result, 'success', 'id'))) { $this->error('Results not found for request. Please try again.'); return 1; } try { /** @type AppKey $_key */ $_key = AppKey::findOrFail($_id); } catch (ModelNotFoundException $_ex) { $this->error('The key has been misplaced. Please try again.'); return 2; } $this->writeln('<info>Key pair id "' . $_id . '" created. Please keep secure.</info>'); $this->writeln(' <comment>client_id</comment>: <info>' . $_key->client_id . '</info>'); $this->writeln('<comment>client_secret</comment>: <info>' . $_key->client_secret . '</info>'); return 0; }
/** * Parses inbound data request for limits and sort and search * * @param int|string $defaultSort Default sort column name or number * @param array $columns */ protected function parseDataRequest($defaultSort = null, array &$columns = null) { $this->setDataTables(isset($_REQUEST, $_REQUEST['length'])); $this->setSkip(array_get($_REQUEST, 'start', 0)); $this->limit = array_get($_REQUEST, 'length', EnterpriseDefaults::DEFAULT_ITEMS_PER_PAGE); $this->order = $defaultSort; $this->search = trim(str_replace('\'', null, IfSet::getDeep($_REQUEST, 'search', 'value'))); if (null === ($_sortOrder = array_get($_REQUEST, 'order'))) { return; } // Parse the columns if (empty($this->columns) && empty($columns)) { $_dataColumns = array_get($_REQUEST, 'columns', []); $_columns = []; foreach ($_dataColumns as $_column) { if (null !== ($_name = array_get($_column, 'data', array_get($_column, 'name')))) { $_columns[] = $_name; } } if (!empty($_columns)) { $this->columns = $columns = $_columns; } } $_sort = []; if (is_array($_sortOrder)) { foreach ($_sortOrder as $_key => $_value) { if (isset($_value['column'])) { $_sort[$_value['column'] + 1] = array_get($_value, 'dir', 'ASC'); } } } elseif (is_string($_sortOrder)) { $this->order = $_sort[$_sortOrder] = array_get($_REQUEST, 'dir', 'ASC'); } if (!empty($_sort)) { $this->order = $_sort; } }