2014-10-16 23:57:47 +08:00
|
|
|
<?php
|
|
|
|
|
2023-10-24 17:43:47 +08:00
|
|
|
use RainLoop\Model\MainAccount;
|
|
|
|
|
2014-10-16 23:57:47 +08:00
|
|
|
class ProxyauthLoginExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
|
|
|
|
{
|
2021-02-10 16:50:20 +08:00
|
|
|
const
|
2021-08-28 05:49:03 +08:00
|
|
|
NAME = 'Proxy Auth Login Example',
|
2022-12-09 00:15:46 +08:00
|
|
|
VERSION = '2.2',
|
2023-10-24 17:43:47 +08:00
|
|
|
RELEASE = '2023-10-24',
|
2022-12-09 00:15:46 +08:00
|
|
|
REQUIRED = '2.23.0',
|
2021-02-10 16:50:20 +08:00
|
|
|
CATEGORY = 'General',
|
|
|
|
DESCRIPTION = '';
|
|
|
|
|
2020-08-31 00:04:54 +08:00
|
|
|
public function Init() : void
|
2014-10-16 23:57:47 +08:00
|
|
|
{
|
2021-04-14 20:30:42 +08:00
|
|
|
$this->addHook('login.success', 'EventLoginPostLoginProvide');
|
2014-10-16 23:57:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-15 04:23:46 +08:00
|
|
|
* @param string $sLogin
|
|
|
|
* @param string $sPassword
|
|
|
|
*/
|
|
|
|
public function isValidAccount($sLogin, $sPassword)
|
|
|
|
{
|
|
|
|
return !empty($sLogin) && !empty($sPassword);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \RainLoop\Model\Account $oAccount
|
2014-10-16 23:57:47 +08:00
|
|
|
*/
|
2023-10-24 17:43:47 +08:00
|
|
|
public function EventLoginPostLoginProvide(MainAccount $oAccount)
|
2014-10-16 23:57:47 +08:00
|
|
|
{
|
2023-10-24 17:43:47 +08:00
|
|
|
// Verify logic
|
|
|
|
if (!$this->isValidAccount($oAccount->IncLogin(), $oAccount->IncPassword())) {
|
|
|
|
// throw a Auth Error Exception
|
|
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError);
|
2014-10-16 23:57:47 +08:00
|
|
|
}
|
2023-10-24 17:43:47 +08:00
|
|
|
|
|
|
|
$oAccount->SetProxyAuthUser('admin@domain.com');
|
|
|
|
$oAccount->SetProxyAuthPassword('secret-admin-password');
|
2014-10-16 23:57:47 +08:00
|
|
|
}
|
|
|
|
}
|