|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
View Code Duplication |
class BlackListPlugin extends \RainLoop\Plugins\AbstractPlugin |
|
|
|
|
|
|
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
|
|
|
|
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.