By default throw AccountNotAllowed as confused in #1478

This commit is contained in:
the-djmaze 2024-03-04 10:12:59 +01:00
parent 644c8ad389
commit 7d485813e5
2 changed files with 22 additions and 30 deletions

View file

@ -4,35 +4,31 @@ class BlackListPlugin extends \RainLoop\Plugins\AbstractPlugin
{ {
const const
NAME = 'Blacklist', NAME = 'Blacklist',
VERSION = '2.1', VERSION = '2.2',
RELEASE = '2021-04-21', RELEASE = '2024-03-04',
REQUIRED = '2.5.0', REQUIRED = '2.5.0',
CATEGORY = 'Login', CATEGORY = 'Login',
DESCRIPTION = 'Simple blacklist extension (with wildcard and exceptions functionality).'; DESCRIPTION = 'Simple blacklist extension (with wildcard and exceptions functionality).';
public function Init() : void public function Init() : void
{ {
$this->addHook('login.credentials', 'FilterLoginCredentials'); $this->addHook('login.credentials.step-1', 'FilterLoginCredentials');
} }
/** /**
* @param string $sEmail
* @param string $sLogin
* @param string $sPassword
*
* @throws \RainLoop\Exceptions\ClientException * @throws \RainLoop\Exceptions\ClientException
*/ */
public function FilterLoginCredentials(&$sEmail, &$sLogin, &$sPassword) public function FilterLoginCredentials(string &$sEmail)
{ {
$sBlackList = \trim($this->Config()->Get('plugin', 'black_list', '')); $sBlackList = \trim($this->Config()->Get('plugin', 'black_list', ''));
if (0 < \strlen($sBlackList) && \RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sBlackList)) if (\strlen($sBlackList) && \RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sBlackList)) {
{
$sExceptions = \trim($this->Config()->Get('plugin', 'exceptions', '')); $sExceptions = \trim($this->Config()->Get('plugin', 'exceptions', ''));
if (0 === \strlen($sExceptions) || !\RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sExceptions)) if (!\strlen($sExceptions) || !\RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sExceptions)) {
{
throw new \RainLoop\Exceptions\ClientException( throw new \RainLoop\Exceptions\ClientException(
$this->Config()->Get('plugin', 'auth_error', true) ? $this->Config()->Get('plugin', 'auth_error', false)
\RainLoop\Notifications::AuthError : \RainLoop\Notifications::AccountNotAllowed); ? \RainLoop\Notifications::AuthError
: \RainLoop\Notifications::AccountNotAllowed
);
} }
} }
} }
@ -46,7 +42,7 @@ class BlackListPlugin extends \RainLoop\Plugins\AbstractPlugin
\RainLoop\Plugins\Property::NewInstance('auth_error')->SetLabel('Auth Error') \RainLoop\Plugins\Property::NewInstance('auth_error')->SetLabel('Auth Error')
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL) ->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
->SetDescription('Throw an authentication error instead of an access error.') ->SetDescription('Throw an authentication error instead of an access error.')
->SetDefaultValue(true), ->SetDefaultValue(false),
\RainLoop\Plugins\Property::NewInstance('black_list')->SetLabel('Black List') \RainLoop\Plugins\Property::NewInstance('black_list')->SetLabel('Black List')
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT) ->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
->SetDescription('Emails black list, space as delimiter, wildcard supported.') ->SetDescription('Emails black list, space as delimiter, wildcard supported.')

View file

@ -4,35 +4,31 @@ class WhiteListPlugin extends \RainLoop\Plugins\AbstractPlugin
{ {
const const
NAME = 'Whitelist', NAME = 'Whitelist',
VERSION = '2.1', VERSION = '2.2',
RELEASE = '2021-04-21', RELEASE = '2024-03-04',
REQUIRED = '2.5.0', REQUIRED = '2.5.0',
CATEGORY = 'Login', CATEGORY = 'Login',
DESCRIPTION = 'Simple login whitelist (with wildcard and exceptions functionality).'; DESCRIPTION = 'Simple login whitelist (with wildcard and exceptions functionality).';
public function Init() : void public function Init() : void
{ {
$this->addHook('login.credentials', 'FilterLoginCredentials'); $this->addHook('login.credentials.step-1', 'FilterLoginCredentials');
} }
/** /**
* @param string $sEmail
* @param string $sLogin
* @param string $sPassword
*
* @throws \RainLoop\Exceptions\ClientException * @throws \RainLoop\Exceptions\ClientException
*/ */
public function FilterLoginCredentials(&$sEmail, &$sLogin, &$sPassword) public function FilterLoginCredentials(string &$sEmail)
{ {
$sWhiteList = \trim($this->Config()->Get('plugin', 'white_list', '')); $sWhiteList = \trim($this->Config()->Get('plugin', 'white_list', ''));
if (0 < strlen($sWhiteList) && !\RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sWhiteList)) if (\strlen($sWhiteList) && !\RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sWhiteList)) {
{
$sExceptions = \trim($this->Config()->Get('plugin', 'exceptions', '')); $sExceptions = \trim($this->Config()->Get('plugin', 'exceptions', ''));
if (0 === \strlen($sExceptions) || !\RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sExceptions)) if (!\strlen($sExceptions) || \RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sExceptions)) {
{
throw new \RainLoop\Exceptions\ClientException( throw new \RainLoop\Exceptions\ClientException(
$this->Config()->Get('plugin', 'auth_error', true) ? $this->Config()->Get('plugin', 'auth_error', false)
\RainLoop\Notifications::AuthError : \RainLoop\Notifications::AccountNotAllowed); ? \RainLoop\Notifications::AuthError
: \RainLoop\Notifications::AccountNotAllowed
);
} }
} }
} }
@ -46,7 +42,7 @@ class WhiteListPlugin extends \RainLoop\Plugins\AbstractPlugin
\RainLoop\Plugins\Property::NewInstance('auth_error')->SetLabel('Auth Error') \RainLoop\Plugins\Property::NewInstance('auth_error')->SetLabel('Auth Error')
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL) ->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
->SetDescription('Throw an authentication error instead of an access error.') ->SetDescription('Throw an authentication error instead of an access error.')
->SetDefaultValue(true), ->SetDefaultValue(false),
\RainLoop\Plugins\Property::NewInstance('white_list')->SetLabel('White List') \RainLoop\Plugins\Property::NewInstance('white_list')->SetLabel('White List')
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT) ->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
->SetDescription('Emails white list, space as delimiter, wildcard supported.') ->SetDescription('Emails white list, space as delimiter, wildcard supported.')