public function forcePopulate($formData)
 {
     //Populate the form elements with data retrieved from the datasource, unless
     //the user has provided new datas.
     //        $auth = Zend_Auth::getInstance();
     //        $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
     //        $session = $auth->getStorage()->read();
     $session = new Zend_Session_Namespace('referencing_global');
     $customerManager = new Manager_Referencing_Customer();
     $customer = $customerManager->getCustomer($session->customerId);
     if (empty($formData['personal_title'])) {
         $formData['personal_title'] = $customer->getTitle();
     }
     if (empty($formData['first_name'])) {
         $formData['first_name'] = $customer->getFirstName();
     }
     if (empty($formData['last_name'])) {
         $formData['last_name'] = $customer->getLastName();
     }
     if (empty($formData['property_postcode'])) {
         $formData['property_postcode'] = $customer->getPostCode();
     }
     if (empty($formData['telephone_day'])) {
         $formData['telephone_day'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE1);
     }
     if (empty($formData['fax_number'])) {
         $formData['fax_number'] = $customer->getFax();
     }
     if (empty($formData['telephone_evening'])) {
         $formData['telephone_evening'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE2);
     }
     if (empty($formData['email'])) {
         $formData['email'] = $customer->getEmailAddress();
     }
     $postcode = new Manager_Core_Postcode();
     $addresses = $postcode->getPropertiesByPostcode($formData['property_postcode']);
     $filterString = $customer->getAddressLine(1);
     $addressList = array();
     $addressID = 0;
     foreach ($addresses as $address) {
         $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
         $cleanAddress = str_replace(",", "", $address['singleLineWithoutPostcode']);
         if (stripos($cleanAddress, $filterString) === 0) {
             $addressID = $address['id'];
         }
     }
     // Add some validation
     $property_address = $this->getElement('property_address');
     $property_address->setMultiOptions($addressList);
     $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
     $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Insured address does not match with postcode'));
     $property_address->addValidator($validator, true);
     // Set the address to selected
     $property_address->setValue($addressID);
     //Allow Zend to complete the population process.
     $this->populate($formData);
     $this->property_address->setValue($addressID);
 }
 /**
  * Executes checks when the user is a PLL finalizing an email-link-to-tenant.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @param string $customerToken
  * @param string $refNo
  *
  * @return boolean
  */
 protected function _privateLandlordLinkPreDespatch(Zend_Controller_Request_Abstract $request, $customerToken, $refNo)
 {
     $session = new Zend_Session_Namespace('referencing_global');
     $referenceManager = new Manager_Referencing_Reference();
     $reference = $referenceManager->getReference($refNo);
     //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($customerToken, array('refNo', 'customerId'));
     if ($securityCheck['result']) {
         //Ensure the customer identifier extracted from the $customerToken matches the identifier
         //stored in the reference.
         $customerId = $securityCheck['data']['customerId'];
         if ($customerId != $reference->customer->customerId) {
             $session->security->error = 'Customer identifier does not match';
             return false;
         }
     } else {
         // Something went wrong, eg, hash didn't match or time was out of bounds
         $session->security->error = $securityCheck['error'];
         return false;
     }
     //Log the customer in.
     $customerManager = new Manager_Referencing_Customer();
     $customer = $customerManager->getCustomer($customerId);
     $loginManager = new Manager_Referencing_Login();
     $loginManager->logUserIn($customer->getEmailAddress(), $customer->getPassword());
     //Set the relevant session variables so that the PLL can proceed the reference.
     $session->referenceId = $reference->internalId;
     $session->productName = $reference->productSelection->product->key;
     $session->userType = Model_Referencing_ReferenceUserTypes::PRIVATE_LANDLORD;
     $session->customerToken = $customerToken;
     $session->refNo = $refNo;
     return true;
 }