public function init() { // Set request method $this->setMethod('post'); // Email entry $this->addElement('span', 'email', array('label' => 'Email address', 'required' => false, 'filters' => array('StringTrim'), 'class' => 'formvalue', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter your email address')))))); // Modify email error messages & add validator $emailValidator = new Zend_Validate_EmailAddress(); $emailValidator->setMessages(array(Zend_Validate_EmailAddress::INVALID_HOSTNAME => "Domain name invalid in email address", Zend_Validate_EmailAddress::INVALID_FORMAT => "Invalid email address")); $this->getElement('email')->addValidator($emailValidator); //The password element. $passwordElement = new Zend_Form_Element_Password('password'); $passwordElement->setRequired(true); $passwordElement->setLabel('Create your password'); $passwordElement->setOptions(array('data-noAjaxValidate' => '1')); $passwordElement->addValidator(new Zend_Validate_PasswordStrength()); $validator = new Zend_Validate_Identical(); $validator->setToken('confirm_password'); $validator->setMessage('Passwords are not the same', Zend_Validate_Identical::NOT_SAME); $passwordElement->addValidator($validator); $this->addElement($passwordElement); //The confirm password element. $confirmPasswordElement = new Zend_Form_Element_Password('confirm_password'); $confirmPasswordElement->setRequired(true); $confirmPasswordElement->setLabel('Re-enter password'); $confirmPasswordElement->setOptions(array('data-noAjaxValidate' => '1')); $validator = new Zend_Validate_NotEmpty(); $validator->setMessage('Please confirm your password'); $confirmPasswordElement->addValidator($validator); $this->addElement($confirmPasswordElement); // Security question & answer $securityQuestionModel = new Datasource_Core_SecurityQuestion(); $securityQuestionOptions = array(0 => '- Please Select -'); foreach ($securityQuestionModel->getOptions() as $option) { $securityQuestionOptions[$option['id']] = $option['question']; } $this->addElement('select', 'security_question', array('label' => 'Security Question', 'required' => false, 'multiOptions' => $securityQuestionOptions, 'decorators' => array(array('ViewHelper', array('escape' => false)), array('Label', array('escape' => false))))); /* Value no longer mandatory, Redmine #11873 $questionElement = $this->getElement('security_question'); $validator = new Zend_Validate_GreaterThan(array('min'=> 0)); $validator->setMessage('You must select a security question'); $questionElement->addValidator($validator); */ $this->addElement('text', 'security_answer', array('label' => 'Answer', 'required' => false, 'filters' => array('StringTrim'))); // Set custom subform decorator - this is the default and gets overridden by view scripts in the tenants' and landlords' Q&Bs $this->setDecorators(array(array('ViewScript', array('viewScript' => 'subforms/register.phtml')))); // Set element decorators $this->setElementDecorators(array(array('ViewHelper', array('escape' => false)), array('Label', array('escape' => false)))); // Grab view and add the client-side password validation JavaScript into the page head $view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view'); $view->headScript()->appendFile('/assets/common/js/passwordValidation.js', 'text/javascript'); }
/** * Edit account action * * @return void */ public function editAccountAction() { $this->_setMetaTitle('My HomeLet | Edit Account'); $this->_setBreadcrumbs(array('/' => 'Home', '/my-homelet' => 'My HomeLet', '/my-homelet/edit-account' => 'My Account Details')); $form = new Account_Form_EditAccount(); // 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']); } // Get the customer session $customerSession = $this->auth->getStorage()->read(); // Retrieve the customer record $customermgr = new Manager_Core_Customer(); $customer = $customermgr->getCustomer(Model_Core_Customer::IDENTIFIER, $customerSession->id); if ($this->getRequest()->isPost()) { // Set the current password for validation $form->setCurrentPassword($customer->getPassword()); // Validate the form if ($form->isValid($this->getRequest()->getPost())) { // Update the customer if ($form->password->getValue() != '') { // Set new password $customer->setPassword($form->password->getValue()); } $customer->setSecurityQuestion($form->security_question->getValue()); $customer->setSecurityAnswer($form->security_answer->getValue()); $this->view->accountUpdated = true; $customermgr->updateCustomer($customer); } } else { // Populate the form with customers data $form->security_question->setValue($customer->getSecurityQuestion()); $form->security_answer->setValue($customer->getSecurityAnswer()); } $form->email->setValue($customer->getEmailAddress()); $form->title->setValue($customer->getTitle()); $form->first_name->setValue($customer->getFirstName()); $form->last_name->setValue($customer->getLastName()); $this->view->form = $form; }
/** * 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; }
/** * Allows the private landlord (PLL) to register with HomeLet. */ public function registerAction() { $request = $this->getRequest(); $registerForm = new LandlordsReferencing_Form_Register(); // Populate the form with the security question options $securityQuestionModel = new Datasource_Core_SecurityQuestion(); $securityQuestionOptions = $securityQuestionModel->getOptions(); foreach ($securityQuestionOptions as $option) { $registerForm->security_question->addMultiOption($option['id'], $option['question']); } // Tell page to use AJAX validation as we go $this->view->headScript()->appendScript('var ajaxValidate = true; var ajaxValidatePage = "register";'); // Extract clean values, save them and validate if ($request->isPost()) { if ($registerForm->isValid($request->getPost())) { $registerForm->saveData(); $this->_despatchToNext(); return; } else { $previouslyLoaded = "var previouslyLoaded = true;\n"; $this->view->headScript()->appendScript($previouslyLoaded, $type = 'text/javascript'); } } //Set this to whatever you want the progress bar to how in percents $this->view->fractionComplete = 0; $this->view->form = $registerForm; }