2014-10-16 23:57:47 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class ProxyauthLoginExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
|
|
|
|
{
|
|
|
|
public function Init()
|
|
|
|
{
|
|
|
|
$this->addHook('event.login-post-login-provide', 'EventLoginPostLoginProvide');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
|
|
|
public function EventLoginPostLoginProvide(&$oAccount)
|
|
|
|
{
|
2014-11-15 04:23:46 +08:00
|
|
|
if ($oAccount instanceof \RainLoop\Model\Account)
|
2014-10-16 23:57:47 +08:00
|
|
|
{
|
|
|
|
// Verify logic
|
2015-02-01 23:44:44 +08:00
|
|
|
$bValid = $this->isValidAccount($oAccount->Login(), $oAccount->Password());
|
2014-10-16 23:57:47 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* $oAccount->Email(); // Email (It is not a IMAP login)
|
|
|
|
* $oAccount->Login(); // IMAP login
|
|
|
|
* $oAccount->Password(); // IMAP password
|
|
|
|
* $oAccount->DomainIncHost(); // IMAP host
|
|
|
|
*
|
2014-11-15 04:23:46 +08:00
|
|
|
* @see \RainLoo\Model\Account for more
|
2014-10-16 23:57:47 +08:00
|
|
|
*/
|
|
|
|
|
2014-11-15 04:23:46 +08:00
|
|
|
if (!$bValid) // if verify failed
|
2014-10-16 23:57:47 +08:00
|
|
|
{
|
|
|
|
// throw a Auth Error Exception
|
|
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError);
|
|
|
|
}
|
|
|
|
else // Or setup your proxyauth admin account credentials
|
|
|
|
{
|
|
|
|
$oAccount->SetProxyAuthUser('admin@domain.com');
|
|
|
|
$oAccount->SetProxyAuthPassword('secret-admin-password');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|