This commit is contained in:
the-djmaze 2024-04-22 13:56:53 +02:00
parent 1b0962cce1
commit 027ce6ccae
2 changed files with 67 additions and 0 deletions

View file

@ -86,4 +86,7 @@ There, click on the link to go to the SnappyMail admin panel.
<step>OCA\SnappyMail\Migration\InstallStep</step>
</post-migration>
</repair-steps>
<commands>
<command>OCA\SnappyMail\Command\Settings</command>
</commands>
</info>

View file

@ -0,0 +1,64 @@
<?php
namespace OCA\SnappyMail\Command;
use OCA\SnappyMail\Util\SnappyMailHelper;
use OC\Core\Command\Base;
use OCP\IConfig;
use OCP\IUserManager;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Settings extends Base
{
protected IUserManager $userManager;
protected IConfig $config;
public function __construct(IUserManager $userManager, IConfig $config) {
parent::__construct();
$this->userManager = $userManager;
$this->config = $config;
}
protected function configure() {
$this
->setName('snappymail:settings')
->setDescription('modifies configuration')
->addArgument(
'uid',
InputArgument::REQUIRED,
'User ID used to login'
)
->addArgument(
'user',
InputArgument::REQUIRED,
'The login username'
)
->addArgument(
'pass',
InputArgument::REQUIRED,
'The login passphrase'
)
;
}
protected function checkInput(InputInterface $input) {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$uid = $input->getArgument('uid');
if (!$this->userManager->userExists($uid)) {
$output->writeln('<error>The user "' . $uid . '" does not exist.</error>');
return 1;
}
$sEmail = $input->getArgument('user');
$this->config->setUserValue($uid, 'snappymail', 'snappymail-email', $sEmail);
$sPass = $input->getArgument('pass');
$sPass = ($sEmail && $sPass) ? SnappyMailHelper::encodePassword($sPass, \md5($sEmail)) : '';
$this->config->setUserValue($uid, 'snappymail', 'passphrase', $sPass);
return 0;
}
}