mailto handler (#136)

+ Some small changes
This commit is contained in:
RainLoop Team 2014-04-17 00:33:12 +04:00
parent 818bf9fb40
commit e86afd8d6e
11 changed files with 290 additions and 278 deletions

View file

@ -1016,15 +1016,6 @@ RainLoopApp.prototype.bootstart = function ()
window.SimplePace.sleep(); window.SimplePace.sleep();
} }
// if (RL.settingsGet('MailToEmail'))
// {
// if (window.postMessage)
// {
// window.console.log('railoop/mailto/auth/' + RL.settingsGet('MailToEmail'), '' + window.location);
//// $.postMessage('railoop/mailto/auth/' + RL.settingsGet('MailToEmail'), '' + window.location);
// }
// }
if (!!RL.settingsGet('Auth')) if (!!RL.settingsGet('Auth'))
{ {
this.setTitle(Utils.i18n('TITLES/LOADING')); this.setTitle(Utils.i18n('TITLES/LOADING'));
@ -1107,19 +1098,22 @@ RainLoopApp.prototype.bootstart = function ()
}, 2000); }, 2000);
// if (window.navigator && Utils.isFunc(window.navigator.registerProtocolHandler))
// {
// window.navigator.registerProtocolHandler('mailto',
// window.location.protocol + '//' + window.location.host + window.location.pathname + '?mailto&to=%s',
// '' + (RL.settingsGet('Title') || 'RainLoop'));
// }
//
// $.receiveMessage(function () {
// window.console.log(arguments);
// }, '' + window.location);
Plugins.runHook('rl-start-user-screens'); Plugins.runHook('rl-start-user-screens');
RL.pub('rl.bootstart-user-screens'); RL.pub('rl.bootstart-user-screens');
if (!!RL.settingsGet('AccountSignMe'))
{
_.delay(function () {
window.navigator.registerProtocolHandler('mailto',
window.location.protocol + '//' + window.location.host + window.location.pathname + '?mailto&to=%s',
'' + (RL.settingsGet('Title') || 'RainLoop'));
if (RL.settingsGet('MailToEmail'))
{
RL.mailToHelper(RL.settingsGet('MailToEmail'));
}
}, 500);
}
} }
else else
{ {

View file

@ -200,7 +200,7 @@ class Account
$this->sEmail, $this->sEmail,
$this->sLogin, $this->sLogin,
$this->sPassword, $this->sPassword,
'0', // PasswordIsXOAuth2 \RainLoop\Utils::Fingerprint(),
$this->sSignMeToken, $this->sSignMeToken,
$this->sParentEmail, $this->sParentEmail,
\RainLoop\Utils::GetShortToken() \RainLoop\Utils::GetShortToken()

View file

@ -10,7 +10,6 @@ define('RL_CONTACTS_MAX', 300);
class Actions class Actions
{ {
const AUTH_TOKEN_KEY = 'rlauth';
const AUTH_SIGN_ME_TOKEN_KEY = 'rlsmauth'; const AUTH_SIGN_ME_TOKEN_KEY = 'rlsmauth';
const AUTH_MAILTO_TOKEN_KEY = 'rlmailtoauth'; const AUTH_MAILTO_TOKEN_KEY = 'rlmailtoauth';
const AUTH_SPEC_TOKEN_KEY = 'rlspecauth'; const AUTH_SPEC_TOKEN_KEY = 'rlspecauth';
@ -874,8 +873,10 @@ class Actions
if (!empty($sToken)) if (!empty($sToken))
{ {
$aAccountHash = \RainLoop\Utils::DecodeKeyValues($sToken); $aAccountHash = \RainLoop\Utils::DecodeKeyValues($sToken);
if (!empty($aAccountHash[0]) && 'token' === $aAccountHash[0] && 8 === \count($aAccountHash) && !empty($aAccountHash[7]) && if (!empty($aAccountHash[0]) && 'token' === $aAccountHash[0] && 8 === \count($aAccountHash) &&
(!$bValidateShortToken || \RainLoop\Utils::GetShortToken() === $aAccountHash[7])) // !empty($aAccountHash[4]) && \RainLoop\Utils::Fingerprint() === $aAccountHash[4] &&
!empty($aAccountHash[7]) && (!$bValidateShortToken || \RainLoop\Utils::GetShortToken() === $aAccountHash[7])
)
{ {
$oAccount = $this->LoginProvide($aAccountHash[1], $aAccountHash[2], $aAccountHash[3], $oAccount = $this->LoginProvide($aAccountHash[1], $aAccountHash[2], $aAccountHash[3],
empty($aAccountHash[5]) ? '' : $aAccountHash[5]); empty($aAccountHash[5]) ? '' : $aAccountHash[5]);
@ -917,6 +918,25 @@ class Actions
return $oResult; return $oResult;
} }
/**
* @return \RainLoop\Account|bool
*/
public function GetAccountFromSignMeToken()
{
$oAccount = false;
$sSignMeToken = \RainLoop\Utils::GetCookie(\RainLoop\Actions::AUTH_SIGN_ME_TOKEN_KEY, '');
if (!empty($sSignMeToken))
{
$oAccount = $this->oActions->GetAccountFromCustomToken($this->StorageProvider()->Get(null,
\RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY,
'SignMe/UserToken/'.$sSignMeToken
), false, false);
}
return $oAccount;
}
/** /**
* @param bool $bThrowExceptionOnFalse = true * @param bool $bThrowExceptionOnFalse = true
* *
@ -948,6 +968,7 @@ class Actions
'IndexFile' => APP_INDEX_FILE, 'IndexFile' => APP_INDEX_FILE,
'Auth' => false, 'Auth' => false,
'AccountHash' => '', 'AccountHash' => '',
'AccountSignMe' => false,
'AuthAccountHash' => '', 'AuthAccountHash' => '',
'MailToEmail' => '', 'MailToEmail' => '',
'Email' => '', 'Email' => '',
@ -990,18 +1011,6 @@ class Actions
$oSettings = null; $oSettings = null;
if (!$bAdmin) if (!$bAdmin)
{ {
$sToken = \RainLoop\Utils::GetCookie(self::AUTH_MAILTO_TOKEN_KEY, null);
if (null !== $sToken)
{
\RainLoop\Utils::ClearCookie(self::AUTH_MAILTO_TOKEN_KEY);
$mMailToData = \RainLoop\Utils::DecodeKeyValues($sToken);
if (\is_array($mMailToData) && !empty($mMailToData['MailTo']) && 'MailTo' === $mMailToData['MailTo'] &&
!empty($mMailToData['To']))
{
$aResult['MailToEmail'] = $mMailToData['To'];
}
}
$oAccount = $this->getAccountFromToken(false); $oAccount = $this->getAccountFromToken(false);
if ($oAccount instanceof \RainLoop\Account) if ($oAccount instanceof \RainLoop\Account)
{ {
@ -1012,6 +1021,7 @@ class Actions
$aResult['IncLogin'] = $oAccount->IncLogin(); $aResult['IncLogin'] = $oAccount->IncLogin();
$aResult['OutLogin'] = $oAccount->OutLogin(); $aResult['OutLogin'] = $oAccount->OutLogin();
$aResult['AccountHash'] = $oAccount->Hash(); $aResult['AccountHash'] = $oAccount->Hash();
$aResult['AccountSignMe'] = $oAccount->SignMe();
$aResult['ChangePasswordIsAllowed'] = $this->ChangePasswordProvider()->PasswordChangePossibility($oAccount); $aResult['ChangePasswordIsAllowed'] = $this->ChangePasswordProvider()->PasswordChangePossibility($oAccount);
$aResult['ContactsIsAllowed'] = $oPab->IsActive(); $aResult['ContactsIsAllowed'] = $oPab->IsActive();
$aResult['ContactsSharingIsAllowed'] = $oPab->IsSharingAllowed(); $aResult['ContactsSharingIsAllowed'] = $oPab->IsSharingAllowed();
@ -1066,6 +1076,21 @@ class Actions
} }
} }
if ($aResult['AccountSignMe'])
{
$sToken = \RainLoop\Utils::GetCookie(self::AUTH_MAILTO_TOKEN_KEY, null);
if (null !== $sToken)
{
\RainLoop\Utils::ClearCookie(self::AUTH_MAILTO_TOKEN_KEY);
$mMailToData = \RainLoop\Utils::DecodeKeyValues($sToken);
if (\is_array($mMailToData) && !empty($mMailToData['MailTo']) && 'MailTo' === $mMailToData['MailTo'] &&
!empty($mMailToData['To']))
{
$aResult['MailToEmail'] = $mMailToData['To'];
}
}
}
$oSettings = $this->SettingsProvider()->Load($oAccount); $oSettings = $this->SettingsProvider()->Load($oAccount);
} }
else else

View file

@ -804,15 +804,14 @@ class ServiceActions
public function ServiceMailto() public function ServiceMailto()
{ {
$sTo = \trim($this->oHttp->GetQuery('to', '')); $sTo = \trim($this->oHttp->GetQuery('to', ''));
if (!empty($sTo)) if (!empty($sTo) && \preg_match('/^mailto:/i', $sTo))
{ {
if (preg_match('/^mailto:/i', $sTo)) $oAccount = $this->oActions->GetAccountFromSignMeToken();
if ($oAccount)
{ {
$sTo = \substr($sTo, 7);
}
$this->oActions->SetMailtoRequest(\MailSo\Base\Utils::StrToLowerIfAscii($sTo)); $this->oActions->SetMailtoRequest(\MailSo\Base\Utils::StrToLowerIfAscii($sTo));
} }
}
$this->oActions->Location('./'); $this->oActions->Location('./');
return ''; return '';
@ -1047,21 +1046,13 @@ class ServiceActions
if (empty($sAuthAccountHash)) if (empty($sAuthAccountHash))
{ {
$sSignMeToken = \RainLoop\Utils::GetCookie(\RainLoop\Actions::AUTH_SIGN_ME_TOKEN_KEY, ''); $oAccount = $this->oActions->GetAccountFromSignMeToken();
if (!empty($sSignMeToken))
{
$oAccount = $this->oActions->GetAccountFromCustomToken($this->StorageProvider()->Get(null,
\RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY,
'SignMe/UserToken/'.$sSignMeToken
), false, false);
if ($oAccount) if ($oAccount)
{ {
$this->oActions->AuthProcess($oAccount); $this->oActions->AuthProcess($oAccount);
$sAuthAccountHash = $this->oActions->GetSpecAuthToken(); $sAuthAccountHash = $this->oActions->GetSpecAuthToken();
} }
} }
}
$this->oActions->SetSpecAuthToken($sAuthAccountHash); $this->oActions->SetSpecAuthToken($sAuthAccountHash);
} }

View file

@ -79,6 +79,14 @@ class Utils
return \md5('Connection'.APP_SALT.$sToken.'Token'.APP_SALT); return \md5('Connection'.APP_SALT.$sToken.'Token'.APP_SALT);
} }
/**
* @return string
*/
static public function Fingerprint()
{
return \md5(empty($_SERVER['HTTP_USER_AGENT']) ? 'RainLoopFingerprint' : $_SERVER['HTTP_USER_AGENT']);
}
/** /**
* @return string * @return string
*/ */

File diff suppressed because one or more lines are too long

View file

@ -19473,15 +19473,6 @@ RainLoopApp.prototype.bootstart = function ()
window.SimplePace.sleep(); window.SimplePace.sleep();
} }
// if (RL.settingsGet('MailToEmail'))
// {
// if (window.postMessage)
// {
// window.console.log('railoop/mailto/auth/' + RL.settingsGet('MailToEmail'), '' + window.location);
//// $.postMessage('railoop/mailto/auth/' + RL.settingsGet('MailToEmail'), '' + window.location);
// }
// }
if (!!RL.settingsGet('Auth')) if (!!RL.settingsGet('Auth'))
{ {
this.setTitle(Utils.i18n('TITLES/LOADING')); this.setTitle(Utils.i18n('TITLES/LOADING'));
@ -19564,19 +19555,22 @@ RainLoopApp.prototype.bootstart = function ()
}, 2000); }, 2000);
// if (window.navigator && Utils.isFunc(window.navigator.registerProtocolHandler))
// {
// window.navigator.registerProtocolHandler('mailto',
// window.location.protocol + '//' + window.location.host + window.location.pathname + '?mailto&to=%s',
// '' + (RL.settingsGet('Title') || 'RainLoop'));
// }
//
// $.receiveMessage(function () {
// window.console.log(arguments);
// }, '' + window.location);
Plugins.runHook('rl-start-user-screens'); Plugins.runHook('rl-start-user-screens');
RL.pub('rl.bootstart-user-screens'); RL.pub('rl.bootstart-user-screens');
if (!!RL.settingsGet('AccountSignMe'))
{
_.delay(function () {
window.navigator.registerProtocolHandler('mailto',
window.location.protocol + '//' + window.location.host + window.location.pathname + '?mailto&to=%s',
'' + (RL.settingsGet('Title') || 'RainLoop'));
if (RL.settingsGet('MailToEmail'))
{
RL.mailToHelper(RL.settingsGet('MailToEmail'));
}
}, 500);
}
} }
else else
{ {

File diff suppressed because one or more lines are too long