IBX-11959: Exposed configured password requirements to the frontend - #132
IBX-11959: Exposed configured password requirements to the frontend#132tbialcz wants to merge 1 commit into
Conversation
|
|
|
||
| $minLength = (int)($constraints['minLength'] ?? 0); | ||
| if ($minLength > 0) { | ||
| $requirements[] = new PasswordRequirement(PasswordRequirement::MIN_LENGTH, ['%length%' => $minLength]); |
There was a problem hiding this comment.
Aren't those configurable and should be dynamically incorporated? How about dynamic labels generation for custom ones?
There was a problem hiding this comment.
it seems they are dynamically added based on actual constraints value?
There was a problem hiding this comment.
the values come from the config, and only the list of rules is fixed, just like in the core schema. After the Slack discussion, I simplified it to a single rules table, and the labels and translations are generated from that table.
| * and {@see \Ibexa\Core\Repository\User\PasswordValidator}. | ||
| */ | ||
| private const array REQUIREMENT_CODE_MAP = [ | ||
| 'User password must be at least %length% characters long' => PasswordRequirement::MIN_LENGTH, |
There was a problem hiding this comment.
Should this be even static?
There was a problem hiding this comment.
it is a const . The map never changes at runtime, so const is the right i think,static would allow mutation for no reason.



Related PRs:
Description:
Backend part of showing password requirements on the "Set new password" screen:
ibexa_password_requirements()Twig function returning the list of rules enabled in the user content type'sPasswordValueValidatorconfig (PasswordRequirementsResolver),code= requirement identifier, so the frontend can mark which rules were not met after submit,PasswordResetControllerpassescontent_typeto the view (the user on the reset screen is not logged in).Validation logic itself is unchanged.
For frontend:
After submit, failed rules are in
form.new_password.first.vars.errors— matcherror.cause.codeagainstrequirement.identifier.For QA:
Full scenario (requirements list on the page) is testable once the storefront PR consuming this API is up. On this PR alone:
abc) — one error per unmet rule is displayed, password is not changed.