Merge pull request #39611 from FedericoHeichou/add-command-user-welcome

pull/47277/head
John Molakvoæ 3 months ago committed by GitHub
commit 62f9c26111
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 86
      core/Command/User/Welcome.php
  2. 1
      core/register_command.php
  3. 1
      lib/composer/composer/autoload_classmap.php
  4. 1
      lib/composer/composer/autoload_static.php

@ -0,0 +1,86 @@
<?php
/**
* SPDX-FileCopyrightText: 2023 FedericoHeichou <federicoheichou@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Core\Command\User;
use OC\Core\Command\Base;
use OCA\Settings\Mailer\NewUserMailHelper;
use OCP\IUserManager;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class Welcome extends Base {
/** @var IUserManager */
protected $userManager;
/** @var NewUserMailHelper */
private $newUserMailHelper;
/**
* @param IUserManager $userManager
* @param NewUserMailHelper $newUserMailHelper
*/
public function __construct(
IUserManager $userManager,
NewUserMailHelper $newUserMailHelper
) {
parent::__construct();
$this->userManager = $userManager;
$this->newUserMailHelper = $newUserMailHelper;
}
/**
* @return void
*/
protected function configure() {
$this
->setName('user:welcome')
->setDescription('Sends the welcome email')
->addArgument(
'user',
InputArgument::REQUIRED,
'The user to send the email to'
)
->addOption(
'reset-password',
'r',
InputOption::VALUE_NONE,
'Add the reset password link to the email'
)
;
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$userId = $input->getArgument('user');
// check if user exists
$user = $this->userManager->get($userId);
if ($user === null) {
$output->writeln('<error>User does not exist</error>');
return 1;
}
$email = $user->getEMailAddress();
if ($email === '' || $email === null) {
$output->writeln('<error>User does not have an email address</error>');
return 1;
}
try {
$emailTemplate = $this->newUserMailHelper->generateTemplate($user, $input->getOption('reset-password'));
$this->newUserMailHelper->sendMail($user, $emailTemplate);
} catch (\Exception $e) {
$output->writeln('<error>Failed to send email: ' . $e->getMessage() . '</error>');
return 1;
}
return 0;
}
}

@ -122,6 +122,7 @@ if ($config->getSystemValueBool('installed', false)) {
$application->add(Server::get(Command\User\AuthTokens\ListCommand::class)); $application->add(Server::get(Command\User\AuthTokens\ListCommand::class));
$application->add(Server::get(Command\User\AuthTokens\Delete::class)); $application->add(Server::get(Command\User\AuthTokens\Delete::class));
$application->add(Server::get(Command\User\Keys\Verify::class)); $application->add(Server::get(Command\User\Keys\Verify::class));
$application->add(Server::get(Command\User\Welcome::class));
$application->add(Server::get(Command\Group\Add::class)); $application->add(Server::get(Command\Group\Add::class));
$application->add(Server::get(Command\Group\Delete::class)); $application->add(Server::get(Command\Group\Delete::class));

@ -1241,6 +1241,7 @@ return array(
'OC\\Core\\Command\\User\\ResetPassword' => $baseDir . '/core/Command/User/ResetPassword.php', 'OC\\Core\\Command\\User\\ResetPassword' => $baseDir . '/core/Command/User/ResetPassword.php',
'OC\\Core\\Command\\User\\Setting' => $baseDir . '/core/Command/User/Setting.php', 'OC\\Core\\Command\\User\\Setting' => $baseDir . '/core/Command/User/Setting.php',
'OC\\Core\\Command\\User\\SyncAccountDataCommand' => $baseDir . '/core/Command/User/SyncAccountDataCommand.php', 'OC\\Core\\Command\\User\\SyncAccountDataCommand' => $baseDir . '/core/Command/User/SyncAccountDataCommand.php',
'OC\\Core\\Command\\User\\Welcome' => $baseDir . '/core/Command/User/Welcome.php',
'OC\\Core\\Controller\\AppPasswordController' => $baseDir . '/core/Controller/AppPasswordController.php', 'OC\\Core\\Controller\\AppPasswordController' => $baseDir . '/core/Controller/AppPasswordController.php',
'OC\\Core\\Controller\\AutoCompleteController' => $baseDir . '/core/Controller/AutoCompleteController.php', 'OC\\Core\\Controller\\AutoCompleteController' => $baseDir . '/core/Controller/AutoCompleteController.php',
'OC\\Core\\Controller\\AvatarController' => $baseDir . '/core/Controller/AvatarController.php', 'OC\\Core\\Controller\\AvatarController' => $baseDir . '/core/Controller/AvatarController.php',

@ -1274,6 +1274,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Core\\Command\\User\\ResetPassword' => __DIR__ . '/../../..' . '/core/Command/User/ResetPassword.php', 'OC\\Core\\Command\\User\\ResetPassword' => __DIR__ . '/../../..' . '/core/Command/User/ResetPassword.php',
'OC\\Core\\Command\\User\\Setting' => __DIR__ . '/../../..' . '/core/Command/User/Setting.php', 'OC\\Core\\Command\\User\\Setting' => __DIR__ . '/../../..' . '/core/Command/User/Setting.php',
'OC\\Core\\Command\\User\\SyncAccountDataCommand' => __DIR__ . '/../../..' . '/core/Command/User/SyncAccountDataCommand.php', 'OC\\Core\\Command\\User\\SyncAccountDataCommand' => __DIR__ . '/../../..' . '/core/Command/User/SyncAccountDataCommand.php',
'OC\\Core\\Command\\User\\Welcome' => __DIR__ . '/../../..' . '/core/Command/User/Welcome.php',
'OC\\Core\\Controller\\AppPasswordController' => __DIR__ . '/../../..' . '/core/Controller/AppPasswordController.php', 'OC\\Core\\Controller\\AppPasswordController' => __DIR__ . '/../../..' . '/core/Controller/AppPasswordController.php',
'OC\\Core\\Controller\\AutoCompleteController' => __DIR__ . '/../../..' . '/core/Controller/AutoCompleteController.php', 'OC\\Core\\Controller\\AutoCompleteController' => __DIR__ . '/../../..' . '/core/Controller/AutoCompleteController.php',
'OC\\Core\\Controller\\AvatarController' => __DIR__ . '/../../..' . '/core/Controller/AvatarController.php', 'OC\\Core\\Controller\\AvatarController' => __DIR__ . '/../../..' . '/core/Controller/AvatarController.php',

Loading…
Cancel
Save