-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: operator self-registration revamp post consultant toggle (#375)
* feat: operator self-registration revamp post consultant toggle * fix: tidy up and fixed mapper usage
- Loading branch information
Showing
7 changed files
with
329 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/selfserve/module/Olcs/src/Controller/Factory/OperatorRegistrationControllerFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...serve/module/Olcs/src/Controller/Factory/UserRegistrationControllerToggleAwareFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
app/selfserve/module/Olcs/src/Controller/OperatorRegistrationController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
app/selfserve/module/Olcs/src/Form/Model/Fieldset/OperatorRegistration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
24 changes: 24 additions & 0 deletions
24
app/selfserve/module/Olcs/src/Form/Model/Fieldset/OperatorRegistrationButtonGroup.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
28 changes: 28 additions & 0 deletions
28
app/selfserve/module/Olcs/src/Form/Model/Form/RegisterOperatorAccount.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |