/** * Preview action * * @return void */ public function previewAction() { $request = $this->getRequest(); Logger::debug(__METHOD__ . ':: referrer = ' . $request->getServer('HTTP_REFERER', '')); Logger::debug(__METHOD__ . ':: siteDomain = ' . Zend_Registry::get('siteDomain')); Logger::debug(__METHOD__ . ':: regex = ' . '/https?:\\/\\/' . preg_quote(Zend_Registry::get('siteDomain'), '/') . '\\/site\\/theme/'); if (!preg_match('/https?:\\/\\/' . preg_quote(Zend_Registry::get('siteDomain'), '/') . '\\/site\\/theme/', $request->getServer('HTTP_REFERER', ''))) { Logger::crit(__METHOD__ . ':: Bad referrer'); throw new Exception(''); } Zend_Layout::getMvcInstance()->setLayoutPath(realpath(APPLICATION_PATH . '/layouts')); $this->view->assign(array()); #$this->view->setScriptPath(APPLICATION_PATH . '/views/scripts/index'); #$this->view->render('home.phtml'); $this->view->setScriptPath(APPLICATION_PATH . '/views/scripts'); #$this->view->render('index/home.phtml'); #$this->_helper->viewRenderer->setNoRender(); $this->_helper->viewRenderer->renderScript('index/home.phtml'); }
public function testCrit() { Logger::crit('foo'); $this->assertEquals(1, preg_match('/CRIT \\(' . Zend_Log::CRIT . '\\): foo/', file_get_contents(Logger::$logStream))); }
/** * Send email address verification email to user * * @param User $user * @param Zend_Mail_Transport_Abstract $transport [Optional] Zend mail transport class * @return void */ public static function sendVerificationEmail(User $user, Zend_Mail_Transport_Abstract $transport = null) { $serverUrlHelper = new Zend_View_Helper_ServerUrl(); $urlHelper = HelperBroker::getStaticHelper('url'); $siteDomain = preg_replace('/^https?:\\/\\//', '', $serverUrlHelper->serverUrl()); $siteName = Zend_Registry::get('siteName'); $config = Zend_Registry::get('config'); $from = 'noreply@' . $siteDomain; if (!empty($config->mail) && !empty($config->mail->from)) { $from = $config->mail->from; } if (null === $transport) { if (Zend_Session::$_unitTestEnabled) { $transport = new MockMailTransport(); } else { if (!empty($config->mail) && !empty($config->mail->smtp) && !empty($config->mail->smtp->host)) { $options = $config->mail->smtp->toArray(); unset($options['host']); $transport = new Zend_Mail_Transport_Smtp($config->mail->smtp->host, $options); } } } UserEmailVerificationService::collectGarbage(); // @todo cronjob?; should also remove any unverified user accounts $verificationToken = sha1(mt_rand() . $user->getEmail() . mt_rand()); if (APPLICATION_ENV === 'testing') { $verificationLink = $serverUrlHelper->serverUrl() . '/verifyEmail/' . $verificationToken; } else { // @codeCoverageIgnoreStart $verificationLink = $serverUrlHelper->serverUrl() . $urlHelper->url(array('token' => $verificationToken), 'verifyEmail'); } // @codeCoverageIgnoreEnd UserEmailVerificationService::create(new UserEmailVerification(array('user' => $user, 'token' => $verificationToken, 'requestDate' => new DateTime()))); $text = 'Hello ' . $user->getUsername() . ', Thank you for registering with ' . $siteName . '. To activate your account and complete the registration process, please click the following link: ' . $verificationLink . '. You are receiving this email because someone recently registered on our site and provided <' . $user->getEmail() . '> as their ema il address. If you did not recently register at ' . $siteDomain . ', then please ignore this email. Your information will be remov ed from our system within 24 hours. Thank you, The ' . $siteName . ' Team '; $html = '<p>Hello ' . $user->getUsername() . ',</p> <p>Thank you for registering with ' . $siteName . '. To activate your account and complete the registration process, please click the following link: <a href="' . $verificationLink . '" title="Verify your email address">' . $verificationLink . '</a>.</p> <p>You are receiving this email because someone recently registered on our site and provided <' . $user->getEmail() . '> as their email address. If you did not recently register at ' . $siteDomain . ', then please ignore this email. Your information will be removed from our system within 24 hours.</p> <p>Thank you,<br> The ' . $siteName . ' Team</p> '; try { Logger::info('Attempting to send email to \'' . $user->getEmail() . '\'.'); $mail = new Zend_Mail('utf-8'); $mail->setFrom($from, $siteName)->setSubject('[' . $siteName . '] Email Verification')->setBodyText($text)->setBodyHtml($html)->addTo($user->getEmail()); $mail->send($transport); } catch (Exception $e) { Logger::crit($e->getMessage()); throw $e; } }
/** * Error action * * @return void */ public function errorAction() { $errors = $this->_getParam('error_handler'); switch ($errors->type) { case ErrorHandler::EXCEPTION_NO_ROUTE: case ErrorHandler::EXCEPTION_NO_CONTROLLER: case ErrorHandler::EXCEPTION_NO_ACTION: // 404 error -- controller or action not found $this->getResponse()->setHttpResponseCode(404); $this->view->message = 404; break; default: // application error $this->getResponse()->setHttpResponseCode(500); if ($errors->exception instanceof ApiControllerException) { $this->view->message = $errors->exception->getMessage(); } elseif ($errors->exception) { $this->view->message = 'Application error: ' . $errors->exception->getMessage(); } else { $this->view->message = 'Application error: Unknown error'; } } // Log exception, if logger available Logger::crit(__METHOD__ . ':: ' . $this->view->message . ' - ' . $errors->exception); // Conditionally display exceptions if ($this->getInvokeArg('displayExceptions') == true) { $this->view->exception = $errors->exception; } if (null === $this->getRequest()->getParam('format')) { $this->view->request = $errors->request; } if ($this->view->message === 404) { $this->view->pageTitle(' - Page not found'); } else { $this->view->pageTitle(' - An error occurred'); } $this->getRequest()->setParams(array('controller' => 'error', 'action' => 'error')); }