/**
  * Initialize translate and html objects
  *
  * Called from {@link __construct()} as final step of object instantiation.
  *
  * @return void
  */
 public function init()
 {
     parent::init();
     // Tell the system where to return to after a survey has been taken
     $this->currentUser->setSurveyReturn($this->getRequest());
 }
 /**
  * Implements HTTP Basic auth
  */
 public function preDispatch()
 {
     parent::preDispatch();
     $action = strtolower($this->getRequest()->getActionName());
     if (in_array($action, $this->authActions)) {
         $auth = \Zend_Auth::getInstance();
         $this->auth = $auth;
         if (!$auth->hasIdentity()) {
             $config = array('accept_schemes' => 'basic', 'realm' => GEMS_PROJECT_NAME, 'nonce_timeout' => 3600);
             $adapter = new \Zend_Auth_Adapter_Http($config);
             $basicResolver = new \Zend_Auth_Adapter_Http_Resolver_File();
             //This is a basic resolver, use username:realm:password
             //@@TODO: move to a better db stored authentication system
             $basicResolver->setFile(GEMS_ROOT_DIR . '/var/settings/pwd.txt');
             $adapter->setBasicResolver($basicResolver);
             $request = $this->getRequest();
             $response = $this->getResponse();
             assert($request instanceof \Zend_Controller_Request_Http);
             assert($response instanceof \Zend_Controller_Response_Http);
             $adapter->setRequest($request);
             $adapter->setResponse($response);
             $result = $auth->authenticate($adapter);
             if (!$result->isValid()) {
                 $adapter->getResponse()->sendResponse();
                 print 'Unauthorized';
                 exit;
             }
         }
     }
 }