Register form tweaked

This commit is contained in:
2023-06-01 15:52:37 +01:00
parent ff871bdbbf
commit 9b229fc6ee
10 changed files with 328 additions and 0 deletions

View File

@@ -108,4 +108,80 @@ class AccountController extends UFAccountController
],
]);
}
/**
* Render the account registration page for UserFrosting.
*
* This allows new (non-authenticated) users to create a new account for themselves on your website (if enabled).
* By definition, this is a "public page" (does not require authentication).
*
* AuthGuard: false
* checkEnvironment
* Route: /account/register
* Route Name: register
* Request type: GET
*
* @param Request $request
* @param Response $response
* @param array $args
*
* @throws NotFoundException If site registration is disabled
*/
public function pageRegister(Request $request, Response $response, $args)
{
/** @var \UserFrosting\Support\Repository\Repository $config */
$config = $this->ci->config;
if (!$config['site.registration.enabled']) {
throw new NotFoundException();
}
/** @var \UserFrosting\Sprinkle\Account\Authenticate\Authenticator $authenticator */
$authenticator = $this->ci->authenticator;
// Redirect if user is already logged in
if ($authenticator->check()) {
$redirect = $this->ci->get('redirect.onAlreadyLoggedIn');
return $redirect($request, $response, $args);
}
// Load validation rules
$schema = new RequestSchema('schema://requests/register.yaml');
$schema->set('password.validators.length.min', $config['site.password.length.min']);
$schema->set('password.validators.length.max', $config['site.password.length.max']);
$schema->set('passwordc.validators.length.min', $config['site.password.length.min']);
$schema->set('passwordc.validators.length.max', $config['site.password.length.max']);
$validatorRegister = new JqueryValidationAdapter($schema, $this->ci->translator);
// Get locale information
$currentLocale = $this->ci->translator->getLocale()->getIdentifier();
// Get a list of all locales
$locales = $this->ci->locale->getAvailableOptions();
// Hide the locale field if there is only 1 locale available
$fields = [
'hidden' => [],
'disabled' => [],
];
if (count($locales) <= 1) {
$fields['hidden'][] = 'locale';
}
return $this->ci->view->render($response, 'pages/register.html.twig', [
'page' => [
'validators' => [
'register' => $validatorRegister->rules('json', false),
],
],
'form' => [
'fields' => $fields,
],
'locales' => [
'available' => $locales,
'current' => $currentLocale,
],
]);
}
}