/** * 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); }
/** * Initialize error description */ public function init() { parent::init(); $errors = $this->_getParam('error_handler'); if (!$errors || !$errors instanceof ArrayObject) { $this->message = 'You have reached the error page'; return; } switch ($errors->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: $this->statusCode = 404; $this->content->message = 'Method does not exists'; break; default: // application error $this->statusCode = $errors->exception->getCode(); $this->content->message = $errors->exception->getMessage(); break; } }