|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Mail-in-a-box Password Change Plugin |
|
4
|
|
|
* |
|
5
|
|
|
* Based on VirtualminChangePassword |
|
6
|
|
|
* |
|
7
|
|
|
* Author: Marius Gripsgard |
|
8
|
|
|
*/ |
|
9
|
|
View Code Duplication |
class MailInABoxChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
public function Init() |
|
12
|
|
|
{ |
|
13
|
|
|
$this->addHook('main.fabrica', 'MainFabrica'); |
|
14
|
|
|
} |
|
15
|
|
|
/** |
|
16
|
|
|
* @param string $sName |
|
17
|
|
|
* @param mixed $oProvider |
|
18
|
|
|
*/ |
|
19
|
|
|
public function MainFabrica($sName, &$oProvider) |
|
20
|
|
|
{ |
|
21
|
|
|
switch ($sName) |
|
22
|
|
|
{ |
|
23
|
|
|
case 'change-password': |
|
24
|
|
|
include_once __DIR__.'/MailInABoxChangePasswordDriver.php'; |
|
25
|
|
|
$sHost = \trim($this->Config()->Get('plugin', 'host', '')); |
|
26
|
|
|
$sAdminUser = (string) $this->Config()->Get('plugin', 'admin_user', ''); |
|
27
|
|
|
$sAdminPassword = (string) $this->Config()->Get('plugin', 'admin_password', ''); |
|
28
|
|
|
$oProvider = new \MailInABoxChangePasswordDriver(); |
|
29
|
|
|
$oProvider->SetLogger($this->Manager()->Actions()->Logger()); |
|
30
|
|
|
$oProvider->SetConfig($sHost, $sAdminUser, $sAdminPassword); |
|
31
|
|
|
$oProvider->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', '')))); |
|
32
|
|
|
break; |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
/** |
|
36
|
|
|
* @return array |
|
37
|
|
|
*/ |
|
38
|
|
|
public function configMapping() |
|
39
|
|
|
{ |
|
40
|
|
|
return array( |
|
41
|
|
|
\RainLoop\Plugins\Property::NewInstance('host')->SetLabel('Mail-in-a-box Host') |
|
42
|
|
|
->SetDefaultValue('https://box.mailinabox.email') |
|
43
|
|
|
->SetDescription('Mail-in-a-box host URL. Example: https://box.mailinabox.email'), |
|
44
|
|
|
\RainLoop\Plugins\Property::NewInstance('admin_user')->SetLabel('Admin User') |
|
45
|
|
|
->SetDefaultValue(''), |
|
46
|
|
|
\RainLoop\Plugins\Property::NewInstance('admin_password')->SetLabel('Admin Password') |
|
47
|
|
|
->SetDefaultValue(''), |
|
48
|
|
|
\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails') |
|
49
|
|
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT) |
|
50
|
|
|
->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: [email protected] [email protected] *@domain2.net') |
|
51
|
|
|
->SetDefaultValue('*') |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.