MailcowChangePasswordPlugin::MainFabrica()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 23

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
cc 5
nc 3
nop 2
dl 23
loc 23
rs 9.2408
c 0
b 0
f 0
1
<?php
2
3 View Code Duplication
class MailcowChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
4
{
5
	public function Init()
6
	{
7
		$this->addHook('main.fabrica', 'MainFabrica');
8
	}
9
10
	/**
11
	 * @return string
12
	 */
13
	public function Supported()
14
	{
15
		if (!extension_loaded('pdo') || !class_exists('PDO'))
16
		{
17
			return 'The PHP extension PDO (mysql) must be installed to use this plugin';
18
		}
19
20
		$aDrivers = \PDO::getAvailableDrivers();
21
		if (!is_array($aDrivers) || !in_array('mysql', $aDrivers))
22
		{
23
			return 'The PHP extension PDO (mysql) must be installed to use this plugin';
24
		}
25
26
		return '';
27
	}
28
29
	/**
30
	 * @param string $sName
31
	 * @param mixed $oProvider
32
	 */
33
	public function MainFabrica($sName, &$oProvider)
34
	{
35
		switch ($sName)
36
		{
37
			case 'change-password':
38
39
				$sDsn = \trim($this->Config()->Get('plugin', 'pdo_dsn', ''));
40
				$sUser = (string) $this->Config()->Get('plugin', 'user', '');
41
				$sPassword = (string) $this->Config()->Get('plugin', 'password', '');
42
43
				if (!empty($sDsn) && 0 < \strlen($sUser) && 0 < \strlen($sPassword))
44
				{
45
					include_once __DIR__.'/MailcowChangePasswordDriver.php';
46
47
					$oProvider = new MailcowChangePasswordDriver();
48
					$oProvider->SetLogger($this->Manager()->Actions()->Logger());
49
					$oProvider->SetConfig($sDsn, $sUser, $sPassword);
50
					$oProvider->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))));
51
				}
52
53
				break;
54
		}
55
	}
56
57
	/**
58
	 * @return array
59
	 */
60
	public function configMapping()
61
	{
62
		return array(
63
			\RainLoop\Plugins\Property::NewInstance('pdo_dsn')->SetLabel('Mailcow PDO dsn')
64
				->SetDefaultValue('mysql:host=127.0.0.1;dbname=mailcow'),
65
			\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('DB User')
66
				->SetDefaultValue('mailcow'),
67
			\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('DB Password')
68
				->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
69
				->SetDefaultValue(''),
70
			\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
71
				->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
72
				->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: [email protected] [email protected] *@domain2.net')
73
				->SetDefaultValue('*')
74
		);
75
	}
76
}
77