mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-04 23:17:02 +03:00
Add POPPASSD change password plugin
This commit is contained in:
parent
a8a21f42f7
commit
9ec92e9946
6 changed files with 198 additions and 0 deletions
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
class ChangePasswordPoppassdDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sHost = '127.0.0.1';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $iPort = 106;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sAllowedEmails = '';
|
||||
|
||||
/**
|
||||
* @var \MailSo\Log\Logger
|
||||
*/
|
||||
private $oLogger = null;
|
||||
|
||||
/**
|
||||
* @param string $sHost
|
||||
*
|
||||
* @return \ChangePasswordPoppassdDriver
|
||||
*/
|
||||
public function SetHost($sHost)
|
||||
{
|
||||
$this->sHost = $sHost;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $iHost
|
||||
*
|
||||
* @return \ChangePasswordPoppassdDriver
|
||||
*/
|
||||
public function SetPort($iHost)
|
||||
{
|
||||
$this->iHost = $iHost;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $aDomains
|
||||
*
|
||||
* @return \ChangePasswordPoppassdDriver
|
||||
*/
|
||||
public function SetAllowedEmails($sAllowedEmails)
|
||||
{
|
||||
$this->sAllowedEmails = $sAllowedEmails;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \MailSo\Log\Logger $oLogger
|
||||
*
|
||||
* @return \ChangePasswordPoppassdDriver
|
||||
*/
|
||||
public function SetLogger($oLogger)
|
||||
{
|
||||
if ($oLogger instanceof \MailSo\Log\Logger)
|
||||
{
|
||||
$this->oLogger = $oLogger;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Account $oAccount
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function PasswordChangePossibility($oAccount)
|
||||
{
|
||||
return $oAccount && $oAccount->Email() &&
|
||||
\RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->sAllowedEmails);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Account $oAccount
|
||||
* @param string $sPrevPassword
|
||||
* @param string $sNewPassword
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
|
||||
{
|
||||
$bResult = false;
|
||||
|
||||
try
|
||||
{
|
||||
$oPoppassdClient = \MailSo\Poppassd\PoppassdClient::NewInstance();
|
||||
if ($this->oLogger instanceof \MailSo\Log\Logger)
|
||||
{
|
||||
$oPoppassdClient->SetLogger($this->oLogger);
|
||||
}
|
||||
|
||||
$oPoppassdClient
|
||||
->Connect($this->sHost, $this->iPort)
|
||||
->Login($oAccount->Login(), $oAccount->Password())
|
||||
->NewPass($sNewPassword)
|
||||
->LogoutAndDisconnect()
|
||||
;
|
||||
|
||||
$bResult = true;
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
{
|
||||
$bResult = false;
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue