mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 12:39:20 +03:00
Merged from sub repository (updated ckeditor, filters - step 3)
Release commit
This commit is contained in:
parent
ec7324b061
commit
42b8a446c6
464 changed files with 10395 additions and 1303 deletions
150
plugins/recaptcha-2/index.php
Normal file
150
plugins/recaptcha-2/index.php
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
|
||||
class Recaptcha2Plugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function Init()
|
||||
{
|
||||
$this->UseLangs(true);
|
||||
|
||||
$this->addJs('js/recaptcha.js');
|
||||
|
||||
$this->addHook('ajax.action-pre-call', 'AjaxActionPreCall');
|
||||
$this->addHook('filter.ajax-response', 'FilterAjaxResponse');
|
||||
|
||||
$this->addTemplate('templates/PluginLoginReCaptchaGroup.html');
|
||||
$this->addTemplateHook('Login', 'BottomControlGroup', 'PluginLoginReCaptchaGroup');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function configMapping()
|
||||
{
|
||||
return array(
|
||||
\RainLoop\Plugins\Property::NewInstance('public_key')->SetLabel('Site key')
|
||||
->SetAllowedInJs(true)
|
||||
->SetDefaultValue(''),
|
||||
\RainLoop\Plugins\Property::NewInstance('private_key')->SetLabel('Secret key')
|
||||
->SetDefaultValue(''),
|
||||
\RainLoop\Plugins\Property::NewInstance('theme')->SetLabel('Theme')
|
||||
->SetAllowedInJs(true)
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::SELECTION)
|
||||
->SetDefaultValue(array('light', 'dark')),
|
||||
\RainLoop\Plugins\Property::NewInstance('error_limit')->SetLabel('Limit')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::SELECTION)
|
||||
->SetDefaultValue(array(0, 1, 2, 3, 4, 5))
|
||||
->SetDescription('')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getCaptchaCacherKey()
|
||||
{
|
||||
return 'Captcha2/Login/'.\RainLoop\Utils::GetConnectionToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
private function getLimit()
|
||||
{
|
||||
$iConfigLimit = $this->Config()->Get('plugin', 'error_limit', 0);
|
||||
if (0 < $iConfigLimit)
|
||||
{
|
||||
$oCacher = $this->Manager()->Actions()->Cacher();
|
||||
$sLimit = $oCacher && $oCacher->IsInited() ? $oCacher->Get($this->getCaptchaCacherKey()) : '0';
|
||||
|
||||
if (0 < \strlen($sLimit) && \is_numeric($sLimit))
|
||||
{
|
||||
$iConfigLimit -= (int) $sLimit;
|
||||
}
|
||||
}
|
||||
|
||||
return $iConfigLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function FilterAppDataPluginSection($bAdmin, $bAuth, &$aData)
|
||||
{
|
||||
if (!$bAdmin && !$bAuth && \is_array($aData))
|
||||
{
|
||||
$aData['show_captcha_on_login'] = 1 > $this->getLimit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sAction
|
||||
*/
|
||||
public function AjaxActionPreCall($sAction)
|
||||
{
|
||||
if ('Login' === $sAction && 0 >= $this->getLimit())
|
||||
{
|
||||
$bResult = false;
|
||||
|
||||
$sResult = $this->Manager()->Actions()->Http()->GetUrlAsString(
|
||||
'https://www.google.com/recaptcha/api/siteverify?secret='.
|
||||
\urlencode($this->Config()->Get('plugin', 'private_key', '')).'&response='.
|
||||
\urlencode($this->Manager()->Actions()->GetActionParam('RecaptchaResponse', '')));
|
||||
|
||||
if ($sResult)
|
||||
{
|
||||
$aResp = @\json_decode($sResult, true);
|
||||
if (\is_array($aResp) && isset($aResp['success']) && $aResp['success'])
|
||||
{
|
||||
$bResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$bResult)
|
||||
{
|
||||
$this->Manager()->Actions()->Logger()->Write('RecaptchaResponse:'.$sResult);
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CaptchaError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sAction
|
||||
* @param array $aResponseItem
|
||||
*/
|
||||
public function FilterAjaxResponse($sAction, &$aResponseItem)
|
||||
{
|
||||
if ('Login' === $sAction && $aResponseItem && isset($aResponseItem['Result']))
|
||||
{
|
||||
$oCacher = $this->Manager()->Actions()->Cacher();
|
||||
$iConfigLimit = (int) $this->Config()->Get('plugin', 'error_limit', 0);
|
||||
$sKey = $this->getCaptchaCacherKey();
|
||||
|
||||
if (0 < $iConfigLimit && $oCacher && $oCacher->IsInited())
|
||||
{
|
||||
if (false === $aResponseItem['Result'])
|
||||
{
|
||||
$iLimit = 0;
|
||||
$sLimut = $oCacher->Get($sKey);
|
||||
if (0 < \strlen($sLimut) && \is_numeric($sLimut))
|
||||
{
|
||||
$iLimit = (int) $sLimut;
|
||||
}
|
||||
|
||||
$oCacher->Set($sKey, ++$iLimit);
|
||||
|
||||
if ($iConfigLimit <= $iLimit)
|
||||
{
|
||||
$aResponseItem['Captcha'] = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$oCacher->Delete($sKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
83
plugins/recaptcha-2/js/recaptcha.js
Normal file
83
plugins/recaptcha-2/js/recaptcha.js
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
|
||||
$(function () {
|
||||
|
||||
var
|
||||
nId = null,
|
||||
bStarted = false
|
||||
;
|
||||
|
||||
function ShowRecaptcha()
|
||||
{
|
||||
if (window.grecaptcha)
|
||||
{
|
||||
if (null === nId)
|
||||
{
|
||||
$('#recaptcha-place').show();
|
||||
|
||||
nId = window.grecaptcha.render('recaptcha-div', {
|
||||
'sitekey': window.rl.pluginSettingsGet('recaptcha-2', 'public_key'),
|
||||
'theme': window.rl.pluginSettingsGet('recaptcha-2', 'theme')
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.__globalShowRecaptcha = ShowRecaptcha;
|
||||
|
||||
function StartRecaptcha()
|
||||
{
|
||||
if (!window.grecaptcha && window.rl)
|
||||
{
|
||||
$.getScript('https://www.google.com/recaptcha/api.js?onload=__globalShowRecaptcha&render=explicit&hl=' + window.rl.settingsGet('Language'));
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowRecaptcha();
|
||||
}
|
||||
}
|
||||
|
||||
if (window.rl)
|
||||
{
|
||||
window.rl.addHook('user-login-submit', function (fSubmitResult) {
|
||||
if (null !== nId && !window.grecaptcha.getResponse(nId))
|
||||
{
|
||||
fSubmitResult(105);
|
||||
}
|
||||
});
|
||||
|
||||
window.rl.addHook('view-model-on-show', function (sName, oViewModel) {
|
||||
if (!bStarted && oViewModel &&
|
||||
('View:RainLoop:Login' === sName || 'View/App/Login' === sName || 'LoginViewModel' === sName || 'LoginAppView' === sName) &&
|
||||
window.rl.pluginSettingsGet('recaptcha-2', 'show_captcha_on_login'))
|
||||
{
|
||||
bStarted = true;
|
||||
StartRecaptcha();
|
||||
}
|
||||
});
|
||||
|
||||
window.rl.addHook('ajax-default-request', function (sAction, oParameters) {
|
||||
if ('Login' === sAction && oParameters && null !== nId && window.grecaptcha)
|
||||
{
|
||||
oParameters['RecaptchaResponse'] = window.grecaptcha.getResponse(nId);
|
||||
}
|
||||
});
|
||||
|
||||
window.rl.addHook('ajax-default-response', function (sAction, oData, sType) {
|
||||
if ('Login' === sAction)
|
||||
{
|
||||
if (!oData || 'success' !== sType || !oData['Result'])
|
||||
{
|
||||
if (null !== nId && window.grecaptcha)
|
||||
{
|
||||
window.grecaptcha.reset(nId);
|
||||
}
|
||||
else if (oData && oData['Captcha'])
|
||||
{
|
||||
StartRecaptcha();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<div class="controls recaptcha-control-group" id="recaptcha-place" style="display: none;">
|
||||
<center id="recaptcha-div"></center>
|
||||
</div>
|
||||
|
|
@ -1 +1 @@
|
|||
1.8
|
||||
1.9
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
<div class="recaptcha-control-group" id="recaptcha-place" style="display: none">
|
||||
<div class="control-group">
|
||||
<div id="recaptcha_image" style="border-radius: 3px"></div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="input-append">
|
||||
<input class="i18n inputLoginForm inputCAPTCHA span4" type="text" autocomplete="off"
|
||||
id="recaptcha_response_field" data-i18n-placeholder="PLUGIN/LABEL_ENTER_THE_WORDS_ABOVE" />
|
||||
<span class="add-on">
|
||||
<i class="icon-repeat" onclick="Recaptcha.reload()" style="cursor: pointer"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="recaptcha-control-group" id="recaptcha-place" style="display: none">
|
||||
<div class="controls">
|
||||
<div id="recaptcha_image" style="border-radius: 3px"></div>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<div class="input-append">
|
||||
<input class="i18n input-block-level inputLoginForm inputCAPTCHA" type="text" autocomplete="off"
|
||||
id="recaptcha_response_field" data-i18n-placeholder="PLUGIN/LABEL_ENTER_THE_WORDS_ABOVE" />
|
||||
<span class="add-on">
|
||||
<i class="icon-repeat" onclick="Recaptcha.reload()" style="cursor: pointer"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue