Create User
Create user accounts with configurable validation, password policy and application collection mapping.
Purpose and architecture
Create User is a specialized, reusable user creation form built on
CoreUi\Form\FieldBuilder.
It handles the user-specific creation workflow rather than attempting to create arbitrary documents.
An
application-specific user collection is required.
The default form collects username, email address and password. The AJAX create action validates required values, username uniqueness, email requirements and the configured password policy, then creates a new user document with a password hash.
Integrating Create User
Extend CoreApp\Create\CreateUser and override getUserCollection().
Optionally
override getPassRegex() to use the application’s password policy.
use Core\Registry;
use Core\Collection\BaseUserCollection;
use CoreApp\Create\CreateUser as CoreAppCreateUser;
class CreateUser extends CoreAppCreateUser
{
protected function getUserCollection(): BaseUserCollection|null
{
return Registry::get(AdminUserCollection::class);
}
protected function getPassRegex(): string
{
return $this->_config?->getAdminPassRegex() ?? '';
}
}
This example is based on the appnetos-api-dev admin implementation; the config property
and
collection are application-specific.
Extension points
| Method | Purpose |
|---|---|
getUserCollection(): BaseUserCollection|null |
Map the user collection; the shared default is null. |
getPassRegex(): string |
Define the password validation expression. |
getFormData(array|null $formData = null): array |
Configure the FieldBuilder form and error display. |
createGetFormData(): array |
Read and normalize submitted username, email and password. |
createValidateFormData(array &$formData): void |
Run the username, email and password validation chain. |
createValidateUsername(array &$formData): void |
Validate username requirements and uniqueness. |
createValidateEmail(array &$formData): void |
Validate the email address. |
createValidatePassword(array &$formData): void |
Enforce the password policy. |
createUserDocument(array $formData): BaseDocument |
Construct the user document, including the password hash. |
getBaseTemplate(), getFormTemplate(), getSuccessTemplate() |
Customize Twig rendering. |
Password handling
The shared default password policy requires at least eight characters with lowercase and uppercase
letters, a digit and a special character. The Core App uses password_hash(...,
PASSWORD_DEFAULT) when building the user document. Applications may override the policy
through getPassRegex().
The appnetos-api-dev admin integration retrieves its policy from the admin
configuration.
Keep validation and application security requirements aligned.
AJAX, templates and translations
The initial form is rendered through FieldBuilder. The #[Ajax]
create() method handles validation errors without a full-page reload and persists the
created user when valid. The provided templates are versioned for Bootstrap (including Bootstrap
5.3)
and can be replaced; translation resources and Core App JavaScript are included.
The generic FieldBuilder API is documented separately under Core UI.