mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-06 16:07:03 +03:00
Some fixes (ChangePasswordCustomSql Plugin)
This commit is contained in:
parent
c0aa67dc52
commit
cbc1aa2f4c
6 changed files with 35 additions and 50 deletions
|
|
@ -125,8 +125,7 @@ class ChangePasswordCustomSqlDriver implements \RainLoop\Providers\ChangePasswor
|
||||||
*/
|
*/
|
||||||
public function PasswordChangePossibility($oAccount)
|
public function PasswordChangePossibility($oAccount)
|
||||||
{
|
{
|
||||||
return $oAccount && $oAccount->Email() &&
|
return $oAccount && $oAccount->Email();
|
||||||
\RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->sAllowedEmails);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -157,45 +156,35 @@ class ChangePasswordCustomSqlDriver implements \RainLoop\Providers\ChangePasswor
|
||||||
$conn = new PDO($dsn,$this->mUser,$this->mPass,$options);
|
$conn = new PDO($dsn,$this->mUser,$this->mPass,$options);
|
||||||
|
|
||||||
//prepare SQL varaibles
|
//prepare SQL varaibles
|
||||||
$sEmail = $oAccount->Email();
|
$sEmail = $oAccount->Email();
|
||||||
$sEmailUser = \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail);
|
$sEmailUser = \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail);
|
||||||
$sEmailDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail);
|
$sEmailDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail);
|
||||||
|
|
||||||
//simple check
|
//simple check
|
||||||
|
|
||||||
$old = array(':email', ':oldpass', ':newpass', ':domain', ':username', ':table' );
|
$old = array(':email', ':oldpass', ':newpass', ':domain', ':username', ':table' );
|
||||||
$new = array($sEmail, $sPrevPassword, $sNewPassword, $sEmailDomain, $sEmailUser, $this->mTable);
|
$new = array($sEmail, $sPrevPassword, $sNewPassword, $sEmailDomain, $sEmailUser, $this->mTable);
|
||||||
|
|
||||||
$this->mSql = str_replace($old, $new, $this->mSql);
|
$this->mSql = str_replace($old, $new, $this->mSql);
|
||||||
|
|
||||||
$update = $conn->prepare($this->mSql);
|
|
||||||
$mSqlReturn = $update->execute(array());
|
|
||||||
/* $mSqlReturn = $update->execute(array(
|
|
||||||
':email' => $sEmail,
|
|
||||||
':oldpass' => $sPrevPassword,
|
|
||||||
':newpass' => $sNewPassword,
|
|
||||||
':domain' => $sEmailDomain,
|
|
||||||
':username' => $sEmailUser,
|
|
||||||
':table' => $this->mTable
|
|
||||||
));
|
|
||||||
*/
|
|
||||||
if ($mSqlReturn == true)
|
|
||||||
{
|
|
||||||
$bResult = true;
|
|
||||||
if ($this->oLogger)
|
|
||||||
{
|
|
||||||
$this->oLogger->Write('Success! Password changed.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$bResult = false;
|
|
||||||
if ($this->oLogger)
|
|
||||||
{
|
|
||||||
$this->oLogger->Write('Something went wrong. Either current password is incorrect, or new password does not match criteria.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$update = $conn->prepare($this->mSql);
|
||||||
|
$mSqlReturn = $update->execute(array());
|
||||||
|
if ($mSqlReturn == true)
|
||||||
|
{
|
||||||
|
$bResult = true;
|
||||||
|
if ($this->oLogger)
|
||||||
|
{
|
||||||
|
$this->oLogger->Write('Success! Password changed.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$bResult = false;
|
||||||
|
if ($this->oLogger)
|
||||||
|
{
|
||||||
|
$this->oLogger->Write('Something went wrong. Either current password is incorrect, or new password does not match criteria.');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (\Exception $oException)
|
catch (\Exception $oException)
|
||||||
{
|
{
|
||||||
|
|
@ -5,6 +5,6 @@ This plugin adds change password capability to Rainloop webmail by write your ow
|
||||||
|
|
||||||
##### Installation is simple:
|
##### Installation is simple:
|
||||||
|
|
||||||
1. Drop the change-password-customsql in the plugins directory (eg. _RainLoopDir_/data/data_xxxxx/_default/plugins/*)
|
1. Drop the change-password-custom-sql in the plugins directory (eg. _RainLoopDir_/data/data_xxxxx/_default/plugins/*)
|
||||||
2. In rainloop admin panel go to Plugins, and activate change-password-customsql.
|
2. In rainloop admin panel go to Plugins, and activate change-password-custom-sql.
|
||||||
3. Enter mysql details on the plugin config screen.
|
3. Enter mysql details on the plugin config screen.
|
||||||
|
|
@ -16,21 +16,17 @@ class ChangePasswordCustomSqlPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
switch ($sName)
|
switch ($sName)
|
||||||
{
|
{
|
||||||
case 'change-password':
|
case 'change-password':
|
||||||
|
|
||||||
include_once __DIR__.'/ChangePasswordCustomSqlDriver.php';
|
include_once __DIR__.'/ChangePasswordCustomSqlDriver.php';
|
||||||
|
|
||||||
$oProvider = new ChangePasswordCustomSqlDriver();
|
$oProvider = new ChangePasswordCustomSqlDriver();
|
||||||
|
|
||||||
$oProvider
|
$oProvider
|
||||||
->SetLogger($this->Manager()->Actions()->Logger())
|
->SetLogger($this->Manager()->Actions()->Logger())
|
||||||
->SetmHost($this->Config()->Get('plugin', 'mHost', ''))
|
->SetmHost($this->Config()->Get('plugin', 'mHost', ''))
|
||||||
->SetmUser($this->Config()->Get('plugin', 'mUser', ''))
|
->SetmUser($this->Config()->Get('plugin', 'mUser', ''))
|
||||||
->SetmPass($this->Config()->Get('plugin', 'mPass', ''))
|
->SetmPass($this->Config()->Get('plugin', 'mPass', ''))
|
||||||
->SetmDatabase($this->Config()->Get('plugin', 'mDatabase', ''))
|
->SetmDatabase($this->Config()->Get('plugin', 'mDatabase', ''))
|
||||||
->SetmTable($this->Config()->Get('plugin', 'mTable', ''))
|
->SetmTable($this->Config()->Get('plugin', 'mTable', ''))
|
||||||
->SetmSql($this->Config()->Get('plugin', 'mSql', ''))
|
->SetmSql($this->Config()->Get('plugin', 'mSql', ''))
|
||||||
;
|
;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +46,7 @@ class ChangePasswordCustomSqlPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
\RainLoop\Plugins\Property::NewInstance('mTable')->SetLabel('MySQL Table'),
|
\RainLoop\Plugins\Property::NewInstance('mTable')->SetLabel('MySQL Table'),
|
||||||
\RainLoop\Plugins\Property::NewInstance('mSql')->SetLabel('SQL statement')
|
\RainLoop\Plugins\Property::NewInstance('mSql')->SetLabel('SQL statement')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
|
||||||
->SetDescription('SQL statement (allowed wildcards :table, :email, :oldpass, :newpass, :domain, :username).When using MD5 OR SHA1 at tables, write it directly here as SQL functions. Fro non-SQL encryptions use another plugin or wait for new version.')
|
->SetDescription('SQL statement (allowed wildcards :table, :email, :oldpass, :newpass, :domain, :username). When using MD5 OR SHA1 at tables, write it directly here as SQL functions. Fro non-SQL encryptions use another plugin or wait for new version.')
|
||||||
->SetDefaultValue('UPDATE :table SET password = md5(:newpass) WHERE domain = :domain AND username = :username and oldpass = md5(:oldpass)')
|
->SetDefaultValue('UPDATE :table SET password = md5(:newpass) WHERE domain = :domain AND username = :username and oldpass = md5(:oldpass)')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue