Skip to content

Commit

Permalink
feat: operator self-registration revamp post consultant toggle (#375)
Browse files Browse the repository at this point in the history
* feat: operator self-registration revamp post consultant toggle

* fix: tidy up and fixed mapper usage
  • Loading branch information
jerotire authored Oct 10, 2024
1 parent 2ecbd09 commit cf3f117
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/selfserve/module/Olcs/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use Olcs\Controller\Lva\TransportManager as LvaTransportManagerControllers;
use Olcs\Controller\Lva\Variation as LvaVariationControllers;
use Olcs\Controller\MyDetailsController;
use Olcs\Controller\OperatorRegistrationController;
use Olcs\Controller\PromptController;
use Olcs\Controller\Search\SearchController;
use Olcs\Controller\SessionTimeoutController;
Expand Down Expand Up @@ -510,7 +511,7 @@
'options' => [
'route' => 'operator[/]',
'defaults' => [
'controller' => UserRegistrationController::class,
'controller' => \Olcs\Controller\Factory\UserRegistrationControllerToggleAwareFactory::class,
'action' => 'add'
]
]
Expand Down Expand Up @@ -1378,6 +1379,8 @@
UserForgotUsernameController::class => \Olcs\Controller\Factory\UserForgotUsernameControllerFactory::class,
UserRegistrationController::class => \Olcs\Controller\Factory\UserRegistrationControllerFactory::class,
ConsultantRegistrationController::class => \Olcs\Controller\Factory\ConsultantRegistrationControllerFactory::class,
OperatorRegistrationController::class => \Olcs\Controller\Factory\OperatorRegistrationControllerFactory::class,
\Olcs\Controller\Factory\UserRegistrationControllerToggleAwareFactory::class => \Olcs\Controller\Factory\UserRegistrationControllerToggleAwareFactory::class,

Olcs\Controller\Entity\ViewController::class => \Olcs\Controller\Factory\Entity\ViewControllerFactory::class,

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Olcs\Controller\Factory;

use Common\Service\Helper\FlashMessengerHelperService;
use Common\Service\Helper\FormHelperService;
use Common\Service\Helper\TranslationHelperService;
use Common\Service\Helper\UrlHelperService;
use Common\Service\Script\ScriptFactory;
use Dvsa\Olcs\Utils\Translation\NiTextTranslation;
use Laminas\ServiceManager\Factory\FactoryInterface;
use LmcRbacMvc\Service\AuthorizationService;
use Olcs\Controller\Mapper\CreateAccountMapper;
use Olcs\Controller\OperatorRegistrationController;
use Psr\Container\ContainerInterface;

class OperatorRegistrationControllerFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): OperatorRegistrationController
{
$niTextTranslationUtil = $container->get(NiTextTranslation::class);
$authService = $container->get(AuthorizationService::class);
$formHelper = $container->get(FormHelperService::class);
$scriptFactory = $container->get(ScriptFactory::class);
$translationHelper = $container->get(TranslationHelperService::class);
$urlHelper = $container->get(UrlHelperService::class);
$flashMessengerHelper = $container->get(FlashMessengerHelperService::class);
$formatDataMapper = $container->get(CreateAccountMapper::class);

return new OperatorRegistrationController(
$niTextTranslationUtil,
$authService,
$formHelper,
$scriptFactory,
$translationHelper,
$urlHelper,
$flashMessengerHelper,
$formatDataMapper
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Olcs\Controller\Factory;

use Common\Controller\Factory\FeatureToggle\BinaryFeatureToggleAwareControllerFactory;
use Common\FeatureToggle;
use Olcs\Controller\OperatorRegistrationController;
use Olcs\Controller\UserRegistrationController;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

class UserRegistrationControllerToggleAwareFactory extends BinaryFeatureToggleAwareControllerFactory
{
protected function getFeatureToggleNames(): array
{
return [
FeatureToggle::TRANSPORT_CONSULTANT_ROLE
];
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function createServiceWhenEnabled(ContainerInterface $container, $requestedName, array $options = null)
{
return $container->get('ControllerManager')->get(OperatorRegistrationController::class);
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function createServiceWhenDisabled(ContainerInterface $container, $requestedName, array $options = null)
{
return $container->get('ControllerManager')->get(UserRegistrationController::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Olcs\Controller;

use Common\Controller\Lva\AbstractController;
use Common\Service\Helper\FlashMessengerHelperService;
use Common\Service\Helper\FormHelperService;
use Common\Service\Helper\TranslationHelperService;
use Common\Service\Helper\UrlHelperService;
use Common\Service\Script\ScriptFactory;
use Dvsa\Olcs\Transfer\Command\User\RegisterUserSelfserve;
use Dvsa\Olcs\Utils\Translation\NiTextTranslation;
use Laminas\Http\Response;
use Laminas\View\Model\ViewModel;
use LmcRbacMvc\Service\AuthorizationService;
use Olcs\Controller\Mapper\CreateAccountMapper;
use Olcs\Form\Model\Form\RegisterOperatorAccount;

class OperatorRegistrationController extends AbstractController
{
public function __construct(
NiTextTranslation $niTextTranslationUtil,
AuthorizationService $authService,
protected FormHelperService $formHelper,
protected ScriptFactory $scriptFactory,
protected TranslationHelperService $translationHelper,
protected UrlHelperService $urlHelper,
protected FlashMessengerHelperService $flashMessengerHelper,
protected CreateAccountMapper $formatDataMapper
) {
parent::__construct($niTextTranslationUtil, $authService);
}

public function addAction(): Response|ViewModel
{
$form = $this->formHelper->createFormWithRequest(RegisterOperatorAccount::class, $this->getRequest());

if ($this->getRequest()->isPost()) {
$postData = $this->formatDataMapper->formatPostData($this->params()->fromPost());
$form->setData($postData);

if ($form->isValid()) {
$formattedOperatorData = $this->formatDataMapper->formatSaveData($form->getData());

$response = $this->handleCommand(
RegisterUserSelfserve::create($formattedOperatorData)
);

if ($response->isOk()) {
return $this->prepareView('olcs/user-registration/check-email', [
'emailAddress' => $formattedOperatorData['contactDetails']['emailAddress'],
'pageTitle' => 'user-registration.page.check-email.title'
]);
}

$this->flashMessengerHelper->addErrorMessage('There was an error registering your account. Please try again.');
}
}

return $this->prepareView('olcs/user-registration/index', [
'form' => $form,
'pageTitle' => 'operator-registration.page.title'
]);
}

private function prepareView(string $template, array $variables = []): ViewModel
{
$view = new ViewModel($variables);
$view->setTemplate($template);

if (isset($variables['pageTitle'])) {
$this->placeholder()->setPlaceholder('pageTitle', $variables['pageTitle']);
}

return $view;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

namespace Olcs\Form\Model\Fieldset;

use Laminas\Form\Annotation as Form;

/**
* @Form\Name("OperatorRegistration")
* @Form\Attributes({"method":"post"})
* @Form\Options({"prefer_form_input_filter": true, "label": ""})
*/
class OperatorRegistration
{
/**
* @Form\Options({
* "label":"user-name",
* "hint": "user-registration.field.username.hint"
* })
* @Form\Required(true)
* @Form\Attributes({"id":"username","placeholder":"","class":"medium", "required":false})
* @Form\Type("Text")
* @Form\Filter("Laminas\Filter\StringTrim")
* @Form\Filter("Laminas\Filter\StringToLower")
* @Form\Validator("Dvsa\Olcs\Transfer\Validators\UsernameCreate")
*/
public $loginId = null;

/**
* @Form\Attributes({"id":"forename","placeholder":"","class":"medium", "required":false})
* @Form\Options({"label":"first-name"})
* @Form\Type("Text")
* @Form\Filter("Laminas\Filter\StringTrim")
* @Form\Validator("Laminas\Validator\StringLength", options={"max":35})
*/
public $forename = null;

/**
* @Form\Attributes({"id":"familyName","placeholder":"","class":"medium", "required":false})
* @Form\Options({"label":"last-name"})
* @Form\Type("Text")
* @Form\Filter("Laminas\Filter\StringTrim")
* @Form\Validator("Laminas\Validator\StringLength", options={"max":35})
*/
public $familyName = null;

/**
* @Form\Attributes({"class":"long"})
* @Form\Options({"label":"email-address"})
* @Form\Type("Text")
* @Form\Filter("Laminas\Filter\StringTrim")
* @Form\Validator("Dvsa\Olcs\Transfer\Validators\EmailAddress")
* @Form\Validator("Common\Form\Elements\Validators\EmailConfirm", options={"token":"emailConfirm"})
*/
public $emailAddress = null;

/**
* @Form\Attributes({"class":"long"})
* @Form\Options({"label":"confirm-email-address"})
* @Form\Type("Text")
* @Form\Filter("Laminas\Filter\StringTrim")
*/
public $emailConfirm = null;

/**
* @Form\Required(true)
* @Form\Type("Text")
* @Form\Attributes({"class":"medium"})
* @Form\Options({"label":"user-registration.field.organisationName.label"})
* @Form\Filter("Laminas\Filter\StringTrim")
*/
public $organisationName = null;

/**
* @Form\Required(true)
* @Form\Type("DynamicRadio")
* @Form\Options({
* "fieldset-attributes": {"id": "businessType"},
* "label": "user-registration.field.businessType.label",
* "label_attributes": {"class": "form-control form-control--radio"},
* "disable_inarray_validator": false,
* "category": "org_type",
* "exclude": {"org_t_ir"}
* })
*/
public $businessType = null;

/**
* @Form\Attributes({"id":"translateToWelsh","placeholder":""})
* @Form\Options({
* "label": "translate-to-welsh",
* "label_attributes" : {
* "class":"form-control form-control--checkbox form-control--confirm"
* },
* "checked_value":"Y",
* "unchecked_value":"N"
* })
* @Form\Type("OlcsCheckbox")
*/

public $translateToWelsh = null;

/**
* @Form\Attributes({"id": "termsAgreed", "placeholder": ""})
* @Form\Options({
* "label": "user-registration.field.termsAgreed.label",
* "label_attributes" : {
* "class":"form-control form-control--checkbox form-control--confirm"
* },
* "checked_value":"Y",
* "unchecked_value":"N",
* "must_be_value": "Y"
* })
* @Form\Type("\Common\Form\Elements\InputFilters\SingleCheckbox")
*/
public $termsAgreed = null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Olcs\Form\Model\Fieldset;

use Laminas\Form\Annotation as Form;

/**
* @Form\Name("form-actions")
* @Form\Attributes({"class":"govuk-button-group"})
*/
class OperatorRegistrationButtonGroup
{
/**
* @Form\Attributes({
* "data-module": "govuk-button",
* "type": "submit",
* "class": "govuk-button"
* })
* @Form\Options({"label": "operator-registration.form-actions.submit.label"})
* @Form\Type("\Common\Form\Elements\InputFilters\ActionButton")
*/
public $submit;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Olcs\Form\Model\Form;

use Laminas\Form\Annotation as Form;

/**
* @Form\Name("RegisterOperatorAccount")
* @Form\Attributes({"method":"post"})
* @Form\Type("Common\Form\Form")
* @Form\Options({"prefer_form_input_filter": true})
*/
class RegisterOperatorAccount
{
/**
* @Form\Name("fields")
* @Form\Options({"label":""})
* @Form\ComposedObject("Olcs\Form\Model\Fieldset\OperatorRegistration")
*/
public $fields = null;

/**
* @Form\Name("form-actions")
* @Form\Attributes({"class":"govuk-button-group"}))
* @Form\ComposedObject("Olcs\Form\Model\Fieldset\OperatorRegistrationButtonGroup")
*/
public $formActions = null;
}

0 comments on commit cf3f117

Please sign in to comment.