mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 21:19:21 +03:00
This commit is contained in:
parent
bb05e3ada9
commit
8f479235d2
2 changed files with 254 additions and 0 deletions
88
plugins/hcaptcha/js/hcaptcha.js
Normal file
88
plugins/hcaptcha/js/hcaptcha.js
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
(rl => {
|
||||
if (rl) {
|
||||
var
|
||||
nId = null,
|
||||
bStarted = false
|
||||
;
|
||||
|
||||
function ShowHcaptcha()
|
||||
{
|
||||
if (window.hcaptcha && null === nId)
|
||||
{
|
||||
var
|
||||
oEl = null,
|
||||
oLink = document.getElementById('plugin-Login-BottomControlGroup')
|
||||
;
|
||||
|
||||
if (oLink)
|
||||
{
|
||||
oEl = document.createElement('div');
|
||||
oEl.className = 'controls';
|
||||
|
||||
oLink.append(oEl);
|
||||
|
||||
nId = hcaptcha.render(oEl, {
|
||||
'sitekey': rl.pluginSettingsGet('hcaptcha', 'site_key'),
|
||||
'theme': rl.pluginSettingsGet('hcaptcha', 'theme')
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.__globalShowHcaptcha = ShowHcaptcha;
|
||||
|
||||
function StartHcaptcha()
|
||||
{
|
||||
if (window.hcaptcha)
|
||||
{
|
||||
ShowHcaptcha();
|
||||
}
|
||||
else
|
||||
{
|
||||
const script = document.createElement('script');
|
||||
script.src = 'https://hcaptcha.com/1/api.js?onload=__globalShowHcaptcha&render=explicit';
|
||||
document.head.append(script);
|
||||
}
|
||||
}
|
||||
|
||||
rl.addHook('user-login-submit', fSubmitResult => {
|
||||
if (null !== nId && !window.hcaptcha.getResponse(nId))
|
||||
{
|
||||
fSubmitResult(105);
|
||||
}
|
||||
});
|
||||
|
||||
rl.addHook('view-model-on-show', (sName, oViewModel) => {
|
||||
if (!bStarted && oViewModel && 'LoginUserView' === sName
|
||||
&& rl.pluginSettingsGet('hcaptcha', 'show_captcha_on_login'))
|
||||
{
|
||||
bStarted = true;
|
||||
StartHcaptcha();
|
||||
}
|
||||
});
|
||||
|
||||
rl.addHook('json-default-request', (sAction, oParameters) => {
|
||||
if ('Login' === sAction && oParameters && null !== nId && window.hcaptcha)
|
||||
{
|
||||
oParameters['h-captcha-response'] = hcaptcha.getResponse(nId);
|
||||
}
|
||||
});
|
||||
|
||||
rl.addHook('json-default-response', (sAction, oData, sType) => {
|
||||
if ('Login' === sAction)
|
||||
{
|
||||
if (!oData || 'success' !== sType || !oData['Result'])
|
||||
{
|
||||
if (null !== nId && window.hcaptcha)
|
||||
{
|
||||
hcaptcha.reset(nId);
|
||||
}
|
||||
else if (oData && oData['Captcha'])
|
||||
{
|
||||
StartHcaptcha();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})(window.rl);
|
||||
Loading…
Add table
Add a link
Reference in a new issue