|
1 | | -<?php |
2 | | - |
3 | | -/** |
4 | | - * @copyright Copyright (c) 2023 FedericoHeichou <federicoheichou@gmail.com> |
5 | | - * |
6 | | - * @author FedericoHeichou <federicoheichou@gmail.com> |
7 | | - * |
8 | | - * @license GNU AGPL version 3 or any later version |
9 | | - * |
10 | | - * This program is free software: you can redistribute it and/or modify |
11 | | - * it under the terms of the GNU Affero General Public License as |
12 | | - * published by the Free Software Foundation, either version 3 of the |
13 | | - * License, or (at your option) any later version. |
14 | | - * |
15 | | - * This program is distributed in the hope that it will be useful, |
16 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | | - * GNU Affero General Public License for more details. |
19 | | - * |
20 | | - * You should have received a copy of the GNU Affero General Public License |
21 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 | | - * |
23 | | - */ |
24 | | - |
25 | | -namespace OC\Core\Command\User; |
26 | | - |
27 | | -use OC\Core\Command\Base; |
28 | | -use OCA\Settings\Mailer\NewUserMailHelper; |
29 | | -use OCP\IUserManager; |
30 | | -use Symfony\Component\Console\Input\InputArgument; |
31 | | -use Symfony\Component\Console\Input\InputInterface; |
32 | | -use Symfony\Component\Console\Input\InputOption; |
33 | | -use Symfony\Component\Console\Output\OutputInterface; |
34 | | - |
35 | | -class Welcome extends Base { |
36 | | - /** @var IUserManager */ |
37 | | - protected $userManager; |
38 | | - |
39 | | - /** @var NewUserMailHelper */ |
40 | | - private $newUserMailHelper; |
41 | | - |
42 | | - /** |
43 | | - * @param IUserManager $userManager |
44 | | - * @param NewUserMailHelper $newUserMailHelper |
45 | | - */ |
46 | | - public function __construct( |
47 | | - IUserManager $userManager, |
48 | | - NewUserMailHelper $newUserMailHelper |
49 | | - ) { |
50 | | - parent::__construct(); |
51 | | - |
52 | | - $this->userManager = $userManager; |
53 | | - $this->newUserMailHelper = $newUserMailHelper; |
54 | | - } |
55 | | - |
56 | | - protected function configure() { |
57 | | - $this |
58 | | - ->setName('user:welcome') |
59 | | - ->setDescription('Sends the welcome email') |
60 | | - ->addArgument( |
61 | | - 'user', |
62 | | - InputArgument::REQUIRED, |
63 | | - 'The user to send the email to' |
64 | | - ) |
65 | | - ->addOption( |
66 | | - 'reset-password', |
67 | | - 'r', |
68 | | - InputOption::VALUE_NONE, |
69 | | - 'Add the reset password link to the email' |
70 | | - ) |
71 | | - ; |
72 | | - } |
73 | | - |
74 | | - /** |
75 | | - * @param InputInterface $input |
76 | | - * @param OutputInterface $output |
77 | | - * @return int |
78 | | - */ |
79 | | - protected function execute(InputInterface $input, OutputInterface $output): int { |
80 | | - $userId = $input->getArgument('user'); |
81 | | - // check if user exists |
82 | | - $user = $this->userManager->get($userId); |
83 | | - if ($user === null) { |
84 | | - $output->writeln('<error>User does not exist</error>'); |
85 | | - return 1; |
86 | | - } |
87 | | - $email = $user->getEMailAddress(); |
88 | | - if ($email === '' || $email === null) { |
89 | | - $output->writeln('<error>User does not have an email address</error>'); |
90 | | - return 1; |
91 | | - } |
92 | | - try { |
93 | | - $emailTemplate = $this->newUserMailHelper->generateTemplate($user, $input->getOption('reset-password')); |
94 | | - $this->newUserMailHelper->sendMail($user, $emailTemplate); |
95 | | - } catch (\Exception $e) { |
96 | | - $output->writeln('<error>Failed to send email: ' . $e->getMessage() . '</error>'); |
97 | | - return 1; |
98 | | - } |
99 | | - return 0; |
100 | | - } |
101 | | -} |
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @copyright Copyright (c) 2023 FedericoHeichou <federicoheichou@gmail.com> |
| 5 | + * |
| 6 | + * @author FedericoHeichou <federicoheichou@gmail.com> |
| 7 | + * |
| 8 | + * @license GNU AGPL version 3 or any later version |
| 9 | + * |
| 10 | + * This program is free software: you can redistribute it and/or modify |
| 11 | + * it under the terms of the GNU Affero General Public License as |
| 12 | + * published by the Free Software Foundation, either version 3 of the |
| 13 | + * License, or (at your option) any later version. |
| 14 | + * |
| 15 | + * This program is distributed in the hope that it will be useful, |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | + * GNU Affero General Public License for more details. |
| 19 | + * |
| 20 | + * You should have received a copy of the GNU Affero General Public License |
| 21 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | + * |
| 23 | + */ |
| 24 | + |
| 25 | +namespace OC\Core\Command\User; |
| 26 | + |
| 27 | +use OC\Core\Command\Base; |
| 28 | +use OCA\Settings\Mailer\NewUserMailHelper; |
| 29 | +use OCP\IUserManager; |
| 30 | +use Symfony\Component\Console\Input\InputArgument; |
| 31 | +use Symfony\Component\Console\Input\InputInterface; |
| 32 | +use Symfony\Component\Console\Input\InputOption; |
| 33 | +use Symfony\Component\Console\Output\OutputInterface; |
| 34 | + |
| 35 | +class Welcome extends Base { |
| 36 | + /** @var IUserManager */ |
| 37 | + protected $userManager; |
| 38 | + |
| 39 | + /** @var NewUserMailHelper */ |
| 40 | + private $newUserMailHelper; |
| 41 | + |
| 42 | + /** |
| 43 | + * @param IUserManager $userManager |
| 44 | + * @param NewUserMailHelper $newUserMailHelper |
| 45 | + */ |
| 46 | + public function __construct( |
| 47 | + IUserManager $userManager, |
| 48 | + NewUserMailHelper $newUserMailHelper |
| 49 | + ) { |
| 50 | + parent::__construct(); |
| 51 | + |
| 52 | + $this->userManager = $userManager; |
| 53 | + $this->newUserMailHelper = $newUserMailHelper; |
| 54 | + } |
| 55 | + |
| 56 | + protected function configure() { |
| 57 | + $this |
| 58 | + ->setName('user:welcome') |
| 59 | + ->setDescription('Sends the welcome email') |
| 60 | + ->addArgument( |
| 61 | + 'user', |
| 62 | + InputArgument::REQUIRED, |
| 63 | + 'The user to send the email to' |
| 64 | + ) |
| 65 | + ->addOption( |
| 66 | + 'reset-password', |
| 67 | + 'r', |
| 68 | + InputOption::VALUE_NONE, |
| 69 | + 'Add the reset password link to the email' |
| 70 | + ) |
| 71 | + ; |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * @param InputInterface $input |
| 76 | + * @param OutputInterface $output |
| 77 | + * @return int |
| 78 | + */ |
| 79 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
| 80 | + $userId = $input->getArgument('user'); |
| 81 | + // check if user exists |
| 82 | + $user = $this->userManager->get($userId); |
| 83 | + if ($user === null) { |
| 84 | + $output->writeln('<error>User does not exist</error>'); |
| 85 | + return 1; |
| 86 | + } |
| 87 | + $email = $user->getEMailAddress(); |
| 88 | + if ($email === '' || $email === null) { |
| 89 | + $output->writeln('<error>User does not have an email address</error>'); |
| 90 | + return 1; |
| 91 | + } |
| 92 | + try { |
| 93 | + $emailTemplate = $this->newUserMailHelper->generateTemplate($user, $input->getOption('reset-password')); |
| 94 | + $this->newUserMailHelper->sendMail($user, $emailTemplate); |
| 95 | + } catch (\Exception $e) { |
| 96 | + $output->writeln('<error>Failed to send email: ' . $e->getMessage() . '</error>'); |
| 97 | + return 1; |
| 98 | + } |
| 99 | + return 0; |
| 100 | + } |
| 101 | +} |
0 commit comments