|
11 | 11 | use OC\Authentication\Events\AppPasswordCreatedEvent; |
12 | 12 | use OC\Authentication\Token\IProvider; |
13 | 13 | use OC\Authentication\Token\IToken; |
| 14 | +use OC\User\Manager as UserManager; |
14 | 15 | use OCP\EventDispatcher\IEventDispatcher; |
15 | | -use OCP\IUserManager; |
16 | 16 | use OCP\Security\ISecureRandom; |
17 | 17 | use Symfony\Component\Console\Command\Command; |
18 | 18 | use Symfony\Component\Console\Helper\QuestionHelper; |
|
24 | 24 |
|
25 | 25 | class Add extends Command { |
26 | 26 | public function __construct( |
27 | | - protected IUserManager $userManager, |
28 | | - protected IProvider $tokenProvider, |
| 27 | + private UserManager $userManager, |
| 28 | + private IProvider $tokenProvider, |
29 | 29 | private ISecureRandom $random, |
30 | 30 | private IEventDispatcher $eventDispatcher, |
31 | 31 | ) { |
@@ -83,8 +83,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
83 | 83 | $password = $helper->ask($input, $output, $question); |
84 | 84 | } |
85 | 85 |
|
| 86 | + $loginName = $input->getOption('login-name') ?? $user->getUID(); |
| 87 | + |
86 | 88 | if ($password === null) { |
87 | 89 | $output->writeln('<info>No password provided. The generated app password will therefore have limited capabilities. Any operation that requires the login password will fail.</info>'); |
| 90 | + } else { |
| 91 | + $loggedInUser = $this->userManager->checkPasswordNoLogging($loginName, $password); |
| 92 | + if ($loggedInUser === false) { |
| 93 | + $output->writeln('<error>The given password is invalid for login ' . $loginName . '</error>'); |
| 94 | + return self::FAILURE; |
| 95 | + } elseif ($loggedInUser->getUID() !== $user->getUID()) { |
| 96 | + $output->writeln('<error>The user ' . $username . ' does not match the given login ' . $loginName . '</error>'); |
| 97 | + return self::FAILURE; |
| 98 | + } |
88 | 99 | } |
89 | 100 |
|
90 | 101 | $tokenName = $input->getOption('name') ?: 'cli'; |
|
0 commit comments