public function indexAction() { do { $message = App_Model_Queue::pop(App_Model_Queue::EMAIL); if ($message) { $user = App_Model_User::fetchOne(['id' => (string) $message->user]); $config = $user->data['mail']; Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Smtp($config['server'], ['auth' => $config['auth'], 'username' => $config['username'], 'password' => $config['password'], 'port' => $config['port'], 'ssl' => $config['ssl']])); $mail = new Zend_Mail('UTF-8'); foreach ($message->receivers as $receiver) { $mail->addTo($receiver['email'], $receiver['name']); } $this->writeLine("------------------------------------------------"); $this->writeLine("to: " . print_r($message->receivers, true)); $this->writeLine("from: " . implode(', ', [$user->data['mail']['username'], $user->data['mail']['name']])); $this->writeLine("Subject: " . $message->subject); $mail->setSubject($message->subject); $mail->setBodyHtml($message->content); $mail->setFrom($user->data['mail']['username'], $user->data['mail']['name']); $this->writeLine("Start sending..."); try { $mail->send(); } catch (Exception $e) { $this->writeLine($e->getMessage()); } $this->writeLine('>>>> Done'); sleep(1); } } while (true); }
public function indexAction() { $config = Zend_Registry::get('config')['sender']; do { $message = App_Model_Queue::pop(App_Model_Queue::SMS); if ($message) { $user = App_Model_User::fetchOne(['id' => (string) $message->user]); $settings = $user->data['sms']; $settings['uri'] = $config['sms']['uri']; \Smsc\Smsc::setConfig($settings); $sms = new \Smsc\Smsc(); $this->writeLine("------------------------------------------------"); $this->writeLine("------------------------------------------------"); $this->writeLine("sending message: " . $message->content); $this->writeLine("to: " . implode(', ', array_values($message->receivers))); $this->writeLine("from: " . $user->data['sms']['sender']); $sms->setReceivers($message->receivers); $sms->setMessage($message->content); $this->writeLine("Start sending..."); try { $sms->send(); } catch (Exception $e) { $this->writeLine($e->getMessage()); } $this->writeLine('>>>> Done'); sleep(1); } } while (true); }
public function authAction() { $user = App_Model_User::fetchOne(['email' => $this->getParam('email'), 'password' => $this->getParam('password')]); if (!$user) { throw new App_Exception_UserWasNotFound(); } $user->addToken(); $this->content->user = App_Map_User::execute($user); }
/** * Authorize user by token * * @throws App_Exception_Forbidden */ public function init() { parent::init(); $this->user = App_Model_User::fetchOne(['tokens' => ['$in' => [$this->getRequest()->getHeader('x-auth')]]]); if (!$this->user) { throw new App_Exception_Forbidden(); } $config = Zend_Registry::get('config'); App_Service_Storage::setConfig($config['storage']); App_Service_Storage::setUser($this->user); }
/** * @throws Exception */ public function init() { parent::init(); $token = $this->getRequest()->getHeader('x-auth'); if ($token) { $this->user = App_Model_User::fetchOne(['tokens' => ['$in' => [$token]]]); if ($this->user) { return; } } throw new Exception('Not authorized', 403); }