|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace OCA\SnappyMail\Command; |
| 4 | + |
| 5 | +use OCA\SnappyMail\Util\SnappyMailHelper; |
| 6 | +use OC\Core\Command\Base; |
| 7 | +use OCP\IConfig; |
| 8 | +use OCP\IUserManager; |
| 9 | +use Symfony\Component\Console\Input\InputArgument; |
| 10 | +use Symfony\Component\Console\Input\InputInterface; |
| 11 | +use Symfony\Component\Console\Output\OutputInterface; |
| 12 | + |
| 13 | +class Settings extends Base |
| 14 | +{ |
| 15 | + protected IUserManager $userManager; |
| 16 | + protected IConfig $config; |
| 17 | + |
| 18 | + public function __construct(IUserManager $userManager, IConfig $config) { |
| 19 | + parent::__construct(); |
| 20 | + $this->userManager = $userManager; |
| 21 | + $this->config = $config; |
| 22 | + } |
| 23 | + |
| 24 | + protected function configure() { |
| 25 | + $this |
| 26 | + ->setName('snappymail:settings') |
| 27 | + ->setDescription('modifies configuration') |
| 28 | + ->addArgument( |
| 29 | + 'uid', |
| 30 | + InputArgument::REQUIRED, |
| 31 | + 'User ID used to login' |
| 32 | + ) |
| 33 | + ->addArgument( |
| 34 | + 'user', |
| 35 | + InputArgument::REQUIRED, |
| 36 | + 'The login username' |
| 37 | + ) |
| 38 | + ->addArgument( |
| 39 | + 'pass', |
| 40 | + InputArgument::REQUIRED, |
| 41 | + 'The login passphrase' |
| 42 | + ) |
| 43 | + ; |
| 44 | + } |
| 45 | + |
| 46 | + protected function checkInput(InputInterface $input) { |
| 47 | + } |
| 48 | + |
| 49 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
| 50 | + $uid = $input->getArgument('uid'); |
| 51 | + if (!$this->userManager->userExists($uid)) { |
| 52 | + $output->writeln('<error>The user "' . $uid . '" does not exist.</error>'); |
| 53 | + return 1; |
| 54 | + } |
| 55 | + |
| 56 | + $sEmail = $input->getArgument('user'); |
| 57 | + $this->config->setUserValue($uid, 'snappymail', 'snappymail-email', $sEmail); |
| 58 | + |
| 59 | + $sPass = $input->getArgument('pass'); |
| 60 | + $sPass = ($sEmail && $sPass) ? SnappyMailHelper::encodePassword($sPass, \md5($sEmail)) : ''; |
| 61 | + $this->config->setUserValue($uid, 'snappymail', 'passphrase', $sPass); |
| 62 | + return 0; |
| 63 | + } |
| 64 | +} |
0 commit comments