/**
  * This function handles a login attempt and validates the credentials
  *
  * @return void
  */
 public function loginAction()
 {
     // Force user over to SSL if not already
     # if ($_SERVER['SERVER_PORT'] != 443) {
     #    $this->_redirect($this->_params->url->connectLogin);
     # }
     $this->_helper->layout->setLayout('login');
     $auth = Zend_Auth::getInstance();
     $auth->setStorage(new Zend_Auth_Storage_Session('hl_connect'));
     if ($auth->hasIdentity()) {
         // User is already logged in so just push them into the system
         $this->_redirect('/');
     }
     // Intantiate form definition
     $pageForm = new Connect_Form_Login();
     // If we have a refno, try to prepopulate the form with ASN
     if (preg_match('/^([0-9]+\\.[0-9]+)$/', $this->getRequest()->getParam('refno'), $matches)) {
         if (isset($matches[1])) {
             $refno = $matches[1];
             $enquiryDatasource = new Datasource_ReferencingLegacy_Enquiry();
             $agentID = $enquiryDatasource->getReferenceAgentID($this->getRequest()->getParam('refno'));
             if ($agentID) {
                 $pageForm->agentschemeno->setValue($agentID);
             }
         }
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         if ($this->_helper->auth->attemptLogin($pageForm)) {
             $this->_redirect($this->getRequest()->getRequestUri());
         } else {
             $this->view->loginErrorMessage = "Invalid user or password";
         }
     }
     $params = Zend_Registry::get('params');
     $this->view->pageTitle = 'Log In';
     $this->view->homePage = $params->homelet->get('domain');
     $this->view->form = $pageForm;
 }
 /**
  * Check this reference against an ASN to check for ownership
  * 
  * @param int $ownerAgentId Agent ID of the agent we're checking for ownership
  * @param string $refno Reference number of the reference to check
  * @return boolean
  */
 private function _isReferenceOwnedBy($refno, $ownerAgentId)
 {
     // Find the ASN of the reference
     $enquiryDatasource = new Datasource_ReferencingLegacy_Enquiry();
     $agentID = $enquiryDatasource->getReferenceAgentID($refno);
     return $agentID == $ownerAgentId;
 }