/** * @Route() * @Method({"GET", "POST"}) * @Template() * * @param Request $request * @return array|RedirectResponse * * @throws RequestException */ public function indexAction(Request $request) { $form = $this->createForm($this->directLandlordType, new DirectLandlord(), array('action' => $this->generateUrl('barbon_hostedapi_landlord_authentication_entrypoint_index')))->add('register', 'submit', array('label' => 'Register', 'attr' => array('class' => 'btn-primary pull-right'))); $masterRequest = $this->container->get('request_stack')->getMasterRequest(); // Only process if this is the form that's been POSTed if ($masterRequest->request->has($form->getName())) { $form->handleRequest($masterRequest); if ($form->isValid()) { $directLandlord = $form->getData(); $registrationSuccessful = true; // Attempt to register direct landlord, handling any errors from IRIS try { // Switch to vendor credentials before creating the Landlord // Checking for its existence in the session has already been handled in the EntryPointController $vendorCredentials = $request->getSession()->get('auth-data'); $this->irisEntityManager->getClient()->setSystemCredentials($vendorCredentials->get('systemKey'), $vendorCredentials->get('systemSecret')); // Create the Landlord $this->irisEntityManager->persist($directLandlord); } catch (RequestException $e) { $registrationSuccessful = false; switch ($e->getCode()) { // Catch missing/invalid details case 400: case 422: $form->addError(new FormError('One or more required details are bad or missing, please contact us if this problem persists.')); break; // Catch duplicate registrations // Catch duplicate registrations case 409: $form->addError(new FormError('A landlord with this e-mail address already exists, please try logging in or resetting your password instead.')); $form->get('email')->addError(new FormError('E-mail address already exists')); break; // Catch and re-throw server errors and any other kind // Catch and re-throw server errors and any other kind case 500: default: throw $e; } } if ($registrationSuccessful) { // Commence auto login $username = $form->getData()->getEmail(); $password = $form->getData()->getPassword(); $this->authenticateUser($username, $password); // Return rendered registration successful message return $this->render('BarbonHostedApiLandlordAuthenticationBundle:Register:success.html.twig'); } } } // Send custom registration text to the view $options = $this->systemBrandService->getSystemBrandOptions(); $customHeaderText = null; if (array_key_exists(DisplayPreferences::CUSTOM_TEXT_REGISTRATION_HEADER, $options->getDisplayPreferences()->getCustomText())) { $customHeaderText = $options->getDisplayPreferences()->getCustomText()[DisplayPreferences::CUSTOM_TEXT_REGISTRATION_HEADER]; } $form = $form->createView(); return compact('form', 'customHeaderText'); }
/** * Success page after reference purchase * * @Route() * @Method({"GET", "POST"}) * @Template() * * @param Request $request * @return array * @throws CaseNotSubmittedException */ public function indexAction(Request $request) { // Get the submitted case /** @var ReferencingCase $case */ $case = unserialize($request->getSession()->get('submitted-case')); if (false === $case) { // Failed to retrieve case from session throw new CaseNotSubmittedException('submitted-case could not be retrieved from the session.'); } // Flatten application/guarantor hierarchy in depth first search order // todo: only needs doing for applications who are completing now $applications = array(); foreach ($case->getApplications() as $application) { $applications[] = $application; if (null !== $application->getGuarantors()) { foreach ($application->getGuarantors() as $guarantor) { $applications[] = $guarantor; } } } $tenancyAgreement = new TenancyAgreement(); $tenancyAgreement->setApplications($applications); // Create form, with flattened data $form = $this->createForm(new TenancyAgreementType(), $tenancyAgreement); $form->handleRequest($request); if ($form->isValid()) { // Persist each application/guarantor model with the updated marketing preferences /** @var AbstractReferencingApplication $application */ foreach ($applications as $application) { $this->irisEntityManager->persist($application, array('caseId' => $case->getCaseId(), 'applicationId' => $application->getApplicationId())); } // Submit the entire case $case->submit($this->irisEntityManager->getClient()); // Flush the case/applications from the session for the next reference $request->getSession()->remove('submitted-case'); return $this->redirect($this->generateUrl('barbon_hostedapi_agent_reference_cases_view_index', array('caseId' => $case->getCaseId()))); } return array('form' => $form->createView()); }
/** * Fetch a system brand object from cache or via REST, using the vendor key and secret * * @param mixed $model * @param string $cacheKeyRoot * @return mixed * @throws \Exception */ private function getCachableSystemBrandObject($model, $cacheKeyRoot) { $vendorCredentials = $this->getVendorCredentials(); $cacheKey = $cacheKeyRoot . '-' . $vendorCredentials['vendorKey']; // Check if cache contains system brand object details for this key if ($systemBrandObjectSerialized = $this->cache->fetch($cacheKey)) { // Cache hit $systemBrandObject = unserialize($systemBrandObjectSerialized); } else { // Cache miss or stale, do the work of fetching new details // Temporarily "resume" the vendor's key and secret for the brand details lookup $irisClient = $this->irisEntityManager->getClient(); // Take note of the original auth details to set back to $originalAuth = $irisClient->getSubscriber(); // Switch to using the vendor credentials and look up the system brand object $client = $irisClient->resume(array('consumerKey' => $vendorCredentials['vendorKey'], 'consumerSecret' => $vendorCredentials['vendorSecret'])); $systemBrandObject = $this->irisEntityManager->find($model); // Now resume the original auth $irisClient->setSubscriber($originalAuth); // Cache the results $this->cache->save($cacheKey, serialize($systemBrandObject)); } return $systemBrandObject; }
/** * {@inheritdoc} */ public function refreshUser(UserInterface $user) { // set the consumer key and secret into the OAuth client $this->irisEntityManager->getClient()->resume(array('consumerKey' => $user->getConsumerKey(), 'consumerSecret' => $user->getConsumerSecret())); return $user; }