snappymail/plugins/proxyauth-login-example/index.php

44 lines
1,023 B
PHP
Raw Normal View History

<?php
2023-10-24 17:43:47 +08:00
use RainLoop\Model\MainAccount;
class ProxyauthLoginExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
{
const
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',
CATEGORY = 'General',
DESCRIPTION = '';
2020-08-31 00:04:54 +08:00
public function Init() : void
{
$this->addHook('login.success', '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
*/
2023-10-24 17:43:47 +08:00
public function EventLoginPostLoginProvide(MainAccount $oAccount)
{
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);
}
2023-10-24 17:43:47 +08:00
$oAccount->SetProxyAuthUser('admin@domain.com');
$oAccount->SetProxyAuthPassword('secret-admin-password');
}
}