Sso integration, Simple Rainloop Api (#103)

Small fixes
This commit is contained in:
RainLoop Team 2014-04-14 20:07:33 +04:00
parent dde42c6190
commit e211899c7b
12 changed files with 191 additions and 18 deletions

View file

@ -159,6 +159,14 @@ class Actions
return $this->sSpecAuthToken;
}
/**
* @return string
*/
public function BuildSsoCacherKey($sSsoHash)
{
return '/Sso/Data/'.$sSsoHash.'/Login/';
}
/**
* @return \RainLoop\Application
*/
@ -4508,7 +4516,7 @@ class Actions
$sFolderFullName = $this->GetActionParam('MessageFolder', '');
$sUid = $this->GetActionParam('MessageUid', '');
$this->Cacher()->Set($oAccount->Email().'/'.$sFolderFullName.'/'.$sUid, '1');
$this->Cacher()->Set('/ReadReceipt/'.$oAccount->Email().'/'.$sFolderFullName.'/'.$sUid, '1');
if (0 < \strlen($sFolderFullName) && 0 < \strlen($sUid))
{
@ -6786,7 +6794,8 @@ class Actions
catch (\Exception $oException) {}
}
if (0 < \strlen($mResult['ReadReceipt']) && '1' === $this->Cacher()->Get($oAccount->Email().'/'.$mResult['Folder'].'/'.$mResult['Uid'], '0'))
if (0 < \strlen($mResult['ReadReceipt']) && '1' === $this->Cacher()->Get(
'/ReadReceipt/'.$oAccount->Email().'/'.$mResult['Folder'].'/'.$mResult['Uid'], '0'))
{
$mResult['ReadReceipt'] = '';
}
@ -6933,8 +6942,12 @@ class Actions
else if ($mResponse instanceof \MailSo\Base\Collection)
{
$aList =& $mResponse->GetAsArray();
if (100 < \count($aList) && $mResponse instanceof \MailSo\Mime\EmailCollection)
{
$aList = \array_slice($aList, 0, 100);
}
$mResult = $this->responseObject($aList, $sParent, $aParameters);
$bHook = false;
}
else

View file

@ -0,0 +1,89 @@
<?php
namespace RainLoop;
class Api
{
/**
* @return void
*/
private function __construct()
{
}
/**
* @return \RainLoop\Actions
*/
private static function Actions()
{
static $oActions = null;
if (null === $oActions)
{
$oActions = \RainLoop\Actions::NewInstance();
}
return $oActions;
}
/**
* @return \RainLoop\Application
*/
public static function Config()
{
return self::Actions()->Config();
}
/**
* @return bool
*/
public static function Handle()
{
static $bOne = null;
if ($bOne)
{
return true;
}
if (!\class_exists('MailSo\Version'))
{
return false;
}
if (self::Config()->Get('labs', 'disable_iconv_if_mbstring_supported') &&
\class_exists('MailSo\Capa') && \MailSo\Base\Utils::IsMbStringSupported())
{
\MailSo\Capa::$ICONV = false;
}
$bOne = true;
return true;
}
/**
* @param string $sEmail
* @param string $sPassword
* @param string $sLogin = ''
*
* @return string
*/
public static function GetUserSsoHash($sEmail, $sPassword, $sLogin = '')
{
$sSsoHash = \sha1(\rand(10000, 99999).$sEmail.$sPassword.$sLogin.\microtime(true));
return self::Actions()->Cacher()->Set(self::Actions()->BuildSsoCacherKey($sSsoHash), \RainLoop\Utils::EncodeKeyValues(array(
'Email' => $sEmail,
'Password' => $sPassword,
'Login' => $sLogin
))) ? $sSsoHash : '';
}
/**
* @param string $sSsoHash
*
* @return bool
*/
public static function ClearUserSsoHash($sSsoHash)
{
return self::Actions()->Delete(self::Actions()->BuildSsoCacherKey($sSsoHash));
}
}

View file

@ -296,7 +296,7 @@ abstract class PdoAbstract
}
/**
* @param string $sType
* @param string $sName
* @param bool $bReturnIntValue = true
*
* @return int|string|bool
@ -335,7 +335,7 @@ abstract class PdoAbstract
}
/**
* @param string $sType
* @param string $sName
*
* @return int|string|bool
*/
@ -345,7 +345,7 @@ abstract class PdoAbstract
}
/**
* @param string $sType
* @param string $sName
* @param int $iVersion
*
* @return bool

View file

@ -823,7 +823,52 @@ class ServiceActions
/**
* @return string
*/
public function ServiceCpanelAutoLogin()
public function ServiceSso()
{
$oException = null;
$oAccount = null;
$sSsoHash = $this->oHttp->GetRequest('hash', '');
if (!empty($sSsoHash))
{
$mData = null;
$sSsoKey = $this->oActions->BuildSsoCacherKey($sSsoHash);
$sSsoSubData = $this->Cacher()->Get($sSsoKey);
if (!empty($sSsoSubData))
{
$mData = \RainLoop\Utils::DecodeKeyValues($sSsoSubData);
$this->Cacher()->Delete($sSsoKey);
if (\is_array($mData) && !empty($mData['Email']) && isset($mData['Password']))
{
$sEmail = \strtolower(\trim($mData['Email']));
$sPassword = $mData['Password'];
$sLogin = isset($mData['Login']) ? $mData['Login'] : '';
try
{
$this->oActions->Logger()->AddSecret($sPassword);
$oAccount = $this->oActions->LoginProcess($sEmail, $sLogin, $sPassword);
$this->oActions->AuthProcess($oAccount);
}
catch (\Exception $oException)
{
$this->oActions->Logger()->WriteException($oException);
}
}
}
}
$this->oActions->Location('./');
return '';
}
/**
* @return string
*/
public function ServiceRemoteAutoLogin()
{
$oException = null;
$oAccount = null;