From 6c805ec9baf4aa875cfcbffe5fa5384caff7b7e7 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Thu, 13 Sep 2018 14:37:06 +0200 Subject: [PATCH 1/3] Add --admin-email to cli installer Signed-off-by: Daniel Kesselberg --- core/Command/Maintenance/Install.php | 3 +++ lib/private/Setup.php | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/core/Command/Maintenance/Install.php b/core/Command/Maintenance/Install.php index 262def99c5f6d..3e6ee2a463f3f 100644 --- a/core/Command/Maintenance/Install.php +++ b/core/Command/Maintenance/Install.php @@ -67,6 +67,7 @@ protected function configure() { ->addOption('database-table-space', null, InputOption::VALUE_OPTIONAL, 'Table space of the database (oci only)', null) ->addOption('admin-user', null, InputOption::VALUE_REQUIRED, 'User name of the admin account', 'admin') ->addOption('admin-pass', null, InputOption::VALUE_REQUIRED, 'Password of the admin account') + ->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'E-Mail of the admin account') ->addOption('data-dir', null, InputOption::VALUE_REQUIRED, 'Path to data directory', \OC::$SERVERROOT."/data"); } @@ -141,6 +142,7 @@ protected function validateInput(InputInterface $input, OutputInterface $output, } $adminLogin = $input->getOption('admin-user'); $adminPassword = $input->getOption('admin-pass'); + $adminEmail = $input->getOption('admin-email'); $dataDir = $input->getOption('data-dir'); if ($db !== 'sqlite') { @@ -179,6 +181,7 @@ protected function validateInput(InputInterface $input, OutputInterface $output, 'dbtableprefix' => $dbTablePrefix, 'adminlogin' => $adminLogin, 'adminpass' => $adminPassword, + 'adminemail' => $adminEmail, 'directory' => $dataDir ]; if ($db === 'oci') { diff --git a/lib/private/Setup.php b/lib/private/Setup.php index d5ccde6bba399..1d7ea5e0e53c0 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -52,6 +52,7 @@ use OCP\Defaults; use OCP\IL10N; use OCP\ILogger; +use OCP\IUser; use OCP\Security\ISecureRandom; class Setup { @@ -368,6 +369,14 @@ public function install($options) { if (!$user) { $error[] = "User <$username> could not be created."; } + if ($user instanceof IUser && !empty($options['adminemail'])) { + $adminEmail = htmlspecialchars_decode($options['adminemail']); + if (filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) { + $user->setEMailAddress($adminEmail); + } else { + $error[] = "Invalid e-mail-address <$adminEmail> for <$username>."; + } + } } catch(Exception $exception) { $error[] = $exception->getMessage(); } From 13877c2d2068189cff180ea8f4f62826afda6414 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Mon, 24 Sep 2018 21:49:43 +0200 Subject: [PATCH 2/3] Use setUserValue instead setEMailAddress because latter omits an changeUser events. Signed-off-by: Daniel Kesselberg --- lib/private/Setup.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/private/Setup.php b/lib/private/Setup.php index 1d7ea5e0e53c0..9346edd836358 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -369,14 +369,6 @@ public function install($options) { if (!$user) { $error[] = "User <$username> could not be created."; } - if ($user instanceof IUser && !empty($options['adminemail'])) { - $adminEmail = htmlspecialchars_decode($options['adminemail']); - if (filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) { - $user->setEMailAddress($adminEmail); - } else { - $error[] = "Invalid e-mail-address <$adminEmail> for <$username>."; - } - } } catch(Exception $exception) { $error[] = $exception->getMessage(); } @@ -421,6 +413,16 @@ public function install($options) { $userSession->setTokenProvider($defaultTokenProvider); $userSession->login($username, $password); $userSession->createSessionToken($request, $userSession->getUser()->getUID(), $username, $password); + + // Set email for admin + if (!empty($options['adminemail'])) { + $adminEmail = htmlspecialchars_decode($options['adminemail']); + if (filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) { + $config->setUserValue($user->getUID(), 'settings', 'email', $adminEmail); + } else { + $error[] = "Invalid e-mail-address <$adminEmail> for <$username>."; + } + } } return $error; From a4eb3ee508804bc1c7c489ea252a9841139e38fb Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Tue, 25 Sep 2018 21:53:04 +0200 Subject: [PATCH 3/3] Validate email in occ command Signed-off-by: Daniel Kesselberg --- core/Command/Maintenance/Install.php | 4 ++++ lib/private/Setup.php | 7 +------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/core/Command/Maintenance/Install.php b/core/Command/Maintenance/Install.php index 3e6ee2a463f3f..39692e036ba07 100644 --- a/core/Command/Maintenance/Install.php +++ b/core/Command/Maintenance/Install.php @@ -171,6 +171,10 @@ protected function validateInput(InputInterface $input, OutputInterface $output, $adminPassword = $helper->ask($input, $output, $question); } + if ($adminEmail !== null && !filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) { + throw new InvalidArgumentException('Invalid e-mail-address <' . $adminEmail . '> for <' . $adminLogin . '>.'); + } + $options = [ 'dbtype' => $db, 'dbuser' => $dbUser, diff --git a/lib/private/Setup.php b/lib/private/Setup.php index 9346edd836358..e9719705fcddd 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -416,12 +416,7 @@ public function install($options) { // Set email for admin if (!empty($options['adminemail'])) { - $adminEmail = htmlspecialchars_decode($options['adminemail']); - if (filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) { - $config->setUserValue($user->getUID(), 'settings', 'email', $adminEmail); - } else { - $error[] = "Invalid e-mail-address <$adminEmail> for <$username>."; - } + $config->setUserValue($user->getUID(), 'settings', 'email', $options['adminemail']); } }