/**
  * Controls the ProspectiveLandlord form.
  */
 public function prospectiveLandlordAction()
 {
     $session = new Zend_Session_Namespace('referencing_global');
     $session->currentFlowItem = Model_Referencing_DataEntry_FlowItems::PROSPECTIVE_LANDLORD;
     $prospectiveLandlordForm = new LandlordsReferencing_Form_ProspectiveLandlord();
     //Tell page to use AJAX validation as we go
     $this->view->headScript()->appendScript('var ajaxValidate = true; var ajaxValidatePage = "prospective-landlord";');
     //Extract clean values, save them and validate
     $request = $this->getRequest();
     $data = $request->getPost();
     if ($request->isPost()) {
         if ($prospectiveLandlordForm->isValid($data)) {
             //Save the form data.
             $prospectiveLandlordForm->saveData();
             //See if the the reference should be emailed to reference subject (and therefore involve
             //multiple users).
             $referencingManager = new Manager_Referencing_Reference();
             $reference = $referencingManager->getMinimalReference($session->referenceId);
             if ($reference->completionMethod == Model_Referencing_ReferenceCompletionMethods::TWO_STEP) {
                 //Email link to reference subject then stop.
                 $this->_helper->redirector->gotoUrl('/landlords/referencing/email-link-start');
                 return;
             }
             //Everything has been saved ok so navigate to next step.
             $this->_despatchToNext();
             return;
         } else {
             $this->view->errors = true;
             $previouslyLoaded = "var previouslyLoaded = true;\n";
             $this->view->headScript()->appendScript($previouslyLoaded, $type = 'text/javascript');
         }
     }
     //If here then populate the ProspectiveLandlord form.
     $prospectiveLandlordForm->forcePopulate($prospectiveLandlordForm->getValues());
     //Set this to whatever you want the progress bar to how in percents
     $this->view->fractionComplete = 25;
     $this->view->form = $prospectiveLandlordForm;
 }
 /**
  * Executes checks when the user is a reference subject completing an email-link-to-tenant.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @param string $userToken
  * @param string $refNo
  *
  * @return boolean
  */
 protected function _referenceSubjectLinkPreDespatch(Zend_Controller_Request_Abstract $request, $userToken, $refNo)
 {
     $session = new Zend_Session_Namespace('referencing_global');
     //Check the validity of the access.
     $params = Zend_Registry::get('params');
     $hashingString = $params->pll->emailLink->security->securityString;
     $leeWay = $params->pll->emailLink->security->securityTokenTimeLeewayUser;
     $securityManager = new Application_Core_Security($hashingString, true, $leeWay);
     $securityCheck = $securityManager->authenticate($userToken, array('refNo' => $refNo));
     if ($securityCheck['result']) {
         // && ($securityCheck['data']['refno'] == $refNo)) {
         //Security token from a tenant or guarantor e-mail link successfully passed, note in session
         if (!isset($session->security)) {
             $session->security = new StdClass();
         }
         $session->security = new StdClass();
         $session->security->origin = Model_Referencing_ReferenceUserTypes::REFERENCE_SUBJECT;
         $session->security->refNo = $refNo;
     } else {
         // Something went wrong, eg, hash didn't match or time was out of bounds
         if (!isset($session->security)) {
             $session->security = new StdClass();
         }
         $session->security->error = $securityCheck['error'];
         return false;
     }
     //Security has passed, next load up the reference.
     $referenceManager = new Manager_Referencing_Reference();
     $reference = $referenceManager->getMinimalReference($refNo);
     if (empty($reference)) {
         unset($session->userType);
         return false;
     } else {
         $session->userType = Model_Referencing_ReferenceUserTypes::REFERENCE_SUBJECT;
         $session->referenceId = $reference->internalId;
     }
     return true;
 }