BlackListPlugin::Init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 4
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3 View Code Duplication
class BlackListPlugin 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('filter.login-credentials', 'FilterLoginCredentials');
8
	}
9
10
	/**
11
	 * @param string $sEmail
12
	 * @param string $sLogin
13
	 * @param string $sPassword
14
	 *
15
	 * @throws \RainLoop\Exceptions\ClientException
16
	 */
17
	public function FilterLoginCredentials(&$sEmail, &$sLogin, &$sPassword)
18
	{
19
		$sBlackList = \trim($this->Config()->Get('plugin', 'black_list', ''));
20
		if (0 < \strlen($sBlackList) && \RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sBlackList))
21
		{
22
			$sExceptions = \trim($this->Config()->Get('plugin', 'exceptions', ''));
23
			if (0 === \strlen($sExceptions) || !\RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sExceptions))
24
			{
25
				throw new \RainLoop\Exceptions\ClientException(
26
					$this->Config()->Get('plugin', 'auth_error', true) ?
27
						\RainLoop\Notifications::AuthError : \RainLoop\Notifications::AccountNotAllowed);
28
			}
29
		}
30
	}
31
32
	/**
33
	 * @return array
34
	 */
35
	public function configMapping()
36
	{
37
		return array(
38
			\RainLoop\Plugins\Property::NewInstance('auth_error')->SetLabel('Auth Error')
39
				->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
40
				->SetDescription('Throw an authentication error instead of an access error.')
41
				->SetDefaultValue(true),
42
			\RainLoop\Plugins\Property::NewInstance('black_list')->SetLabel('Black List')
43
				->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
44
				->SetDescription('Emails black list, space as delimiter, wildcard supported.')
45
				->SetDefaultValue('*@domain1.com [email protected]'),
46
			\RainLoop\Plugins\Property::NewInstance('exceptions')->SetLabel('Exceptions')
47
				->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
48
				->SetDescription('Exceptions for black list, space as delimiter, wildcard supported.')
49
				->SetDefaultValue('[email protected] *@domain2.com admin@*')
50
		);
51
	}
52
}
53