1
0
mirror of https://github.com/flarum/core.git synced 2025-10-14 08:24:28 +02:00

Move password confirmation validation to frontends

Since this is not strictly speaking a domain invariant, but rather
specific to the user interface where passwords are not displayed, and
should therefore be entered twice to prevent mistakes going unnoticed,
this stuff should be checked in the frontend, not in the install steps.

Next step: Ensure that all domain-specific validation is done in the
installer's domain layer. This will ensure these validations cannot be
forgotten, and keep the frontends DRY.
This commit is contained in:
Franz Liedke
2019-01-26 00:51:28 +01:00
parent 0879829dc4
commit 0a59b7164e
6 changed files with 90 additions and 44 deletions

View File

@@ -64,13 +64,33 @@ class UserDataProvider implements DataProviderInterface
public function getAdminUser()
{
return [
'username' => $this->ask('Admin username:'),
'password' => $this->secret('Admin password:'),
'password_confirmation' => $this->secret('Admin password (confirmation):'),
'email' => $this->ask('Admin email address:'),
'username' => $this->ask('Admin username:'),
'password' => $this->askForAdminPassword(),
'email' => $this->ask('Admin email address:'),
];
}
private function askForAdminPassword()
{
while (true) {
$password = $this->secret('Admin password:');
if (strlen($password) < 8) {
$this->validationError('Password must be at least 8 characters.');
continue;
}
$confirmation = $this->secret('Admin password (confirmation):');
if ($password !== $confirmation) {
$this->validationError('The password did not match its confirmation.');
continue;
}
return $password;
}
}
public function getSettings()
{
$title = $this->ask('Forum title:');
@@ -99,6 +119,12 @@ class UserDataProvider implements DataProviderInterface
return $this->questionHelper->ask($this->input, $this->output, $question);
}
protected function validationError($message)
{
$this->output->writeln("<error>$message</error>");
$this->output->writeln('Please try again.');
}
public function isDebugMode(): bool
{
return false;