Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit 027ce6c

Browse files
author
the-djmaze
committed
Resolve #1552
1 parent 1b0962c commit 027ce6c

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

integrations/nextcloud/snappymail/appinfo/info.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,7 @@ There, click on the link to go to the SnappyMail admin panel.
8686
<step>OCA\SnappyMail\Migration\InstallStep</step>
8787
</post-migration>
8888
</repair-steps>
89+
<commands>
90+
<command>OCA\SnappyMail\Command\Settings</command>
91+
</commands>
8992
</info>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)