/** * check customer registration and carry on the registration process if it is not completed * * Returns True if valid, false otherwise. * * @param string $email_address * * @return int */ public function checkRegister($refno, $email, $isChangeEmail) { (string) ($refno = preg_replace('/X/', '', $refno)); $customermgr = new Manager_Core_Customer(); $customer = $customermgr->getCustomerByEmailAddress($email); $params = Zend_Registry::get('params'); $mac = new Application_Core_Security($params->myhomelet->activation_mac_secret, false); $digest = $mac->generate(array('email' => $email)); $activationLink = 'refno=' . $refno . '&' . 'email=' . $email . '&' . 'mac=' . $digest; $customerMap = new Datasource_Core_CustomerMaps(); if ($customer) { if (!$customerMap->getMap(Model_Core_Customer::LEGACY_IDENTIFIER, $refno)) { $customermgr->linkLegacyToNew($refno, $customer->getIdentifier(Model_Core_Customer::IDENTIFIER)); } if (!$customer->getEmailValidated()) { $mail = new Application_Core_Mail(); $mail->setTo($email, null); $mail->setFrom('*****@*****.**', 'HomeLet'); $mail->setSubject('My HomeLet account validation'); $mail->applyTemplate('core/account-validation', array('activationLink' => $activationLink, 'homeletWebsite' => $params->homelet->domain, 'firstname' => $customer->getFirstName(), 'templateId' => 'HL2442 12-12', 'heading' => 'Validating your My HomeLet account', 'imageBaseUrl' => $params->weblead->mailer->imageBaseUrl), false, '/email-branding/homelet/portal-footer.phtml', '/email-branding/homelet/portal-header.phtml'); $mail->applyTextTemplate('core/account-validationtxt', array('activationLink' => $activationLink, 'homeletWebsite' => $params->homelet->domain, 'firstname' => $customer->getFirstName(), 'templateId' => 'HL2442 12-12', 'heading' => 'Validating your My HomeLet account'), false, '/email-branding/homelet/portal-footer-txt.phtml', '/email-branding/homelet/portal-header-txt.phtml'); // Send email $mail->send(); return 1; } else { return 0; } } else { if ($isChangeEmail) { $cMap = $customerMap->getMap(Model_Core_Customer::LEGACY_IDENTIFIER, $refno); if ($cMap) { $customer = $customermgr->getCustomer(Model_Core_Customer::IDENTIFIER, $cMap->getIdentifier()); $customer->setEmailAddress($email); $customermgr->updateCustomer($customer); $legacyids = $customerMap->getLegacyIDs($customer->getIdentifier()); foreach ($legacyids as $legacyid) { if ($legacyid != $refno) { $customer = $customermgr->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $legacyid); $customer->setEmailAddress($email); $customermgr->updateCustomer($customer); } } return 0; } } $oldCustomer = $customermgr->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $refno); $mail = new Application_Core_Mail(); $mail->setTo($email, null); $mail->setFrom('*****@*****.**', 'HomeLet'); $mail->setSubject("Don't forget to register your My HomeLet account"); $mail->applyTemplate('core/partial-registration', array('activationLink' => $activationLink, 'homeletWebsite' => $params->homelet->domain, 'firstname' => $oldCustomer->getFirstName(), 'templateId' => 'HL2469 12-12', 'heading' => 'Get even more with your My HomeLet account', 'imageBaseUrl' => $params->weblead->mailer->imageBaseUrl), false, '/email-branding/homelet/portal-footer.phtml', '/email-branding/homelet/portal-header.phtml'); $mail->applyTextTemplate('core/partial-registrationtxt', array('activationLink' => $activationLink, 'homeletWebsite' => $params->homelet->domain, 'firstname' => $oldCustomer->getFirstName(), 'templateId' => 'HL2469 12-12', 'heading' => 'Get even more with your My HomeLet account'), false, '/email-branding/homelet/portal-footer-txt.phtml', '/email-branding/homelet/portal-header-txt.phtml'); // Send email $mail->send(); return 2; } }
/** * Retrieves the specified customer record, encapsulates the details in a * Customer object and returns this. * * @param $identifier * @return param $identifier * Identifies the customer record in the customers table. * * @return \param The customer details encapsulated in a Customer object. */ public function getCustomer($identifier) { //Retrieve the customer record. $select = $this->select(); $select->where('id = ?', $identifier); $customerRow = $this->fetchRow($select); if ($customerRow) { //Populate the details into a Customer object. $customer = new Model_Core_Customer(); $customer->setIdentifier(Model_Core_Customer::IDENTIFIER, $identifier); $customerMaps = new Datasource_Core_CustomerMaps(); $customerMap = $customerMaps->getMap(Model_Core_Customer::IDENTIFIER, $identifier); if ($customerMap) { $customer->setIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER, $customerMap->getLegacyIdentifier()); } $customer->setTitle($customerRow->title); $customer->setFirstName($customerRow->first_name); $customer->setLastName($customerRow->last_name); $customer->setLandlordName($customerRow->landname); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, $customerRow->address1); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $customerRow->address2); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $customerRow->address3); $customer->setPostCode($customerRow->postcode); $customer->setCountry($customerRow->country); if ($customerRow->foreign_address == 0) { $customer->setIsForeignAddress(false); } else { $customer->setIsForeignAddress(true); } $customer->setTelephone(Model_Core_Customer::TELEPHONE1, $customerRow->telephone1); $customer->setTelephone(Model_Core_Customer::TELEPHONE2, $customerRow->telephone2); $customer->setEmailAddress($customerRow->email_address); $customer->setPassword($customerRow->password); $customer->setOccupation($customerRow->occupation); $customer->setEmailValidated($customerRow->email_validated == 1 ? true : false); $customer->setAccountLoadComplete($customerRow->account_load_complete == 1 ? true : false); $customerTypeName = array_search($customerRow->type_id, $this->_legacyTypeMap); if ($customerTypeName !== false) { $customer->typeID = $customerTypeName; } return $customer; } else { return null; } }
/** * Retrieves the specified customer record, encapsulates the details in a * Customer object and returns this. * * @param string $identifier * Identifies the customer record in the legacy customer table. * * @return Model_Core_Customer * The customer details encapsulated in a Customer object.#5 /home/benjamin.vickers/HomeLet-Framework/src/application/models/datasources/Core/LegacyCustomers.php(209): Zend_Db_Table_Abstract->fetchRow(Object(Zend_Db_Table_Select)) * * @throws Zend_Exception * Throws a Zend_Exception if the customer record cannot be found. */ public function getCustomer($identifier) { //Retrieve the customer record. $select = $this->select(); $select->where('refno = ?', $identifier); $customerRow = $this->fetchRow($select); if (empty($customerRow)) { throw new Zend_Exception('Customer not found.'); } //Populate the details into a Customer object. $customer = new Model_Core_Customer(); $customer->setIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER, $identifier); $customerMaps = new Datasource_Core_CustomerMaps(); $customerMap = $customerMaps->getMap(Model_Core_Customer::LEGACY_IDENTIFIER, $identifier); if ($customerMap) { $customer->setIdentifier(Model_Core_Customer::IDENTIFIER, $customerMap->getIdentifier()); } $customer->setTitle($customerRow->title); $customer->setFirstName($customerRow->firstname); $customer->setLastName($customerRow->lastname); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, $customerRow->personaladdress1); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $customerRow->personaladdress3); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $customerRow->personaladdress5); $customer->setPostCode($customerRow->personalpostcode); $customer->setCountry($customerRow->country); if ($customerRow->isForeignAddress == 'no') { $customer->setIsForeignAddress(false); } else { $customer->setIsForeignAddress(true); } $customer->setTelephone(Model_Core_Customer::TELEPHONE1, $customerRow->phone1); $customer->setTelephone(Model_Core_Customer::TELEPHONE2, $customerRow->phone2); $customer->setFax($customerRow->fax); $customer->setEmailAddress($customerRow->email); $customer->setPassword($customerRow->password); $customer->setOccupation($customerRow->occupation); $customer->setDateOfBirthAt($customerRow->date_of_birth_at); $customer->typeID = 2; // Default to a tenant return $customer; }
/** * Register action * * @return void */ public function partialRegistrationAction() { $this->_setBreadcrumbs(array('/' => 'Home', '/my-homelet' => 'My HomeLet', '/my-homelet/partial-registration' => 'Continue Registration')); $params = Zend_Registry::get('params'); $form = new Account_Form_Register(); // Populate the form with the security question options $securityQuestionModel = new Datasource_Core_SecurityQuestion(); $securityQuestionOptions = $securityQuestionModel->getOptions(); foreach ($securityQuestionOptions as $option) { $form->security_question->addMultiOption($option['id'], $option['question']); } $customerManager = new Manager_Core_Customer(); if (!$this->getRequest()->isPost()) { $refno = $_GET['refno']; $email = $_GET['email']; $mac = new Application_Core_Security($params->myhomelet->activation_mac_secret, false); $digest = $mac->generate(array('email' => $email)); if ($refno) { // Try by legacy customer refno $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $refno); } else { // Try by email $customer = $customerManager->getCustomerByEmailAddress($email); } $formData = array(); $formData['title'] = $customer->getTitle(); $formData['first_name'] = $customer->getFirstName(); $formData['last_name'] = $customer->getLastName(); $formData['email'] = $email; $formData['refno'] = $refno; #$form->title->setAttrib('readonly','readonly'); #$form->first_name->setAttrib('readonly','readonly'); #$form->last_name->setAttrib('readonly','readonly'); $form->email->setAttrib('readonly', 'readonly'); $form->populate($formData); if ($digest != $_GET['mac']) { // Render error page if invalid mac $this->render('activate-account-invalidmac'); return; } } else { if ($form->isValid($this->getRequest()->getPost())) { // Detect if the customer has already registered with this email address $customer = $customerManager->getCustomerByEmailAddress($form->email->getValue()); if ($customer) { // Customer already exists, flag form in error // Ideally this should go in the form as an overridden validation method, but this would // tightly couple the form to the customer manager anyway, which itself is bad. // Alternatively I could inject the found customer object into the form, but then this doesn't change // much to using the code here anyway. $form->email->addError('This email is already in use. Have you signed up before?')->markAsError(); } else { // Create customer. Because this is the generic registration page, we use a generic customer type $customer = $customerManager->createCustomerFromLegacy($form->email->getValue(), $form->refno->getValue()); $custID = $customer->getIdentifier(Model_Core_Customer::IDENTIFIER); $leg = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $form->refno->getValue()); // Update customer with password and security data $customerManager->updateCustomerByLegacy($leg, $custID); $customer = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $custID); $customer->setSecurityQuestion($form->security_question->getValue()); $customer->setSecurityAnswer($form->security_answer->getValue()); $customer->setPassword($form->password->getValue()); $customer->setEmailValidated(true); $customerManager->updateCustomer($customer); // Create welcome email $mail = new Application_Core_Mail(); $mail->setTo($_GET['email'], null); $mail->setFrom('*****@*****.**', 'HomeLet'); $mail->setSubject('Registration for My HomeLet'); // Apply template $mail->applyTemplate('core/account-welcome', array('homeletWebsite' => $params->homelet->domain, 'templateId' => 'HL2443 12-12', 'firstname' => $customer->getFirstName(), 'heading' => 'Your registration for My HomeLet is complete!', 'imageBaseUrl' => $params->weblead->mailer->imageBaseUrl), false, '/email-branding/homelet/portal-footer.phtml', '/email-branding/homelet/portal-header.phtml'); $mail->applyTextTemplate('core/account-welcometxt', array('homeletWebsite' => $params->homelet->domain, 'templateId' => 'HL2443 12-12', 'firstname' => $customer->getFirstName(), 'heading' => 'Your registration for My HomeLet is complete!'), false, '/email-branding/homelet/portal-footer-txt.phtml', '/email-branding/homelet/portal-header-txt.phtml'); // Send email $mail->send(); // Find all customers in mysql4 insurance that have the same email address $legacyCustomers = $customerManager->getAllLegacyCustomersByEmailAddress($_GET['email']); $customerIdentifier = $customer->getIdentifier(Model_Core_Customer::IDENTIFIER); foreach ($legacyCustomers as $legacyCustomer) { // For each customer found, insert a record into the mysql5 customer_legacy_customer_map table $legacyIdentifier = $legacyCustomer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER); $customerMap = new Datasource_Core_CustomerMaps(); if (!$customerMap->getMap(Model_Core_Customer::LEGACY_IDENTIFIER, $legacyIdentifier)) { $customerManager->linkLegacyToNew($legacyIdentifier, $customerIdentifier); } } $this->_helper->redirector->gotoUrl('/my-homelet/login?message=registration-complete'); } } } $this->view->form = $form; }
/** * Retrieve the document * * @param string $policyNumber Policy number * @param string $documentId Unique document request hash * @return string null or PDF contents */ private function _fetchDocument($policyNumber, $documentId) { // Get the customer session $customerSession = $this->auth->getStorage()->read(); // Get the request policy if ($policyNumber[0] == 'Q') { // Quotes $legacyPolicies = new Datasource_Insurance_LegacyQuotes(); } else { // Policies $legacyPolicies = new Datasource_Insurance_LegacyPolicies(); } $policy = $legacyPolicies->getByPolicyNumber($policyNumber); if (!$policy) { return null; } // Check the policy customer refno is linked to the customer id through mapping $customerMaps = new Datasource_Core_CustomerMaps(); $customerMap = $customerMaps->getMap(Model_Core_Customer::LEGACY_IDENTIFIER, $policy->refNo); // Confirm the policy number belongs to the logged in customer if ($customerMap == false || $customerMap->getIdentifier() != $customerSession->id) { // Customer map not found or customer is not mapped to refno, render error message return null; } // Get all document details $documentHistory = new Datasource_Insurance_DocumentHistory(); $document = $documentHistory->getDocument($documentId, $policyNumber); if (!$document) { return null; } // Retrieve document from store $documentFulfillmentService = new Service_Insurance_Document(); return $documentFulfillmentService->retrieveDocumentFromStore($documentId, $document->template_name, Service_Insurance_Document::DOCUMENT_AND_ATTACHMENTS); }