mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 08:57:03 +03:00
LoginProcess refactoring
+ Output parameter in ExternalLogin functionality
This commit is contained in:
parent
6ca3b44d05
commit
b7e135a553
2 changed files with 58 additions and 34 deletions
|
|
@ -1280,8 +1280,23 @@ class Actions
|
||||||
* @return \RainLoop\Account
|
* @return \RainLoop\Account
|
||||||
* @throws \RainLoop\Exceptions\ClientException
|
* @throws \RainLoop\Exceptions\ClientException
|
||||||
*/
|
*/
|
||||||
public function LoginProcess($sEmail, $sLogin, $sPassword, $sSignMeToken = '')
|
public function LoginProcess(&$sEmail, &$sLogin, &$sPassword, $sSignMeToken = '')
|
||||||
{
|
{
|
||||||
|
if (false === \strpos($sEmail, '@') && 0 < \strlen(\trim($this->Config()->Get('login', 'default_domain', ''))))
|
||||||
|
{
|
||||||
|
$sEmail = $sEmail.'@'.\trim(\trim($this->Config()->Get('login', 'default_domain', '')), ' @');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->Config()->Get('login', 'allow_custom_login', false) || 0 === \strlen($sLogin))
|
||||||
|
{
|
||||||
|
$sLogin = $sEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 === \strlen($sLogin))
|
||||||
|
{
|
||||||
|
$sLogin = $sEmail;
|
||||||
|
}
|
||||||
|
|
||||||
$this->Plugins()->RunHook('filter.login-credentials', array(&$sEmail, &$sLogin, &$sPassword));
|
$this->Plugins()->RunHook('filter.login-credentials', array(&$sEmail, &$sLogin, &$sPassword));
|
||||||
|
|
||||||
$oAccount = $this->LoginProvider()->Provide($sEmail, $sLogin, $sPassword, $sSignMeToken);
|
$oAccount = $this->LoginProvider()->Provide($sEmail, $sLogin, $sPassword, $sSignMeToken);
|
||||||
|
|
@ -1343,25 +1358,11 @@ class Actions
|
||||||
$sLanguage = $this->GetActionParam('Language', '');
|
$sLanguage = $this->GetActionParam('Language', '');
|
||||||
$bSignMe = '1' === $this->GetActionParam('SignMe', '0');
|
$bSignMe = '1' === $this->GetActionParam('SignMe', '0');
|
||||||
|
|
||||||
if (false === \strpos($sEmail, '@') && 0 < \strlen(\trim($this->Config()->Get('login', 'default_domain', ''))))
|
|
||||||
{
|
|
||||||
$sEmail = $sEmail.'@'.\trim($this->Config()->Get('login', 'default_domain', ''), ' @');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->Config()->Get('login', 'allow_custom_login', false) || 0 === \strlen($sLogin))
|
|
||||||
{
|
|
||||||
$sLogin = $sEmail;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sSignMeToken = '';
|
|
||||||
if ($bSignMe)
|
|
||||||
{
|
|
||||||
$sSignMeToken = \md5(\microtime(true).APP_SALT.\rand(10000, 99999).$sEmail);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->Logger()->AddSecret($sPassword);
|
$this->Logger()->AddSecret($sPassword);
|
||||||
|
|
||||||
$oAccount = $this->LoginProcess($sEmail, $sLogin, $sPassword, $sSignMeToken);
|
$oAccount = $this->LoginProcess($sEmail, $sLogin, $sPassword,
|
||||||
|
$bSignMe ? \md5(\microtime(true).APP_SALT.\rand(10000, 99999).$sEmail) : '');
|
||||||
|
|
||||||
$this->AuthProcess($oAccount);
|
$this->AuthProcess($oAccount);
|
||||||
|
|
||||||
if ($oAccount && 0 < \strlen($sLanguage))
|
if ($oAccount && 0 < \strlen($sLanguage))
|
||||||
|
|
@ -1510,11 +1511,6 @@ class Actions
|
||||||
$sLogin = \trim($this->GetActionParam('Login', ''));
|
$sLogin = \trim($this->GetActionParam('Login', ''));
|
||||||
$sPassword = $this->GetActionParam('Password', '');
|
$sPassword = $this->GetActionParam('Password', '');
|
||||||
|
|
||||||
if (!$this->Config()->Get('login', 'allow_custom_login', false) || 0 === strlen($sLogin))
|
|
||||||
{
|
|
||||||
$sLogin = $sEmail;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->Logger()->AddSecret($sPassword);
|
$this->Logger()->AddSecret($sPassword);
|
||||||
|
|
||||||
$sParentEmail = 0 < \strlen($oAccount->ParentEmail()) ? $oAccount->ParentEmail() : $oAccount->Email();
|
$sParentEmail = 0 < \strlen($oAccount->ParentEmail()) ? $oAccount->ParentEmail() : $oAccount->Email();
|
||||||
|
|
|
||||||
|
|
@ -825,22 +825,19 @@ class ServiceActions
|
||||||
*/
|
*/
|
||||||
public function ServiceExternalLogin()
|
public function ServiceExternalLogin()
|
||||||
{
|
{
|
||||||
|
$oException = null;
|
||||||
|
$oAccount = null;
|
||||||
|
|
||||||
if ($this->oActions->Config()->Get('labs', 'allow_external_login', false))
|
if ($this->oActions->Config()->Get('labs', 'allow_external_login', false))
|
||||||
{
|
{
|
||||||
$oException = null;
|
$sEmail = trim($this->oHttp->GetRequest('Email', ''));
|
||||||
|
$sLogin = trim($this->oHttp->GetRequest('Login', ''));
|
||||||
|
$sPassword = $this->oHttp->GetRequest('Password', '');
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$sEmail = trim($this->oHttp->GetRequest('Email', ''));
|
|
||||||
$sLogin = trim($this->oHttp->GetRequest('Login', ''));
|
|
||||||
$sPassword = $this->oHttp->GetRequest('Password', '');
|
|
||||||
|
|
||||||
$this->oActions->Logger()->AddSecret($sPassword);
|
$this->oActions->Logger()->AddSecret($sPassword);
|
||||||
|
|
||||||
if (0 === \strlen($sLogin))
|
|
||||||
{
|
|
||||||
$sLogin = $sEmail;
|
|
||||||
}
|
|
||||||
|
|
||||||
$oAccount = $this->oActions->LoginProcess($sEmail, $sLogin, $sPassword);
|
$oAccount = $this->oActions->LoginProcess($sEmail, $sLogin, $sPassword);
|
||||||
$this->oActions->AuthProcess($oAccount);
|
$this->oActions->AuthProcess($oAccount);
|
||||||
}
|
}
|
||||||
|
|
@ -850,7 +847,38 @@ class ServiceActions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->oActions->Location('./');
|
switch (\strtolower($this->oHttp->GetRequest('Output', 'Redirect')))
|
||||||
|
{
|
||||||
|
case 'json':
|
||||||
|
|
||||||
|
@\header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
|
$aResult = array(
|
||||||
|
'Action' => 'ExternalLogin',
|
||||||
|
'Result' => $oAccount instanceof \RainLoop\Account ? true : false,
|
||||||
|
'ErrorCode' => 0
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$aResult['Result'])
|
||||||
|
{
|
||||||
|
if ($oException instanceof \RainLoop\Exceptions\ClientException)
|
||||||
|
{
|
||||||
|
$aResult['ErrorCode'] = $oException->getCode();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$aResult['ErrorCode'] = \RainLoop\Notifications::AuthError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return \MailSo\Base\Utils::Php2js($aResult);
|
||||||
|
|
||||||
|
case 'redirect':
|
||||||
|
default:
|
||||||
|
$this->oActions->Location('./');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue